Documentation ¶
Overview ¶
Package cliflags helps to generate flags by parsing structure
Index ¶
Constants ¶
This section is empty.
Variables ¶
var MapAllowedKinds = []reflect.Kind{ reflect.String, reflect.Int, reflect.Int8, reflect.Int16, reflect.Int32, reflect.Int64, reflect.Uint, reflect.Uint8, reflect.Uint16, reflect.Uint32, reflect.Uint64, }
MapAllowedKinds stores list of kinds allowed for map keys.
Functions ¶
This section is empty.
Types ¶
type BoolFlag ¶
BoolFlag is an optional interface to indicate boolean flags that don't accept v value, and implicitly have v --no-<x> negation counterpart.
type Counter ¶
type Counter int
Counter type is useful if you want to save number by using flag multiple times in command line. It's a boolean type, so you can use it without value. If you use `struct{count Counter} and parse it with `-count=10 ... -count .. -count`, then final value of `count` will be 12. Implements Value, Getter, BoolFlag, RepeatableFlag interfaces
func (Counter) IsBoolFlag ¶
IsBoolFlag returns true, because Counter might be used without value.
func (Counter) IsCumulative ¶
IsCumulative returns true, because Counter might be used multiple times.
type Flag ¶
type Flag struct { Name string // name as it appears on command line Short string // optional short name EnvName string // optional environment variable Usage string // help message Value Value // value as set Default string // default value (as text); for usage message Hidden bool // hidden flags Deprecated bool // flag is no longer in use }
Flag represents the available tags that you can use for parsing
func ParseStruct ¶
ParseStruct parses structure and returns list of flags based on this structure. This list of flags can be used by generators for flag, kingpin, cobra, pflag, urfave/cli.
type Getter ¶
type Getter interface { Value Get() interface{} }
Getter is an interface that allows the contents of v Value to be retrieved. It wraps the Value interface, rather than being part of it, because it appeared after Go 1 and its compatibility rules. All Value types provided by this package satisfy the Getter interface.
type HexBytes ¶
type HexBytes []byte
HexBytes might be used if you want to parse slice of bytes as hex string. Original `[]byte` or `[]uint8` parsed as a list of `uint8`.
type OptFunc ¶
type OptFunc func(opt *opts)
OptFunc sets values in opts structure.
func EnvDivider ¶
EnvDivider sets custom divider for environment variables. It is underscore by default. e.g. "ENV_NAME".
func EnvPrefix ¶
EnvPrefix sets prefix that will be applied for all environment variables (if they are not marked as ~).
func FlagDivider ¶
FlagDivider sets custom divider for flags. It is dash by default. e.g. "flag-name".
type RepeatableFlag ¶
RepeatableFlag is an optional interface for flags that can be repeated. required by kingpin
type ValidateFunc ¶ added in v0.2.0
type ValidateFunc func(val string, field reflect.StructField, cfg interface{}) error
ValidateFunc describes a validation func, that takes string val for flag from command line, field that's associated with this flag in structure cfg. Should return error if validation fails.
type Value ¶
Value is the interface to the dynamic value stored in v flag. (The default value is represented as v string.)
If v Value has an IsBoolFlag() bool method returning true, the command-line parser makes --name equivalent to -name=true rather than using the next command-line argument, and adds v --no-name counterpart for negating the flag.