Documentation ¶
Index ¶
- Constants
- Variables
- func Prepare(plain interface{}, structured interface{}) *preparedOutput
- func Structured(structured interface{}) *structuredOutput
- type Behavior
- type Config
- type Editor
- type Emphasize
- type Format
- type JSON
- type Marshaller
- type Mediator
- type Outputer
- type Plain
- type PlainOpts
- type Simple
- type Spinner
- type StructuredError
- type StructuredMarshaller
- type Title
Constants ¶
const TreeEnd = "└─"
const TreeLink = "│"
const TreeMid = "├─"
Variables ¶
var ErrNotRecognized = errs.New("Not Recognized")
var SpinnerFrames = []string{`|`, `/`, `-`, `\`}
Functions ¶
func Structured ¶
func Structured(structured interface{}) *structuredOutput
Types ¶
type Config ¶
type Config struct { OutWriter io.Writer ErrWriter io.Writer Colored bool Interactive bool ShellName string }
Config is the thing we pass to Outputer constructors
func (*Config) OutWriterFD ¶
type Emphasize ¶
type Emphasize string
func (Emphasize) MarshalOutput ¶
func (Emphasize) MarshalStructured ¶
type Format ¶
type Format string
const ( PlainFormatName Format = "plain" // human readable SimpleFormatName Format = "simple" // human readable without notice level JSONFormatName Format = "json" // plain json EditorFormatName Format = "editor" // alias of "json" )
FormatName constants are tokens representing supported output formats.
func (Format) IsStructured ¶
type JSON ¶
type JSON struct {
// contains filtered or unexported fields
}
JSON is our JSON outputer, there's not much going on here, just forwards it to the JSON marshaller and provides a basic structure for error
func (*JSON) Error ¶
func (f *JSON) Error(value interface{})
Error will marshal and print the given value to the error writer NOTE that JSON always prints to the output writer, the error writer is unused.
func (*JSON) Fprint ¶
Fprint allows printing to a specific writer, using all the conveniences of the output package
func (*JSON) Notice ¶
func (f *JSON) Notice(value interface{})
Notice is ignored by JSON, as they are considered as non-critical output and there's currently no reliable way to reliably combine this data into the eventual output
type Marshaller ¶
type Marshaller interface {
MarshalOutput(Format) interface{}
}
type Outputer ¶
type Outputer interface { Fprint(writer io.Writer, value interface{}) Print(value interface{}) Error(value interface{}) Notice(value interface{}) Type() Format Config() *Config }
Outputer is the initialized formatter
type Plain ¶
type Plain struct {
// contains filtered or unexported fields
}
Plain is our plain outputer, it uses reflect to marshal the data. Semantic highlighting tags are supported as [NOTICE]foo[/RESET] Table output is supported if you pass a slice of structs Struct keys are localized by sending them to the locale library as field_key (lowercase)
func (*Plain) Error ¶
func (f *Plain) Error(value interface{})
Error will marshal and print the given value to the error writer, it wraps it in the error format but otherwise the only thing that identifies it as an error is the channel it writes it to
func (*Plain) Fprint ¶
Fprint allows printing to a specific writer, using all the conveniences of the output package
func (*Plain) Notice ¶
func (f *Plain) Notice(value interface{})
Notice will marshal and print the given value to the error writer, it wraps it in the notice format but otherwise the only thing that identifies it as an error is the channel it writes it to
type PlainOpts ¶
type PlainOpts string
PlainOpts define available tokens for setting plain output options.
const ( // SeparateLineOpt requests table output to be printed on a separate line (without columns) SeparateLineOpt PlainOpts = "separateLine" // VerticalTable requests a table be output vertically VerticalTable PlainOpts = "verticalTable" // EmptyNil replaces nil values with the empty string EmptyNil PlainOpts = "emptyNil" // HidePlain hides the field value in table output HidePlain PlainOpts = "hidePlain" // ShiftColsPrefix starts the column after the set qty ShiftColsPrefix PlainOpts = "shiftCols=" // OmitEmpty omits empty values from output OmitEmpty PlainOpts = "omitEmpty" // HideDash hides the dash in table output HideDash PlainOpts = "hideDash" // OmitKey hides the current struct key from output, its value is still printed OmitKey PlainOpts = "omitKey" )
type Simple ¶
type Simple struct {
Plain
}
Simple is an outputer that works exactly as Plain without any notice level output
type Spinner ¶
type Spinner struct {
// contains filtered or unexported fields
}
func (*Spinner) MarshalOutput ¶
type StructuredError ¶
StructuredError communicates that an error happened due to output that was meant to be structured but wasn't.
func (StructuredError) Error ¶
func (s StructuredError) Error() string
type StructuredMarshaller ¶
type StructuredMarshaller interface {
MarshalStructured(Format) interface{}
}