Documentation ¶
Index ¶
- Constants
- func Add(flag *Flag)
- func Args() []string
- func Bool(bvar *bool, long, short, description string, hasArg bool)
- func Count(cvar *int, long, short, description string)
- func Duration(dvar *time.Duration, long, short, description string)
- func Float64(fvar *float64, long, short, description string)
- func Help(long, short, description string)
- func Int(ivar *int, long, short, description string)
- func Parse() error
- func String(svar *string, long, short, description string)
- func Struct(svar interface{})
- type Flag
- type FlagArg
- type FlagSet
- func (f *FlagSet) Add(flag *Flag)
- func (f *FlagSet) Args() []string
- func (f *FlagSet) Bool(bvar *bool, long, short, description string, hasArg bool)
- func (f *FlagSet) Count(cvar *int, long, short, description string)
- func (f *FlagSet) Duration(dvar *time.Duration, long, short, description string)
- func (f *FlagSet) Float64(fvar *float64, long, short, description string)
- func (f *FlagSet) Help(long, short, description string)
- func (f *FlagSet) Int(ivar *int, long, short, description string)
- func (f *FlagSet) Parse(args []string) error
- func (f *FlagSet) String(svar *string, long, short, description string)
- func (f *FlagSet) Struct(svar interface{})
- func (f *FlagSet) Usage() string
- func (f *FlagSet) VisitAll(fn func(*Flag))
- type Value
Constants ¶
const ( ContinueOnError errorHandling = iota // Return a descriptive error. ExitOnError // Print a descriptive error to os.Stderr and call os.Exit(2). PanicOnError // Call panic with a descriptive error. )
These constants cause FlagSet.Parse to behave as described if the parse fails.
Variables ¶
This section is empty.
Functions ¶
func Args ¶
func Args() []string
Args returns the remaining arguments once options have been parsed.
func Bool ¶
Bool adds a bool flag with specified long/short form and description. hasArg indicates whether the flag accepts an optional argument (eg. --flag=false).
func Help ¶
func Help(long, short, description string)
Help sets the help flag's long/short form and description.
func Parse ¶
func Parse() error
Parse parses flag definitions from the argument list, which should not include the command name. Must be called after all flags in the FlagSet are defined and before flags are accessed by the program.
Types ¶
type Flag ¶
type Flag struct { // Long option name. Long string // Short option name. Short string // Description for the option, as it will appear in help usage. Description string // Specifies whether or not the option accepts an argument: // - when set to nil, the option doesn't accept any argument // - when set to &FlagArg{}, the option requires an argument // - when set to &FlagArg{"default", ""}, the option accepts // an optional argument which defaults to "default". Arg *FlagArg // Value is the interface to the dynamic value stored in the flag. Value Value // Hidden indicates that the option should be hidden in help usage. Hidden bool // Usage can be set to overwrite the option usage line in the help usage. Usage string // Final indicates that option parsing should stop when the option is seen. // This is generally not to be used, except for some options such as --help or --version. Final bool }
Flag is a representation for a command line option.
type FlagArg ¶
FlagArg represents a flag argument. An empty Default indicates that the argument is required.
type FlagSet ¶
type FlagSet struct { // Abbreviations indicates that option abbreviations are supported. Abbreviations bool // DisableHelp disables help usage. DisableHelp bool // ErrorHandling defines how FlagSet.Parse behaves when parsing fails. ErrorHandling errorHandling // Ordered indicates that command-line options are expected before operands. // This means that the parsing will stop when an operand is seen. Ordered bool // UsageLine can be set to overwrite the flag help usage. UsageLine string // UsageFunc UsageFunc func(*FlagSet) string // contains filtered or unexported fields }
A FlagSet represents a set of defined flags. The zero value of a FlagSet has ContinueOnError error handling and doesn't add a help flag.
func (*FlagSet) Bool ¶
Bool adds a bool flag with specified long/short form and description. hasArg indicates whether the flag accepts an optional argument (eg. --flag=false).
func (*FlagSet) Duration ¶
Duration adds a duration flag with specified long/short form and description.
func (*FlagSet) Float64 ¶
Float64 adds a float64 flag with specified long/short form and description.
func (*FlagSet) Parse ¶
Parse parses flag definitions from the argument list, which should not include the command name. Must be called after all flags in the FlagSet are defined and before flags are accessed by the program.