Documentation ¶
Index ¶
- Constants
- Variables
- func CheckErr(err error)
- func DeleteKeyAndWriteConfigFile(key string) error
- func FormatMapField(object interface{}, column string, field interface{}) (formated string)
- func FormatSliceField(object interface{}, column string, field interface{}) (formated string)
- func LoadFileIntoVar(filePath string, destContent *string) error
- func ValidateEnumArgument(argName, argValue string, values []string) error
- func WriteConfigFile() error
- type FormattingOptions
- type GlobalOptions
- type KeyValueArgs
- type OutputFormat
- type OutputFormatFunc
- type OutputFormatters
Constants ¶
const ( // ConfigFileName is the name of the FuseML configuration file (without extension) ConfigFileName = "config" // ConfigFileType is the type of default config file ConfigFileType = "yaml" // ConfigHomeSubdir is the main subdirectory where the user configuration files are located ConfigHomeSubdir = ".config" // ConfigFuseMLSubdir is the subdirectory where the FuseML configuration file is located ConfigFuseMLSubdir = "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 DeleteKeyAndWriteConfigFile ¶ added in v0.3.0
Writes the current content of file and also deletes given key from it As viper does not support this operation directly, here's a workaround taken from https://github.com/spf13/viper/issues/632
func FormatMapField ¶ added in v0.2.1
FormatMapField is a generic formatter for map fields
func FormatSliceField ¶ added in v0.2.1
FormatSliceField is a generic formatter for slice fields
func LoadFileIntoVar ¶
LoadFileIntoVar loads the entire contents of a file into the supplied string variable
func ValidateEnumArgument ¶ added in v0.2.1
ValidateEnumArgument is used to validate command line arguments that can take a limited set of values
func WriteConfigFile ¶ added in v0.2.1
func WriteConfigFile() error
WriteConfigFile writes new content of the config file. If the file does not exist, it is created at default location TODO temporary solution until upstream https://github.com/spf13/viper/issues/433 is fixed
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 // CurrentProject says which project to use if "project" flag is not passed CurrentProject string // CurrentCodeset sets which codeset to use if the name is not provided CurrentCodeset string }
GlobalOptions contains global CLI configuration parameters
func (*GlobalOptions) Validate ¶
func (o *GlobalOptions) Validate() error
Validate validates the global configuration
type KeyValueArgs ¶ added in v0.2.1
KeyValueArgs is used with key-value command line arguments
func (*KeyValueArgs) Unpack ¶ added in v0.2.1
func (args *KeyValueArgs) Unpack()
Unpack 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":""}
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