Documentation
¶
Index ¶
- Constants
- Variables
- func AddDebugFlag(flagSet *pflag.FlagSet)
- func AddHideTagsFormatFlag(flagSet *pflag.FlagSet)
- func AddInputFlags(flagSet *pflag.FlagSet)
- func AddOutputFlags(flagSet *pflag.FlagSet)
- func AddTtyFlags(flagSet *pflag.FlagSet)
- func ConvertDecodeErr(err error, reals map[string]string) error
- func DecodeHook(from, to reflect.Type, data interface{}) (interface{}, error)
- func FindField(t reflect.Type, name string, ns FieldNamespace) (reflect.StructField, bool)
- func FindHierField(t reflect.Type, hierName string, ns FieldNamespace) (reflect.StructField, bool)
- func GenGroup(use, short string, cmds []*Command) *cobra.Command
- func GetFieldTaggedName(sf reflect.StructField, ns FieldNamespace) string
- func GetGenericObj(dataMap interface{}) (map[string]interface{}, error)
- func GetGenericObjFromList(dataMap interface{}, idx int) (map[string]interface{}, error)
- func GetParseHelp(t reflect.Type) (string, string, bool)
- func GetParseHelpKind(k reflect.Kind) string
- func GetSpecialArgs(obj interface{}) map[string]string
- func GetSpecifiedFields(data *MapData, obj interface{}) []string
- func GroupRunE(cmd *cobra.Command, args []string) error
- func LocalFlagsUsageNoNewline(cmd *cobra.Command) string
- func MapJsonNamesT(dat, js map[string]interface{}, t reflect.Type, inputNS FieldNamespace) error
- func MapToArgs(prefix []string, dat map[string]interface{}, ignore map[string]struct{}, ...) []string
- func MarshalArgs(obj interface{}, ignore []string, aliases []string, ...) ([]string, error)
- func WeakDecode(input, output interface{}, hook mapstructure.DecodeHookFunc) ([]string, error)
- type Command
- type FieldNamespace
- type GetStructMapOp
- type GetStructMapOptions
- type GroupCommand
- type Input
- type MapData
Constants ¶
const ( OutputFormatYaml = "yaml" OutputFormatJson = "json" OutputFormatJsonCompact = "json-compact" OutputFormatTable = "table" )
Variables ¶
var Data string
var Datafile string
var Debug bool
var HideTags string
HideTags is a comma separated list of tag names that are matched against the protocmd.hidetag field option. Fields that match will be zeroed-out on output objects, effectively hiding them when outputing json or yaml. How this is set is up to the user, but typically a global flag can be used.
var Interactive bool
var NoFlags func(flagSet *pflag.FlagSet) = nil
var OutputFormat = OutputFormatYaml
var OutputFormats = []string{ OutputFormatYaml, OutputFormatJson, OutputFormatJsonCompact, OutputFormatTable, }
var OutputStream bool
var Parsable bool
var SilenceUsage bool
var Tty bool
Functions ¶
func AddDebugFlag ¶
func AddHideTagsFormatFlag ¶
func AddInputFlags ¶
func AddOutputFlags ¶
func AddTtyFlags ¶
func DecodeHook ¶
func FindField ¶
func FindField(t reflect.Type, name string, ns FieldNamespace) (reflect.StructField, bool)
func FindHierField ¶
func FindHierField(t reflect.Type, hierName string, ns FieldNamespace) (reflect.StructField, bool)
func GetFieldTaggedName ¶
func GetFieldTaggedName(sf reflect.StructField, ns FieldNamespace) string
Get the field name based on the namespace
func GetGenericObj ¶
func GetGenericObjFromList ¶
func GetParseHelp ¶
GetParseHelp gets end-user specific messages for error messages without any golang-specific language. It returns a non-golang specific type name, a help message with valid values, and a bool that represents whether the original error should be suppressed because it is too golang-specific.
func GetParseHelpKind ¶
func GetSpecialArgs ¶
func GetSpecifiedFields ¶
Get a list of fields specified as their hierarchical id space. I.e. a field will be "1", or "2.2", based on the protobuf id and hierarchy. Data contains the specified data hierarchically arranged. Obj is the protobuf object with protobuf tags on fields that corresponds to the data.
func GroupRunE ¶
For group commands, if no subcommand is specified, we want to return an error (unless help was specified).
func LocalFlagsUsageNoNewline ¶
For usage, the cobra code converts the entire usage to a string and then calls Println on it. This ends up introducing an extra unsightly newline in the output. Flags should be last, so this gets the flags output without the final new line.
func MapJsonNamesT ¶
func MapJsonNamesT(dat, js map[string]interface{}, t reflect.Type, inputNS FieldNamespace) error
func MarshalArgs ¶
func MarshalArgs(obj interface{}, ignore []string, aliases []string, queryParams map[string]string) ([]string, error)
MarshalArgs generates a name=val arg list from the object. Arg names that should be ignore can be specified. Names are the same format as arg names, lowercase of field names, joined by '.' Aliases are of the form alias=hiername.
func WeakDecode ¶
func WeakDecode(input, output interface{}, hook mapstructure.DecodeHookFunc) ([]string, error)
Use mapstructure to convert an args map (map[string]interface{}) to fill in an object in output.
Types ¶
type Command ¶
type Command struct { Use string Short string RequiredArgs string OptionalArgs string AliasArgs string SpecialArgs *map[string]string Comments map[string]string QueryParams string QueryComments map[string]string ReqData interface{} ReplyData interface{} PasswordArg string CurrentPasswordArg string VerifyPassword bool DataFlagOnly bool StreamOut bool StreamOutIncremental bool CobraCmd *cobra.Command Run func(c *Command, args []string) error UsageIsHelp bool Annotations map[string]string AddFlagsFunc func(*pflag.FlagSet) // contains filtered or unexported fields }
func (*Command) ParseInput ¶
ParseInput converts args to generic map. Input can come in 3 flavors, arg=value lists, yaml data, or json data. The output is generic map[string]interface{} holding the data, but normally each input format would have slightly different values for the map keys (field names) due to json or yaml tags being different from the go struct field name and each other. So we settle on the output map using json field names for consistency.
type FieldNamespace ¶
type FieldNamespace int
FieldNamespace describes the format of field names in generic map[string]interface{} data, whether they correspond to the go struct's field names, yaml tag names, json tag names, or arg names. Note that arg names are just lower-cased field names. It does not specify what format the values are in. Values may be type-specific (if extracted from an object with type info), or may be generic values (if unmarshaling yaml/json into map[string]interface{} where type info is not present).
const ( StructNamespace FieldNamespace = iota YamlNamespace JsonNamespace ArgsNamespace )
func (FieldNamespace) String ¶
func (s FieldNamespace) String() string
type GetStructMapOp ¶
type GetStructMapOp func(opts *GetStructMapOptions)
func WithStructMapFieldFlags ¶
func WithStructMapFieldFlags(fieldFlags []string) GetStructMapOp
Only include fields specified by the field flags, which are based on the protobuf id tag.
type GetStructMapOptions ¶
type GetStructMapOptions struct {
// contains filtered or unexported fields
}
type GroupCommand ¶
type GroupCommand struct {
UsageIsHelp bool
}
type Input ¶
type Input struct { // Required argument names RequiredArgs []string // Alias argument names, format is alias=real AliasArgs []string // Special argument names, format is arg=argType SpecialArgs *map[string]string // Password arg will prompt for password if not in args list PasswordArg string // Current password arg will prompt for current password if not in args list CurrentPasswordArg string // API key arg will replace password and avoid prompt for password ApiKeyArg string // Verify password if prompting VerifyPassword bool // Mapstructure DecodeHook functions DecodeHook mapstructure.DecodeHookFunc // Allow extra args that were not mapped to target object. AllowUnused bool // Args that are query params and not part of the object QueryParams []string }
func (*Input) ParseArgs ¶
Args are format name=val, where name could be a hierarchical name separated by ., i.e. appdata.key.name. Arg names should be all lowercase, matching the struct field names. This returns a generic map of values set by the args, again based on lower case field names, ignoring any json/yaml tags. It also fills in obj if specified. NOTE: arrays and maps not supported yet.
type MapData ¶
type MapData struct { Namespace FieldNamespace Data map[string]interface{} QueryParams map[string]string }
MapData associates generic imported mapped data with the namespace that the keys are in.
func GetStructMap ¶
func GetStructMap(obj interface{}, ops ...GetStructMapOp) (*MapData, error)
GetStructMap converts the object to a StructMap.