Documentation ¶
Index ¶
- Constants
- Variables
- func RenderTable(wr io.Writer, cfg Config, obj interface{}) error
- func SetupTable(wr io.Writer, cfg Config) (table *tablewriter.Table)
- func SupportedOutputFormats() (outputFormats []string)
- func Write(wr io.Writer, cfg Config, obj Outputtable) error
- type Config
- type DefaultFieldsHaver
- type Fn
- type Format
- type Outputtable
Constants ¶
const ( // List is the canonical name of the List output format List Format = "list" // Table is the canonical name of the Table output format Table = "table" // JSON is the canonical name of the JSON output format JSON = "json" // Human is the canonical name of the Human output format Human = "human" // Debug is the canonical name of the Debug output format Debug = "debug" )
Variables ¶
var FormatFns = map[Format]Fn{ Debug: func(wr io.Writer, cfg Config, obj Outputtable) error { _, err := fmt.Fprintf(wr, "%#v", obj) return err }, JSON: func(wr io.Writer, _ Config, obj Outputtable) error { encoder := json.NewEncoder(wr) encoder.SetIndent("", " ") return encoder.Encode(obj) }, List: outputTable, Table: outputTable, Human: func(wr io.Writer, _ Config, obj Outputtable) error { return obj.PrettyPrint(wr, prettyprint.Full) }, }
FormatFns is a map which contains all the supported output format functions -- except 'human' because that's implemented in the OutputInDesiredForm method, by necessity.
Functions ¶
func RenderTable ¶
RenderTable creates a table for the given object. This makes most sense when it's an array, but a regular struct-y object works fine too.
func SetupTable ¶
func SetupTable(wr io.Writer, cfg Config) (table *tablewriter.Table)
SetupTable creates a tablewriter.Table for the given writer and output config.
func SupportedOutputFormats ¶
func SupportedOutputFormats() (outputFormats []string)
SupportedOutputFormats returns a list of all suppported output forms, including 'human'
Types ¶
type Config ¶
Config is a simple struct to configure whichever OutputFormatFn is selected all its fields should be set regardless of Format.
type DefaultFieldsHaver ¶
type DefaultFieldsHaver interface { // DefaultFields must return a string of valid field names (according to github.com/BytemarkHosting/row - i.e. they must be in the list output by row.FieldsFrom) for the type it is implemented on. // It is used to discover what fields should be output by output.Write when there's no list of user-specified fields. DefaultFields(f Format) string }
DefaultFieldsHaver is an interface that must be implemented in order to pass objects to output.Write
type Fn ¶
type Fn func(wr io.Writer, config Config, obj Outputtable) error
Fn is a function for outputting an object to the terminal in some way See the FormatFns map to see examples
type Format ¶
type Format string
Format is a canonical name of output formats
func FormatByName ¶
FormatByName returns the Format for the given format name. If the name is not valid, returns Human
type Outputtable ¶
type Outputtable interface { prettyprint.PrettyPrinter DefaultFieldsHaver }
Outputtable is an interface that means the object has a default set of fields and an implementation of prettyprint.PrettyPrinter. This means it can be output as a table or list, or in a simpler human-readable format.