Documentation ¶
Index ¶
Constants ¶
const ( // ConfigFileName is the name of the FuseML configuration file (without extension) ConfigFileName = "config" // ConfigHomeSubdir is the subdirectory where the FuseML configuration files is located ConfigHomeSubdir = ".fuseml" // DefaultHTTPTimeout is the default HTTP timeout value DefaultHTTPTimeout = 30 )
Variables ¶
var OutputFormatIDs = map[OutputFormat][]string{ FormatTable: {"table"}, FormatJSON: {"json"}, FormatYAML: {"yaml"}, FormatCSV: {"csv"}, FormatText: {"text"}, }
OutputFormatIDs maps format values to their textual representations
Functions ¶
func CheckErr ¶
func CheckErr(err error)
CheckErr prints a user friendly error to STDERR and exits with a non-zero exit code. This function is used as a wrapper for the set of steps that comprise the execution of a cobra command. It is the common exit point used by all cobra `Run` handlers. This convention, in combination with the fact that cobra commands only use `Run` handlers, but not `RunE` handlers (i.e. they don't return errors back to the cobra framework), allows for better control over where and how errors are handled.
func LoadFileIntoVar ¶
LoadFileIntoVar loads the entire contents of a file into the supplied string variable
func UnpackLabelArgs ¶
UnpackLabelArgs converts a list of strings into a map. This helper function can be used to unpack command line arguments used to supplye dictionary values, e.g.:
--label foo:bar --label fan: --label fin
can be collected as an array of strings:
["foo:bar", "fan:", "fin"]
and then unpacked with this function into a corresponding map:
{"foo": "bar", "fan": "", "fin":""}
Types ¶
type FormattingOptions ¶
type FormattingOptions struct { // Output format Format OutputFormat // List of field specifiers controlling how information is converted from structured data into tabular format. // Each value can be formatted using the following syntax: // // <column-name>[:<field-name>[.<subfield-name>[...]]] // // The <column-name> token represents the name used for the header. If a field is not specified, it is also // interpreted as a field name and its value is not case-sensitive as far as it concerns matching the field names // in the structure information being formatting. // // The <field-name> and subsequent <subfield-name> tokens are used to identify the exact (sub)field in the hierarchically // structured information that the table column maps to. Their values are not case-sensitive. Fields []string // List of column names and their associated sorting mode, in sorting order. SortBy []table.SortBy // Custom formatting functions Formatters OutputFormatters }
FormattingOptions contains output formatting parameters
func NewFormattingOptions ¶
func NewFormattingOptions(fields []string, sortFields []table.SortBy, formatters OutputFormatters) (o *FormattingOptions)
NewFormattingOptions initializes formatting options for a cobra command. It accepts the following arguments:
- fields: list of field specifiers controlling how information is converted from structured data into tabular format (see FormattingOptions/Fields).
- sortFields: list of sort specifiers. Each specifier should indicate the column name and sort mode. The order is significant and will determine the order in which columns will be sorted.
- formatters: map of custom formatters. Use this to attach custom formatting handlers to columns that are not handled properly by the default formatting.
func NewSingleValueFormattingOptions ¶
func NewSingleValueFormattingOptions() (o *FormattingOptions)
NewSingleValueFormattingOptions initializes formatting options for a cobra command. Use this method instead of NewTableFormattingOptions if your command doesn't need to format list of objects in a table layout.
func (*FormattingOptions) AddMultiValueFormattingFlags ¶
func (o *FormattingOptions) AddMultiValueFormattingFlags(cmd *cobra.Command)
AddMultiValueFormattingFlags adds formatting command line flags to a cobra command. This function includes tabular formatting parameters. If the command only outputs single objects, use AddSingleValueFormattingFlags instead.
func (*FormattingOptions) AddSingleValueFormattingFlags ¶
func (o *FormattingOptions) AddSingleValueFormattingFlags(cmd *cobra.Command, defaultFormat OutputFormat)
AddSingleValueFormattingFlags adds formatting command line flags to a cobra command with the specified output format as default. This function does not include tabular formatting parameters. If the command also outputs lists of objects that can be formatted using a tabular layout, use AddMultiValueFormattingFlags instead.
func (*FormattingOptions) FormatValue ¶
func (o *FormattingOptions) FormatValue(out io.Writer, value interface{})
FormatValue formats any go struct or list of structs that can be converted into JSON, according to the configured formatting options.
type GlobalOptions ¶
type GlobalOptions struct { // URL to the FuseML server API URL string // HTTP timeout value used for REST API calls Timeout int // Verbose mode prints out additional information Verbose bool }
GlobalOptions contains global CLI configuration parameters
func (*GlobalOptions) Validate ¶
func (o *GlobalOptions) Validate() error
Validate validates the global configuration
type OutputFormat ¶
OutputFormat encodes the available formats that can be used to display structured data
const ( FormatTable OutputFormat = iota FormatJSON FormatYAML FormatCSV FormatText )
Supported output formats
type OutputFormatFunc ¶
OutputFormatFunc is a handler used to customize how a tabular field is formatted. The formatting utility calls the handler with the following arguments:
- object: the golang struct that represents the table row being formatted
- colume: the table column for which this handler is called
- field: the object that needs formatting
The handler must return a textual representation of the `field` object.
type OutputFormatters ¶
type OutputFormatters map[string]OutputFormatFunc
OutputFormatters is a map of output formatters, indexed by column name