Documentation
¶
Index ¶
- Variables
- func DescribeStruct(header string, s any) (out string, err error)
- func Format(format string, data []any, extra *map[string][]string, spec FormatSpec) (string, error)
- func HumanByteTransform(s string, _ *api.Clients) string
- func TimezoneTransform(s string, _ *api.Clients) string
- func Truncate50Transform(s string, _ *api.Clients) string
- func UpperCaseTransform(in string, _ *api.Clients) string
- func UsernameTransform(id string, clients *api.Clients) string
- type FormatSpec
- type PrefixWriter
- type TransformFunc
- type TransformMap
Constants ¶
This section is empty.
Variables ¶
var ( // Formats is the list of supported output formats. Formats = []string{"json", "yaml", "csv", "long", "short"} // ErrZeroValueOf is returned if when taking the reflect ValueOf an item we get a zero Value. ErrZeroValueOf = errors.New("ValueOf is zero") // ErrNotAStruct is returned when we expect a struct, but find something else. ErrNotAStruct = errors.New("not a struct") // ErrFieldNotFound is returned if we cannot find the requested field on a reflect.Value. ErrFieldNotFound = errors.New("field not found") // ErrPanic is returned if an unhandled panic occurs - this should not happen. ErrPanic = errors.New("unhandled panic") // ErrShortExtra is returned if not enough values are given for an extra field. ErrShortExtra = errors.New("not enough values for extra field") )
Functions ¶
func DescribeStruct ¶
DescribeStruct returns a human readable representation of an arbitrary struct. A provided header is prepended, as a title to the output.
func Format ¶
Format returns a string containing output in the requested format. data is a generic interface{} representation of the data retrieved from the API. extra is a map of computed values that can be used to add an extra field to TSV/CSV output. spec specifies fields to display, and transformations to apply on fields. Note: json and yaml output are raw dumps from the API, ignoring extra and spec.
func HumanByteTransform ¶
HumanByteTransform will format a number of bytes into K/M/G/TiB.
func TimezoneTransform ¶
TimezoneTransform will reformat a date/time into the current timezone.
func Truncate50Transform ¶
Truncate50Transform will truncate a string to 50 characters.
func UpperCaseTransform ¶
UpperCaseTransform will transform a string to upper-case.
Types ¶
type FormatSpec ¶
type FormatSpec struct {
// ShortFields indicates which fields are to be included in a short output format.
ShortFields []string
// ShortHeaders provides header text per entry in ShortFields.
ShortHeaders []string
// LongFields indicates which fields are to be included in a long output format.
LongFields []string
// LongFields provides header text per entry in LongFields.
LongHeaders []string
// Transforms can be used to specifies an optional function per field that will transform output values.
// Only applies to CSV and TSV output. JSON & YAML output is raw, and is not transformed.
Transforms map[string]TransformFunc
// Clients provides service clients for transformations that may need API access.
Clients *api.Clients
}
FormatSpec defines the way in which output will be displayed.
type PrefixWriter ¶
type PrefixWriter interface {
// Write writes text with the specified indentation level.
Writef(level int, format string, a ...any)
// WriteLine writes an entire line with no indentation level.
WriteLine(a ...any)
// Flush forces indentation to be reset.
Flush()
}
PrefixWriter can write text at various indentation levels.
func NewNestedPrefixWriter ¶
func NewNestedPrefixWriter(out PrefixWriter, indent int) PrefixWriter
NewPrefixWriter creates a new PrefixWriter.
func NewPrefixWriter ¶
func NewPrefixWriter(out io.Writer) PrefixWriter
NewPrefixWriter creates a new PrefixWriter.
type TransformFunc ¶
TransformFunc are used to convert a string into a different representation for display. Service clients are provided so transformations can be performed that involve API calls.
type TransformMap ¶
type TransformMap map[string]TransformFunc
TransformMap is a map from field name to a TransformFunc.