Documentation ¶
Index ¶
- Constants
- func HelpOptions() (optionNames []string)
- func NewStringSliceValue(slicePointer *[]string, defaultValue []string) (v flag.Value)
- func OptionValues(optionData []OptionData) (effectiveValueMap, defaultsMap map[string]string)
- type ArgParser
- type OptionData
- type StringSliceValue
- type VisitedOptions
Constants ¶
const ( // the os.Args value of debug option: “-debug” DebugOption = "-" + DebugOptionName // the name of debug option “debug” DebugOptionName = "debug" )
Variables ¶
This section is empty.
Functions ¶
func HelpOptions ¶
func HelpOptions() (optionNames []string)
returns implicit help options: "h" "help"
func NewStringSliceValue ¶ added in v0.4.113
NewStringSliceValue initializes a slice option
- the option’s value is stored in a slice at slicePointer
- defaultValue may be nil
- flag.Value is an interface of the flag package storing non-standard value types
func OptionValues ¶ added in v0.4.113
func OptionValues(optionData []OptionData) (effectiveValueMap, defaultsMap map[string]string)
OptionValues returns a printable map of current values
- %v: map[debug:false …]
Types ¶
type ArgParser ¶
type ArgParser struct {
// contains filtered or unexported fields
}
ArgParser invokes flag.Parse with off-flags support. pflags package compared to flags package:
- ability to use declarative options
- ability to read default option values from yaml configuration files
- support for multiple-strings option value
- support for unary off-flags, “-no-flag” options
- map or list of visited options
func NewArgParser ¶
func NewArgParser(optionsList []OptionData, usage func()) (argParser *ArgParser)
NewArgParser returns an options-parser with off-flags support
func (*ArgParser) Parse ¶
func (a *ArgParser) Parse()
Parse invokes flag.Parse after providing optionsList and usage to flag package
- -no-flagname flags are inverted before and after
type OptionData ¶
type OptionData struct { P interface{} // P is a reference to where the effective value of this option is stored Name string // Name is the option name without hyphen, “debug” for -debug Value interface{} // Value is the default value for this option Usage string // printable string describing what this option does Y interface{} // reference to effective value in YamlData }
OptionData contain options data for the flag package
- OptionData is used for command-line options to be declarative
- instead of flag.BoolVar and similar invocations scattered about the codebase all options are in a single OptionData slice that is iterated so that AddOption is invoked for each element
- to invoke flag.BoolVar. pointer, name, value and usage is required
- flag.BoolVar is consumer-provided storage, flag.Bool is flag-provided storage
func (*OptionData) AddOption ¶
func (o *OptionData) AddOption()
AddOption executes flag.BoolVar and such on the options map
- this defines the option to the flag package
- all options must be defined prior to invoking flag.Parse
- options are defined using value pointers, ie flag.BoolVar not flag.Bool[], so flag.Parse updates effective option values directly
func (*OptionData) ApplyYaml ¶
func (o *OptionData) ApplyYaml() (err error)
ApplyYaml copies a value read from yaml into the effective value location
func (*OptionData) ValueDump ¶ added in v0.4.113
func (o *OptionData) ValueDump() (valueS string)
type StringSliceValue ¶
type StringSliceValue struct {
// contains filtered or unexported fields
}
StringSliceValue manages a string-slice value for flag.Var
func (*StringSliceValue) Set ¶
func (v *StringSliceValue) Set(optionValue string) (err error)
Set updates the string slice
- Set is invoked once for each option-occurrence in the command line
- Set appends each such option value to its list of strings
func (StringSliceValue) String ¶
func (v StringSliceValue) String() (s string)
flag package invoke String to render default value
type VisitedOptions ¶ added in v0.4.113
type VisitedOptions struct {
// contains filtered or unexported fields
}
func NewVisitedOptions ¶ added in v0.4.113
func NewVisitedOptions() (o *VisitedOptions)
func (*VisitedOptions) Map ¶ added in v0.4.113
func (o *VisitedOptions) Map() (m map[string]bool)
func (*VisitedOptions) Slice ¶ added in v0.4.113
func (o *VisitedOptions) Slice() (s []string)