output

package
v1.18.5 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Mar 15, 2024 License: MIT Imports: 16 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var MonetaryFieldValueHandler = func(reflectedValue reflect.Value) string {
	return fmt.Sprintf("%.2f", reflectedValue.Float())
}

Functions

func CSV

func CSV(rows []*OrderedFields) error

CSV outputs provided rows as CSV to stdout

func CommandOutput

func CommandOutput(cmd *cobra.Command, out OutputHandlerDataProvider) error

func CommandOutputPaginated

func CommandOutputPaginated[T any](cmd *cobra.Command, out OutputHandlerDataProvider, paginated *connection.Paginated[T]) error

func Error

func Error(str string)

Error writes specified string to stderr

func Errorf

func Errorf(format string, a ...interface{})

Errorf writes specified string with formatting to stderr

func ExitWithErrorLevel

func ExitWithErrorLevel()

func Fatal

func Fatal(str string)

Fatal writes specified string to stderr and calls outputExit to exit with 1

func Fatalf

func Fatalf(format string, a ...interface{})

Fatalf writes specified string with formatting to stderr and calls outputExit to exit with 1

func JSON

func JSON(v interface{}) error

JSON marshals and outputs value v to stdout

func JSONPath

func JSONPath(query string, v interface{}) error

JSONPath marshals and outputs value v to stdout

func List

func List(rows []*OrderedFields) error

List will format specified rows using given includeProperties by extracting fields, and output them to stdout

func OutputWithCustomErrorLevel

func OutputWithCustomErrorLevel(level int, str string)

OutputWithCustomErrorLevel is a wrapper for OutputError, which sets global var errorLevel with provided level

func OutputWithCustomErrorLevelf

func OutputWithCustomErrorLevelf(level int, format string, a ...interface{})

OutputWithCustomErrorLevelf is a wrapper for OutputWithCustomErrorLevel, which sets global var errorLevel with provided level

func OutputWithErrorLevel

func OutputWithErrorLevel(str string)

OutputWithErrorLevel is a wrapper for OutputWithCustomErrorLevel, which sets global var errorLevel to 1

func OutputWithErrorLevelf

func OutputWithErrorLevelf(format string, a ...interface{})

OutputWithErrorLevelf is a wrapper for OutputWithCustomErrorLevelf, which sets global var errorLevel to 1

func ParseOutputFlag

func ParseOutputFlag(flag string) (name, arg string)

func SetOutputExit

func SetOutputExit(e func(code int)) func(code int)

func Table

func Table(rows []*OrderedFields) error

Table takes an array of mapped fields (key being lowercased name), and outputs a table

func Template

func Template(t string, i interface{}) error

Template will format i with given Golang template t, and output resulting string to stdout

func Value

func Value(rows []*OrderedFields) error

Value will format specified rows using given includeProperties by extracting field values, and output them to stdout

func YAML

func YAML(v interface{}) error

YAML marshals and outputs value v to stdout

Types

type DebugLogger

type DebugLogger struct {
}

func (*DebugLogger) Debug

func (l *DebugLogger) Debug(msg string)

func (*DebugLogger) Error

func (l *DebugLogger) Error(msg string)

func (*DebugLogger) Info

func (l *DebugLogger) Info(msg string)

func (*DebugLogger) Trace

func (l *DebugLogger) Trace(msg string)

func (*DebugLogger) Warn

func (l *DebugLogger) Warn(msg string)

type FieldHandlerFunc

type FieldHandlerFunc func(v *OrderedFields, fieldName string, reflectedValue reflect.Value) *OrderedFields

type FieldValue

type FieldValue struct {
	Value   string
	Default bool
}

FieldValue holds the value for a table field

func NewFieldValue

func NewFieldValue(value string, def bool) FieldValue

NewFieldValue returns a new, initialized FieldValue struct

type FieldValueHandlerFunc

type FieldValueHandlerFunc func(reflectedValue reflect.Value) string

type GenericOutputHandlerDataProvider

type GenericOutputHandlerDataProvider struct {
	// contains filtered or unexported fields
}

func (*GenericOutputHandlerDataProvider) GetData

func (p *GenericOutputHandlerDataProvider) GetData() interface{}

func (*GenericOutputHandlerDataProvider) GetFieldData

func (p *GenericOutputHandlerDataProvider) GetFieldData() ([]*OrderedFields, error)

type OrderedFields

type OrderedFields struct {
	// contains filtered or unexported fields
}

OrderedFields holds a string map with field values, and a slice of keys for maintaining order

func NewOrderedFields

func NewOrderedFields() *OrderedFields

NewOrderedFields returns a pointer to an initialized OrderedFields struct

func (*OrderedFields) Exists

func (o *OrderedFields) Exists(k string) bool

Exists returns true if given key k exists, otherwise false

func (*OrderedFields) Get

func (o *OrderedFields) Get(k string) FieldValue

Get retrieves FieldValue for given key k

func (*OrderedFields) Keys

func (o *OrderedFields) Keys() []string

Keys returns a list of ordered keys

func (*OrderedFields) Set

func (o *OrderedFields) Set(k string, v FieldValue)

Set adds/updates given key k with FieldValue v

type OutputHandler

type OutputHandler struct {
	Format           string
	FormatArg        string
	Properties       []string
	SupportedFormats []string
	DataProvider     OutputHandlerDataProvider
}

func NewOutputHandler

func NewOutputHandler(dataProvider OutputHandlerDataProvider, format string, formatArg string) *OutputHandler

func (*OutputHandler) Handle

func (o *OutputHandler) Handle() error

Handle calls the relevant OutputProvider data retrieval methods for given value in struct property 'Format'

func (*OutputHandler) WithSupportedFormats

func (o *OutputHandler) WithSupportedFormats(formats []string) *OutputHandler

type OutputHandlerDataProvider

type OutputHandlerDataProvider interface {
	GetData() interface{}
	GetFieldData() ([]*OrderedFields, error)
}

type OutputHandlerDataProviderOption

type OutputHandlerDataProviderOption func(p *GenericOutputHandlerDataProvider)

func WithData

func WithData(data interface{}) OutputHandlerDataProviderOption

func WithFieldDataFunc

func WithFieldDataFunc(fieldDataFunc func() ([]*OrderedFields, error)) OutputHandlerDataProviderOption

type OutputHandlerOpts

type OutputHandlerOpts map[string]interface{}

type SerializedOutputHandlerDataProvider

type SerializedOutputHandlerDataProvider struct {
	*GenericOutputHandlerDataProvider
	// contains filtered or unexported fields
}

func NewSerializedOutputHandlerDataProvider

func NewSerializedOutputHandlerDataProvider(items interface{}) *SerializedOutputHandlerDataProvider

func (*SerializedOutputHandlerDataProvider) GetFieldData

func (*SerializedOutputHandlerDataProvider) WithDefaultFields

func (*SerializedOutputHandlerDataProvider) WithFieldHandler

func (*SerializedOutputHandlerDataProvider) WithFieldValueHandler

func (*SerializedOutputHandlerDataProvider) WithIgnoredFields

func (*SerializedOutputHandlerDataProvider) WithMonetaryFields

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL