Documentation
¶
Index ¶
- Variables
- func Arg(i int) string
- func Args() []string
- func Bool(name string, value bool, usage string, required, isset bool) *bool
- func BoolVar(p *bool, name string, value bool, usage string, required, isset bool)
- func Color(colorString string) func(...interface{}) string
- func Duration(name string, value time.Duration, usage string, required, isset bool) *time.Duration
- func DurationVar(p *time.Duration, name string, value time.Duration, usage string, ...)
- func Float32(name string, value float32, usage string, required, isset bool) *float32
- func Float32Var(p *float32, name string, value float32, usage string, required, isset bool)
- func Float64(name string, value float64, usage string, required, isset bool) *float64
- func Float64Var(p *float64, name string, value float64, usage string, required, isset bool)
- func Int(name string, value int, usage string, required, isset bool) *int
- func Int16(name string, value int16, usage string, required, isset bool) *int16
- func Int16Var(p *int16, name string, value int16, usage string, required, isset bool)
- func Int32(name string, value int32, usage string, required, isset bool) *int32
- func Int32Var(p *int32, name string, value int32, usage string, required, isset bool)
- func Int64(name string, value int64, usage string, required, isset bool) *int64
- func Int64Var(p *int64, name string, value int64, usage string, required, isset bool)
- func Int8(name string, value int8, usage string, required, isset bool) *int8
- func Int8Var(p *int8, name string, value int8, usage string, required, isset bool)
- func IntVar(p *int, name string, value int, usage string, required, isset bool)
- func IsSet(name string) bool
- func MakeVar(addr interface{}, name, defaultValue, usage, override string, ...)
- func MapFromText(arg interface{}, textArg ...string) (err error)
- func NArg() int
- func NFlag() int
- func Ok(name string) bool
- func Parse()
- func Parsed() bool
- func PrintDefaults()
- func Required(name string) bool
- func Set(name, value string) error
- func String(name string, value string, usage string, required, isset bool) *string
- func StringVar(p *string, name string, value string, usage string, required, isset bool)
- func Uint(name string, value uint, usage string, required, isset bool) *uint
- func Uint16(name string, value uint16, usage string, required, isset bool) *uint16
- func Uint16Var(p *uint16, name string, value uint16, usage string, required, isset bool)
- func Uint32(name string, value uint32, usage string, required, isset bool) *uint32
- func Uint32Var(p *uint32, name string, value uint32, usage string, required, isset bool)
- func Uint64(name string, value uint64, usage string, required, isset bool) *uint64
- func Uint64Var(p *uint64, name string, value uint64, usage string, required, isset bool)
- func Uint8(name string, value uint8, usage string, required, isset bool) *uint8
- func Uint8Var(p *uint8, name string, value uint8, usage string, required, isset bool)
- func UintVar(p *uint, name string, value uint, usage string, required, isset bool)
- func UnquoteUsage(flag *Flag) (name string, usage string)
- func Var(value Value, name string, usage string, required, isset bool)
- func Visit(fn func(*Flag))
- func VisitAll(fn func(*Flag))
- type ErrorHandling
- type Flag
- type FlagSet
- func (f *FlagSet) Arg(i int) string
- func (f *FlagSet) Args() []string
- func (f *FlagSet) Bool(name string, value bool, usage string, required, isset bool) *bool
- func (f *FlagSet) BoolVar(p *bool, name string, value bool, usage string, required, isset bool)
- func (f *FlagSet) Duration(name string, value time.Duration, usage string, required, isset bool) *time.Duration
- func (f *FlagSet) DurationVar(p *time.Duration, name string, value time.Duration, usage string, ...)
- func (f *FlagSet) Float32(name string, value float32, usage string, required, isset bool) *float32
- func (f *FlagSet) Float32Var(p *float32, name string, value float32, usage string, required, isset bool)
- func (f *FlagSet) Float64(name string, value float64, usage string, required, isset bool) *float64
- func (f *FlagSet) Float64Var(p *float64, name string, value float64, usage string, required, isset bool)
- func (f *FlagSet) Init(name string, errorHandling ErrorHandling)
- func (f *FlagSet) Int(name string, value int, usage string, required, isset bool) *int
- func (f *FlagSet) Int16(name string, value int16, usage string, required, isset bool) *int16
- func (f *FlagSet) Int16Var(p *int16, name string, value int16, usage string, required, isset bool)
- func (f *FlagSet) Int32(name string, value int32, usage string, required, isset bool) *int32
- func (f *FlagSet) Int32Var(p *int32, name string, value int32, usage string, required, isset bool)
- func (f *FlagSet) Int64(name string, value int64, usage string, required, isset bool) *int64
- func (f *FlagSet) Int64Var(p *int64, name string, value int64, usage string, required, isset bool)
- func (f *FlagSet) Int8(name string, value int8, usage string, required, isset bool) *int8
- func (f *FlagSet) Int8Var(p *int8, name string, value int8, usage string, required, isset bool)
- func (f *FlagSet) IntVar(p *int, name string, value int, usage string, required, isset bool)
- func (f *FlagSet) IsSet(name string) bool
- func (f *FlagSet) Lookup(name string) *Flag
- func (f *FlagSet) NArg() int
- func (f *FlagSet) NFlag() int
- func (f *FlagSet) Ok(name string) bool
- func (f *FlagSet) Parse(arguments []string) error
- func (f *FlagSet) Parsed() bool
- func (f *FlagSet) PrintDefaults()
- func (f *FlagSet) Required(name string) bool
- func (f *FlagSet) Reset()
- func (f *FlagSet) Set(name, value string) error
- func (f *FlagSet) SetOutput(output io.Writer)
- func (f *FlagSet) String(name string, value string, usage string, required, isset bool) *string
- func (f *FlagSet) StringVar(p *string, name string, value string, usage string, required, isset bool)
- func (f *FlagSet) Uint(name string, value uint, usage string, required, isset bool) *uint
- func (f *FlagSet) Uint16(name string, value uint16, usage string, required, isset bool) *uint16
- func (f *FlagSet) Uint16Var(p *uint16, name string, value uint16, usage string, required, isset bool)
- func (f *FlagSet) Uint32(name string, value uint32, usage string, required, isset bool) *uint32
- func (f *FlagSet) Uint32Var(p *uint32, name string, value uint32, usage string, required, isset bool)
- func (f *FlagSet) Uint64(name string, value uint64, usage string, required, isset bool) *uint64
- func (f *FlagSet) Uint64Var(p *uint64, name string, value uint64, usage string, required, isset bool)
- func (f *FlagSet) Uint8(name string, value uint8, usage string, required, isset bool) *uint8
- func (f *FlagSet) Uint8Var(p *uint8, name string, value uint8, usage string, required, isset bool)
- func (f *FlagSet) UintVar(p *uint, name string, value uint, usage string, required, isset bool)
- func (f *FlagSet) Var(value Value, name, usage string, required, isset bool)
- func (f *FlagSet) Visit(fn func(*Flag))
- func (f *FlagSet) VisitAll(fn func(*Flag))
- type Getter
- type Value
Constants ¶
This section is empty.
Variables ¶
var ( Black = Color("\033[1;30m%s\033[0m") Red = Color("\033[1;31m%s\033[0m") Green = Color("\033[1;32m%s\033[0m") Yellow = Color("\033[1;33m%s\033[0m") Purple = Color("\033[1;34m%s\033[0m") Magenta = Color("\033[1;35m%s\033[0m") Teal = Color("\033[1;36m%s\033[0m") White = Color("\033[1;37m%s\033[0m") )
var ErrHelp = errors.New("flag: help requested")
ErrHelp is the error returned if the -help or -h flag is invoked but no such flag is defined.
var ErrInvalidArgPointerRequired = fmt.Errorf("Argument must be a pointer")
ErrInvalidArgPointerRequired pointer error message
var LookupEnv = syscall.Getenv
var SupressFlagUsageMsg = false
var SupressFlagUsageMsgBools = map[string]bool{ "1": true, "T": true, "TRUE": true, "True": true, "t": true, "true": true, }
SupressFlagUsageMsgBools is the map of booleans to accept from the environment variable SUPPRESS_FLAG_USAGE_MSG 1,T,t,True,TRUE or true
var Usage = func() { fmt.Fprintf(os.Stderr, "Usage of %s:\n", os.Args[0]) PrintDefaults() }
Usage prints to standard error a usage message documenting all defined command-line flags. It is called when an error occurs while parsing flags. The function is a variable that may be changed to point to a custom function. By default it prints a simple header and calls PrintDefaults; for details about the format of the output and how to control it, see the documentation for PrintDefaults.
Functions ¶
func Arg ¶
Arg returns the i'th command-line argument. Arg(0) is the first remaining argument after flags have been processed. Arg returns an empty string if the requested element does not exist.
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. The flag accepts a value acceptable to time.ParseDuration.
func DurationVar ¶
func DurationVar(p *time.Duration, name string, value time.Duration, usage string, required, isset bool)
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. The flag accepts a value acceptable to time.ParseDuration.
func Float32 ¶
Float32 defines a float32 flag with specified name, default value, and usage string. The return value is the address of a float32 variable that stores the value of the flag.
func Float32Var ¶
Float32Var defines a float32 flag with specified name, default value, and usage string. The argument p points to a float32 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 Int16 ¶
Int16 defines an int16 flag with specified name, default value, and usage string. The return value is the address of an int16 variable that stores the value of the flag.
func Int16Var ¶
Int16Var defines an int16 flag with specified name, default value, and usage string. The argument p points to an int16 variable in which to store the value of the flag.
func Int32 ¶
Int32 defines an int32 flag with specified name, default value, and usage string. The return value is the address of an int32 variable that stores the value of the flag.
func Int32Var ¶
Int32Var defines an int32 flag with specified name, default value, and usage string. The argument p points to an int32 variable in which to store 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 Int8 ¶
Int8 defines an int8 flag with specified name, default value, and usage string. The return value is the address of an int8 variable that stores the value of the flag.
func Int8Var ¶
Int8Var defines an int8 flag with specified name, default value, and usage string. The argument p points to an int8 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 MapFromText ¶
MapFromText interface text to value
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 unless configured otherwise, a usage message showing the default settings of all defined command-line flags. For an integer valued flag x, the default output has the form
-x int usage-message-for-x (default 7)
The usage message will appear on a separate line for anything but a bool flag with a one-byte name. For bool flags, the type is omitted and if the flag name is one byte the usage message appears on the same line. The parenthetical default is omitted if the default is the zero value for the type. The listed type, here int, can be changed by placing a back-quoted name in the flag's usage string; the first such item in the message is taken to be a parameter name to show in the message and the back quotes are stripped from the message when displayed. For instance, given
flag.String("I", "", "search `directory` for include files")
the output will be
-I directory search directory for include files.
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 Uint16 ¶
Uint16 defines a uint16 flag with specified name, default value, and usage string. The return value is the address of a uint16 variable that stores the value of the flag.
func Uint16Var ¶
Uint16Var defines a uint16 flag with specified name, default value, and usage string. The argument p points to a uint16 variable in which to store the value of the flag.
func Uint32 ¶
Uint32 defines a uint32 flag with specified name, default value, and usage string. The return value is the address of a uint32 variable that stores the value of the flag.
func Uint32Var ¶
Uint32Var defines a uint32 flag with specified name, default value, and usage string. The argument p points to a uint32 variable in which to store 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 Uint8 ¶
Uint8 defines a uint8 flag with specified name, default value, and usage string. The return value is the address of a uint8 variable that stores the value of the flag.
func Uint8Var ¶
Uint8Var defines a uint8 flag with specified name, default value, and usage string. The argument p points to a uint8 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 UnquoteUsage ¶
UnquoteUsage extracts a back-quoted name from the usage string for a flag and returns it and the un-quoted usage. Given "a `name` to show" it returns ("name", "a name to show"). If there are no back quotes, the name is an educated guess of the type of the flag's value, or the empty string if the flag is boolean.
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 FlagSet.Parse behaves if the parse fails.
const ( ContinueOnError ErrorHandling = iota // Return a descriptive error. ExitOnError // Call os.Exit(2). PanicOnError // Call panic with a descriptive error. )
These constants cause FlagSet.Parse to behave as described if the parse fails.
type Flag ¶
type Flag struct { Name 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 Required bool // must set the value IsSet bool // has been altered }
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() // 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.
var CommandLine *FlagSet = 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 so on are wrappers for the methods of CommandLine.
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. Arg returns an empty string if the requested element does not exist.
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) Duration ¶
func (f *FlagSet) Duration(name string, value time.Duration, usage string, required, isset bool) *time.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. The flag accepts a value acceptable to time.ParseDuration.
func (*FlagSet) DurationVar ¶
func (f *FlagSet) DurationVar(p *time.Duration, name string, value time.Duration, usage string, required, isset bool)
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. The flag accepts a value acceptable to time.ParseDuration.
func (*FlagSet) Float32 ¶
Float32 defines a float32 flag with specified name, default value, and usage string. The return value is the address of a float32 variable that stores the value of the flag.
func (*FlagSet) Float32Var ¶
func (f *FlagSet) Float32Var(p *float32, name string, value float32, usage string, required, isset bool)
Float32Var defines a float32 flag with specified name, default value, and usage string. The argument p points to a float32 variable in which to store the value of the flag.
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 ¶
func (f *FlagSet) Float64Var(p *float64, name string, value float64, usage string, required, isset bool)
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 (f *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) Int16 ¶
Int16 defines an int16 flag with specified name, default value, and usage string. The return value is the address of an int16 variable that stores the value of the flag.
func (*FlagSet) Int16Var ¶
Int16Var defines an int16 flag with specified name, default value, and usage string. The argument p points to an int16 variable in which to store the value of the flag.
func (*FlagSet) Int32 ¶
Int32 defines an int32 flag with specified name, default value, and usage string. The return value is the address of an int32 variable that stores the value of the flag.
func (*FlagSet) Int32Var ¶
Int32Var defines an int32 flag with specified name, default value, and usage string. The argument p points to an int32 variable in which to store 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) Int8 ¶
Int8 defines an int8 flag with specified name, default value, and usage string. The return value is the address of an int8 variable that stores the value of the flag.
func (*FlagSet) Int8Var ¶
Int8Var defines an int8 flag with specified name, default value, and usage string. The argument p points to an int8 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 or -h were set but not defined.
func (*FlagSet) PrintDefaults ¶
func (f *FlagSet) PrintDefaults()
PrintDefaults prints to standard error the default values of all defined command-line flags in the set. See the documentation for the global function PrintDefaults for more information.
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 ¶
func (f *FlagSet) StringVar(p *string, name string, value string, usage string, required, isset bool)
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) Uint16 ¶
Uint16 defines a uint16 flag with specified name, default value, and usage string. The return value is the address of a uint16 variable that stores the value of the flag.
func (*FlagSet) Uint16Var ¶
func (f *FlagSet) Uint16Var(p *uint16, name string, value uint16, usage string, required, isset bool)
Uint16Var defines a uint16 flag with specified name, default value, and usage string. The argument p points to a uint16 variable in which to store the value of the flag.
func (*FlagSet) Uint32 ¶
Uint32 defines a uint32 flag with specified name, default value, and usage string. The return value is the address of a uint32 variable that stores the value of the flag.
func (*FlagSet) Uint32Var ¶
func (f *FlagSet) Uint32Var(p *uint32, name string, value uint32, usage string, required, isset bool)
Uint32Var defines a uint32 flag with specified name, default value, and usage string. The argument p points to a uint32 variable in which to store 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 ¶
func (f *FlagSet) Uint64Var(p *uint64, name string, value uint64, usage string, required, isset bool)
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) Uint8 ¶
Uint8 defines a uint8 flag with specified name, default value, and usage string. The return value is the address of a uint8 variable that stores the value of the flag.
func (*FlagSet) Uint8Var ¶
Uint8Var defines a uint8 flag with specified name, default value, and usage string. The argument p points to a uint8 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.
type Value ¶
Value is the interface to the dynamic value stored in a flag. (The default value is represented as a string.)
If a 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.
Set is called once, in command line order, for each flag present. The flag package may call the String method with a zero-valued receiver, such as a nil pointer.