Documentation ¶
Index ¶
- Constants
- Variables
- func Arg(i int) string
- func Args() []string
- func Bool(names []string, value bool, usage string) *bool
- func BoolVar(p *bool, names []string, value bool, usage string)
- func Duration(names []string, value time.Duration, usage string) *time.Duration
- func DurationVar(p *time.Duration, names []string, value time.Duration, usage string)
- func Float64(names []string, value float64, usage string) *float64
- func Float64Var(p *float64, names []string, value float64, usage string)
- func Int(names []string, value int, usage string) *int
- func Int64(names []string, value int64, usage string) *int64
- func Int64Var(p *int64, names []string, value int64, usage string)
- func IntVar(p *int, names []string, value int, usage string)
- func IsSet(name string) bool
- func Merge(dest *FlagSet, flagsets ...*FlagSet) error
- func NArg() int
- func NFlag() int
- func Parse()
- func Parsed() bool
- func PrintDefaults()
- func Set(name, value string) error
- func String(names []string, value string, usage string) *string
- func StringVar(p *string, names []string, value string, usage string)
- func Uint(names []string, value uint, usage string) *uint
- func Uint64(names []string, value uint64, usage string) *uint64
- func Uint64Var(p *uint64, names []string, value uint64, usage string)
- func UintVar(p *uint, names []string, value uint, usage string)
- func Var(value Value, names []string, usage string)
- func Visit(fn func(*Flag))
- func VisitAll(fn func(*Flag))
- type ErrorHandling
- type Flag
- type FlagSet
- func (fs *FlagSet) Arg(i int) string
- func (fs *FlagSet) Args() []string
- func (fs *FlagSet) Bool(names []string, value bool, usage string) *bool
- func (fs *FlagSet) BoolVar(p *bool, names []string, value bool, usage string)
- func (fs *FlagSet) CheckArgs() (message string)
- func (fs *FlagSet) Duration(names []string, value time.Duration, usage string) *time.Duration
- func (fs *FlagSet) DurationVar(p *time.Duration, names []string, value time.Duration, usage string)
- func (fs *FlagSet) FlagCount() int
- func (fs *FlagSet) FlagCountUndeprecated() int
- func (fs *FlagSet) Float64(names []string, value float64, usage string) *float64
- func (fs *FlagSet) Float64Var(p *float64, names []string, value float64, usage string)
- func (fs *FlagSet) Init(name string, errorHandling ErrorHandling)
- func (fs *FlagSet) Int(names []string, value int, usage string) *int
- func (fs *FlagSet) Int64(names []string, value int64, usage string) *int64
- func (fs *FlagSet) Int64Var(p *int64, names []string, value int64, usage string)
- func (fs *FlagSet) IntVar(p *int, names []string, value int, usage string)
- func (fs *FlagSet) IsEmpty() bool
- func (fs *FlagSet) IsSet(name string) bool
- func (fs *FlagSet) Lookup(name string) *Flag
- func (fs *FlagSet) NArg() int
- func (fs *FlagSet) NFlag() int
- func (fs *FlagSet) Name() string
- func (fs *FlagSet) Out() io.Writer
- func (fs *FlagSet) Parse(arguments []string) error
- func (fs *FlagSet) ParseFlags(args []string, withHelp bool) error
- func (fs *FlagSet) Parsed() bool
- func (fs *FlagSet) PrintDefaults()
- func (fs *FlagSet) ReportError(str string, withHelp bool)
- func (fs *FlagSet) Require(nArgRequirementType nArgRequirementType, nArg int)
- func (fs *FlagSet) Set(name, value string) error
- func (fs *FlagSet) SetOutput(output io.Writer)
- func (fs *FlagSet) String(names []string, value string, usage string) *string
- func (fs *FlagSet) StringVar(p *string, names []string, value string, usage string)
- func (fs *FlagSet) Uint(names []string, value uint, usage string) *uint
- func (fs *FlagSet) Uint64(names []string, value uint64, usage string) *uint64
- func (fs *FlagSet) Uint64Var(p *uint64, names []string, value uint64, usage string)
- func (fs *FlagSet) UintVar(p *uint, names []string, value uint, usage string)
- func (fs *FlagSet) Var(value Value, names []string, usage string)
- func (fs *FlagSet) Visit(fn func(*Flag))
- func (fs *FlagSet) VisitAll(fn func(*Flag))
- type Getter
- type Value
Constants ¶
const ( Exact nArgRequirementType = iota Max Min )
Indicator used to pass to BadArgs function
Variables ¶
var CommandLine = NewFlagSet(os.Args[0], ExitOnError)
CommandLine is the default set of command-line flags, parsed from os.Args. The top-level functions such as BoolVar, Arg, and on are wrappers for the methods of CommandLine.
var ErrHelp = errors.New("flag: help requested")
ErrHelp is the error returned if the flag -help is invoked but no such flag is defined.
var ErrRetry = errors.New("flag: retry")
ErrRetry is the error returned if you need to try letter by letter
var ShortUsage = func() { fmt.Fprintf(CommandLine.output, "Usage of %s:\n", os.Args[0]) }
Usage prints to standard error a usage message documenting the standard command layout The function is a variable that may be changed to point to a custom function.
var Usage = func() { fmt.Fprintf(CommandLine.Out(), "Usage of %s:\n", os.Args[0]) PrintDefaults() }
Usage prints to standard error a usage message documenting all defined command-line flags. The function is a variable that may be changed to point to a custom function.
Functions ¶
func Arg ¶
Arg returns the i'th command-line argument. Arg(0) is the first remaining argument after flags have been processed.
func Bool ¶
Bool defines a bool flag with specified name, default value, and usage string. The return value is the address of a bool variable that stores the value of the flag.
func BoolVar ¶
BoolVar defines a bool flag with specified name, default value, and usage string. The argument p points to a bool variable in which to store the value of the flag.
func Duration ¶
Duration defines a time.Duration flag with specified name, default value, and usage string. The return value is the address of a time.Duration variable that stores the value of the flag.
func DurationVar ¶
DurationVar defines a time.Duration flag with specified name, default value, and usage string. The argument p points to a time.Duration variable in which to store the value of the flag.
func Float64 ¶
Float64 defines a float64 flag with specified name, default value, and usage string. The return value is the address of a float64 variable that stores the value of the flag.
func Float64Var ¶
Float64Var defines a float64 flag with specified name, default value, and usage string. The argument p points to a float64 variable in which to store the value of the flag.
func Int ¶
Int defines an int flag with specified name, default value, and usage string. The return value is the address of an int variable that stores the value of the flag.
func Int64 ¶
Int64 defines an int64 flag with specified name, default value, and usage string. The return value is the address of an int64 variable that stores the value of the flag.
func Int64Var ¶
Int64Var defines an int64 flag with specified name, default value, and usage string. The argument p points to an int64 variable in which to store the value of the flag.
func IntVar ¶
IntVar defines an int flag with specified name, default value, and usage string. The argument p points to an int variable in which to store the value of the flag.
func Merge ¶
Merge is an helper function that merges n FlagSets into a single dest FlagSet In case of name collision between the flagsets it will apply the destination FlagSet's errorHandling behaviour.
func NArg ¶
func NArg() int
NArg is the number of arguments remaining after flags have been processed.
func Parse ¶
func Parse()
Parse parses the command-line flags from os.Args[1:]. Must be called after all flags are defined and before flags are accessed by the program.
func PrintDefaults ¶
func PrintDefaults()
PrintDefaults prints to standard error the default values of all defined command-line flags.
func String ¶
String defines a string flag with specified name, default value, and usage string. The return value is the address of a string variable that stores the value of the flag.
func StringVar ¶
StringVar defines a string flag with specified name, default value, and usage string. The argument p points to a string variable in which to store the value of the flag.
func Uint ¶
Uint defines a uint flag with specified name, default value, and usage string. The return value is the address of a uint variable that stores the value of the flag.
func Uint64 ¶
Uint64 defines a uint64 flag with specified name, default value, and usage string. The return value is the address of a uint64 variable that stores the value of the flag.
func Uint64Var ¶
Uint64Var defines a uint64 flag with specified name, default value, and usage string. The argument p points to a uint64 variable in which to store the value of the flag.
func UintVar ¶
UintVar defines a uint flag with specified name, default value, and usage string. The argument p points to a uint variable in which to store the value of the flag.
func Var ¶
Var defines a flag with the specified name and usage string. The type and value of the flag are represented by the first argument, of type Value, which typically holds a user-defined implementation of Value. For instance, the caller could create a flag that turns a comma-separated string into a slice of strings by giving the slice the methods of Value; in particular, Set would decompose the comma-separated string into the slice.
Types ¶
type ErrorHandling ¶
type ErrorHandling int
ErrorHandling defines how to handle flag parsing errors.
const ( ContinueOnError ErrorHandling = iota ExitOnError PanicOnError )
ErrorHandling strategies available when a flag parsing error occurs
type Flag ¶
type Flag struct { Names []string // name as it appears on command line Usage string // help message Value Value // value as set DefValue string // default value (as text); for usage message }
A Flag represents the state of a flag.
type FlagSet ¶
type FlagSet struct { // Usage is the function called when an error occurs while parsing flags. // The field is a function (not a method) that may be changed to point to // a custom error handler. Usage func() ShortUsage func() // contains filtered or unexported fields }
A FlagSet represents a set of defined flags. The zero value of a FlagSet has no name and has ContinueOnError error handling.
func NewFlagSet ¶
func NewFlagSet(name string, errorHandling ErrorHandling) *FlagSet
NewFlagSet returns a new, empty flag set with the specified name and error handling property.
func (*FlagSet) Arg ¶
Arg returns the i'th argument. Arg(0) is the first remaining argument after flags have been processed.
func (*FlagSet) Bool ¶
Bool defines a bool flag with specified name, default value, and usage string. The return value is the address of a bool variable that stores the value of the flag.
func (*FlagSet) BoolVar ¶
BoolVar defines a bool flag with specified name, default value, and usage string. The argument p points to a bool variable in which to store the value of the flag.
func (*FlagSet) CheckArgs ¶
CheckArgs uses the requirements set by FlagSet.Require() to validate the number of arguments. If the requirements are not met, an error message string is returned.
func (*FlagSet) Duration ¶
Duration defines a time.Duration flag with specified name, default value, and usage string. The return value is the address of a time.Duration variable that stores the value of the flag.
func (*FlagSet) DurationVar ¶
DurationVar defines a time.Duration flag with specified name, default value, and usage string. The argument p points to a time.Duration variable in which to store the value of the flag.
func (*FlagSet) FlagCountUndeprecated ¶
FlagCountUndeprecated returns the number of undeprecated flags that have been defined.
func (*FlagSet) Float64 ¶
Float64 defines a float64 flag with specified name, default value, and usage string. The return value is the address of a float64 variable that stores the value of the flag.
func (*FlagSet) Float64Var ¶
Float64Var defines a float64 flag with specified name, default value, and usage string. The argument p points to a float64 variable in which to store the value of the flag.
func (*FlagSet) Init ¶
func (fs *FlagSet) Init(name string, errorHandling ErrorHandling)
Init sets the name and error handling property for a flag set. By default, the zero FlagSet uses an empty name and the ContinueOnError error handling policy.
func (*FlagSet) Int ¶
Int defines an int flag with specified name, default value, and usage string. The return value is the address of an int variable that stores the value of the flag.
func (*FlagSet) Int64 ¶
Int64 defines an int64 flag with specified name, default value, and usage string. The return value is the address of an int64 variable that stores the value of the flag.
func (*FlagSet) Int64Var ¶
Int64Var defines an int64 flag with specified name, default value, and usage string. The argument p points to an int64 variable in which to store the value of the flag.
func (*FlagSet) IntVar ¶
IntVar defines an int flag with specified name, default value, and usage string. The argument p points to an int variable in which to store the value of the flag.
func (*FlagSet) Lookup ¶
Lookup returns the Flag structure of the named flag, returning nil if none exists.
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. The return value will be ErrHelp if -help was set but not defined.
func (*FlagSet) ParseFlags ¶
ParseFlags is a utility function that adds a help flag if withHelp is true, calls fs.Parse(args) and prints a relevant error message if there are incorrect number of arguments. It returns error only if error handling is set to ContinueOnError and parsing fails. If error handling is set to ExitOnError, it's safe to ignore the return value.
func (*FlagSet) PrintDefaults ¶
func (fs *FlagSet) PrintDefaults()
PrintDefaults prints, to standard error unless configured otherwise, the default values of all defined flags in the set.
func (*FlagSet) ReportError ¶
ReportError is a utility method that prints a user-friendly message containing the error that occured during parsing and a suggestion to get help
func (*FlagSet) Require ¶
Require adds a requirement about the number of arguments for the FlagSet. The first parameter can be Exact, Max, or Min to respectively specify the exact, the maximum, or the minimal number of arguments required. The actual check is done in FlagSet.CheckArgs().
func (*FlagSet) SetOutput ¶
SetOutput sets the destination for usage and error messages. If output is nil, os.Stderr is used.
func (*FlagSet) String ¶
String defines a string flag with specified name, default value, and usage string. The return value is the address of a string variable that stores the value of the flag.
func (*FlagSet) StringVar ¶
StringVar defines a string flag with specified name, default value, and usage string. The argument p points to a string variable in which to store the value of the flag.
func (*FlagSet) Uint ¶
Uint defines a uint flag with specified name, default value, and usage string. The return value is the address of a uint variable that stores the value of the flag.
func (*FlagSet) Uint64 ¶
Uint64 defines a uint64 flag with specified name, default value, and usage string. The return value is the address of a uint64 variable that stores the value of the flag.
func (*FlagSet) Uint64Var ¶
Uint64Var defines a uint64 flag with specified name, default value, and usage string. The argument p points to a uint64 variable in which to store the value of the flag.
func (*FlagSet) UintVar ¶
UintVar defines a uint flag with specified name, default value, and usage string. The argument p points to a uint variable in which to store the value of the flag.
func (*FlagSet) Var ¶
Var defines a flag with the specified name and usage string. The type and value of the flag are represented by the first argument, of type Value, which typically holds a user-defined implementation of Value. For instance, the caller could create a flag that turns a comma-separated string into a slice of strings by giving the slice the methods of Value; in particular, Set would decompose the comma-separated string into the slice.
type Getter ¶
type Getter interface { Value Get() interface{} }
Getter is an interface that allows the contents of a 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.