CommandLine is the default set of command-line flags, parsed from os.Args.
var CommandLine = NewFlagSet(os.Args[0], ExitOnError)
ErrHelp is the error returned if the flag -help is invoked but no such flag is defined.
var ErrHelp = errors.New("pflag: help requested")
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. 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.
var Usage = func() { fmt.Fprintf(os.Stderr, "Usage of %s:\n", os.Args[0]) PrintDefaults() }
func Arg(i int) string
Arg returns the i'th command-line argument. Arg(0) is the first remaining argument after flags have been processed.
func Args() []string
Args returns the non-flag command-line arguments.
func Bool(name string, value bool, usage string) *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 BoolP(name, shorthand string, value bool, usage string) *bool
BoolP is like Bool, but accepts a shorthand letter that can be used after a single dash.
func BoolSlice(name string, value []bool, usage string) *[]bool
BoolSlice 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 BoolSliceP(name, shorthand string, value []bool, usage string) *[]bool
BoolSliceP is like BoolSlice, but accepts a shorthand letter that can be used after a single dash.
func BoolSliceVar(p *[]bool, name string, value []bool, usage string)
BoolSliceVar 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 BoolSliceVarP(p *[]bool, name, shorthand string, value []bool, usage string)
BoolSliceVarP is like BoolSliceVar, but accepts a shorthand letter that can be used after a single dash.
func BoolVar(p *bool, name string, value bool, usage string)
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 BoolVarP(p *bool, name, shorthand string, value bool, usage string)
BoolVarP is like BoolVar, but accepts a shorthand letter that can be used after a single dash.
func BytesBase64(name string, value []byte, usage string) *[]byte
BytesBase64 defines an []byte flag with specified name, default value, and usage string. The return value is the address of an []byte variable that stores the value of the flag.
func BytesBase64P(name, shorthand string, value []byte, usage string) *[]byte
BytesBase64P is like BytesBase64, but accepts a shorthand letter that can be used after a single dash.
func BytesBase64Var(p *[]byte, name string, value []byte, usage string)
BytesBase64Var defines an []byte flag with specified name, default value, and usage string. The argument p points to an []byte variable in which to store the value of the flag.
func BytesBase64VarP(p *[]byte, name, shorthand string, value []byte, usage string)
BytesBase64VarP is like BytesBase64Var, but accepts a shorthand letter that can be used after a single dash.
func BytesHex(name string, value []byte, usage string) *[]byte
BytesHex defines an []byte flag with specified name, default value, and usage string. The return value is the address of an []byte variable that stores the value of the flag.
func BytesHexP(name, shorthand string, value []byte, usage string) *[]byte
BytesHexP is like BytesHex, but accepts a shorthand letter that can be used after a single dash.
func BytesHexVar(p *[]byte, name string, value []byte, usage string)
BytesHexVar defines an []byte flag with specified name, default value, and usage string. The argument p points to an []byte variable in which to store the value of the flag.
func BytesHexVarP(p *[]byte, name, shorthand string, value []byte, usage string)
BytesHexVarP is like BytesHexVar, but accepts a shorthand letter that can be used after a single dash.
func Count(name string, usage string) *int
Count defines a count 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. A count flag will add 1 to its value evey time it is found on the command line
func CountP(name, shorthand string, usage string) *int
CountP is like Count only takes a shorthand for the flag name.
func CountVar(p *int, name string, usage string)
CountVar like CountVar only the flag is placed on the CommandLine instead of a given flag set
func CountVarP(p *int, name, shorthand string, usage string)
CountVarP is like CountVar only take a shorthand for the flag name.
func Duration(name string, value time.Duration, usage string) *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.
func DurationP(name, shorthand string, value time.Duration, usage string) *time.Duration
DurationP is like Duration, but accepts a shorthand letter that can be used after a single dash.
func DurationSlice(name string, value []time.Duration, usage string) *[]time.Duration
DurationSlice 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 DurationSliceP(name, shorthand string, value []time.Duration, usage string) *[]time.Duration
DurationSliceP is like DurationSlice, but accepts a shorthand letter that can be used after a single dash.
func DurationSliceVar(p *[]time.Duration, name string, value []time.Duration, usage string)
DurationSliceVar defines a duration[] flag with specified name, default value, and usage string. The argument p points to a duration[] variable in which to store the value of the flag.
func DurationSliceVarP(p *[]time.Duration, name, shorthand string, value []time.Duration, usage string)
DurationSliceVarP is like DurationSliceVar, but accepts a shorthand letter that can be used after a single dash.
func DurationVar(p *time.Duration, name string, value time.Duration, usage string)
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 DurationVarP(p *time.Duration, name, shorthand string, value time.Duration, usage string)
DurationVarP is like DurationVar, but accepts a shorthand letter that can be used after a single dash.
func Float32(name string, value float32, usage string) *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 Float32P(name, shorthand string, value float32, usage string) *float32
Float32P is like Float32, but accepts a shorthand letter that can be used after a single dash.
func Float32Slice(name string, value []float32, usage string) *[]float32
Float32Slice 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 Float32SliceP(name, shorthand string, value []float32, usage string) *[]float32
Float32SliceP is like Float32Slice, but accepts a shorthand letter that can be used after a single dash.
func Float32SliceVar(p *[]float32, name string, value []float32, usage string)
Float32SliceVar 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 Float32SliceVarP(p *[]float32, name, shorthand string, value []float32, usage string)
Float32SliceVarP is like Float32SliceVar, but accepts a shorthand letter that can be used after a single dash.
func Float32Var(p *float32, name string, value float32, usage string)
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 Float32VarP(p *float32, name, shorthand string, value float32, usage string)
Float32VarP is like Float32Var, but accepts a shorthand letter that can be used after a single dash.
func Float64(name string, value float64, usage string) *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 Float64P(name, shorthand string, value float64, usage string) *float64
Float64P is like Float64, but accepts a shorthand letter that can be used after a single dash.
func Float64Slice(name string, value []float64, usage string) *[]float64
Float64Slice 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 Float64SliceP(name, shorthand string, value []float64, usage string) *[]float64
Float64SliceP is like Float64Slice, but accepts a shorthand letter that can be used after a single dash.
func Float64SliceVar(p *[]float64, name string, value []float64, usage string)
Float64SliceVar 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 Float64SliceVarP(p *[]float64, name, shorthand string, value []float64, usage string)
Float64SliceVarP is like Float64SliceVar, but accepts a shorthand letter that can be used after a single dash.
func Float64Var(p *float64, name string, value float64, usage string)
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 Float64VarP(p *float64, name, shorthand string, value float64, usage string)
Float64VarP is like Float64Var, but accepts a shorthand letter that can be used after a single dash.
func IP(name string, value net.IP, usage string) *net.IP
IP defines an net.IP flag with specified name, default value, and usage string. The return value is the address of an net.IP variable that stores the value of the flag.
func IPMask(name string, value net.IPMask, usage string) *net.IPMask
IPMask defines an net.IPMask flag with specified name, default value, and usage string. The return value is the address of an net.IPMask variable that stores the value of the flag.
func IPMaskP(name, shorthand string, value net.IPMask, usage string) *net.IPMask
IPMaskP is like IP, but accepts a shorthand letter that can be used after a single dash.
func IPMaskVar(p *net.IPMask, name string, value net.IPMask, usage string)
IPMaskVar defines an net.IPMask flag with specified name, default value, and usage string. The argument p points to an net.IPMask variable in which to store the value of the flag.
func IPMaskVarP(p *net.IPMask, name, shorthand string, value net.IPMask, usage string)
IPMaskVarP is like IPMaskVar, but accepts a shorthand letter that can be used after a single dash.
func IPNet(name string, value net.IPNet, usage string) *net.IPNet
IPNet defines an net.IPNet flag with specified name, default value, and usage string. The return value is the address of an net.IPNet variable that stores the value of the flag.
func IPNetP(name, shorthand string, value net.IPNet, usage string) *net.IPNet
IPNetP is like IPNet, but accepts a shorthand letter that can be used after a single dash.
func IPNetVar(p *net.IPNet, name string, value net.IPNet, usage string)
IPNetVar defines an net.IPNet flag with specified name, default value, and usage string. The argument p points to an net.IPNet variable in which to store the value of the flag.
func IPNetVarP(p *net.IPNet, name, shorthand string, value net.IPNet, usage string)
IPNetVarP is like IPNetVar, but accepts a shorthand letter that can be used after a single dash.
func IPP(name, shorthand string, value net.IP, usage string) *net.IP
IPP is like IP, but accepts a shorthand letter that can be used after a single dash.
func IPSlice(name string, value []net.IP, usage string) *[]net.IP
IPSlice defines a []net.IP flag with specified name, default value, and usage string. The return value is the address of a []net.IP variable that stores the value of the flag.
func IPSliceP(name, shorthand string, value []net.IP, usage string) *[]net.IP
IPSliceP is like IPSlice, but accepts a shorthand letter that can be used after a single dash.
func IPSliceVar(p *[]net.IP, name string, value []net.IP, usage string)
IPSliceVar defines a []net.IP flag with specified name, default value, and usage string. The argument p points to a []net.IP variable in which to store the value of the flag.
func IPSliceVarP(p *[]net.IP, name, shorthand string, value []net.IP, usage string)
IPSliceVarP is like IPSliceVar, but accepts a shorthand letter that can be used after a single dash.
func IPVar(p *net.IP, name string, value net.IP, usage string)
IPVar defines an net.IP flag with specified name, default value, and usage string. The argument p points to an net.IP variable in which to store the value of the flag.
func IPVarP(p *net.IP, name, shorthand string, value net.IP, usage string)
IPVarP is like IPVar, but accepts a shorthand letter that can be used after a single dash.
func Int(name string, value int, usage string) *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(name string, value int16, usage string) *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 Int16P(name, shorthand string, value int16, usage string) *int16
Int16P is like Int16, but accepts a shorthand letter that can be used after a single dash.
func Int16Var(p *int16, name string, value int16, usage string)
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 Int16VarP(p *int16, name, shorthand string, value int16, usage string)
Int16VarP is like Int16Var, but accepts a shorthand letter that can be used after a single dash.
func Int32(name string, value int32, usage string) *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 Int32P(name, shorthand string, value int32, usage string) *int32
Int32P is like Int32, but accepts a shorthand letter that can be used after a single dash.
func Int32Slice(name string, value []int32, usage string) *[]int32
Int32Slice defines a []int32 flag with specified name, default value, and usage string. The return value is the address of a []int32 variable that stores the value of the flag.
func Int32SliceP(name, shorthand string, value []int32, usage string) *[]int32
Int32SliceP is like Int32Slice, but accepts a shorthand letter that can be used after a single dash.
func Int32SliceVar(p *[]int32, name string, value []int32, usage string)
Int32SliceVar defines a int32[] flag with specified name, default value, and usage string. The argument p points to a int32[] variable in which to store the value of the flag.
func Int32SliceVarP(p *[]int32, name, shorthand string, value []int32, usage string)
Int32SliceVarP is like Int32SliceVar, but accepts a shorthand letter that can be used after a single dash.
func Int32Var(p *int32, name string, value int32, usage string)
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 Int32VarP(p *int32, name, shorthand string, value int32, usage string)
Int32VarP is like Int32Var, but accepts a shorthand letter that can be used after a single dash.
func Int64(name string, value int64, usage string) *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 Int64P(name, shorthand string, value int64, usage string) *int64
Int64P is like Int64, but accepts a shorthand letter that can be used after a single dash.
func Int64Slice(name string, value []int64, usage string) *[]int64
Int64Slice defines a []int64 flag with specified name, default value, and usage string. The return value is the address of a []int64 variable that stores the value of the flag.
func Int64SliceP(name, shorthand string, value []int64, usage string) *[]int64
Int64SliceP is like Int64Slice, but accepts a shorthand letter that can be used after a single dash.
func Int64SliceVar(p *[]int64, name string, value []int64, usage string)
Int64SliceVar defines a int64[] flag with specified name, default value, and usage string. The argument p points to a int64[] variable in which to store the value of the flag.
func Int64SliceVarP(p *[]int64, name, shorthand string, value []int64, usage string)
Int64SliceVarP is like Int64SliceVar, but accepts a shorthand letter that can be used after a single dash.
func Int64Var(p *int64, name string, value int64, usage string)
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 Int64VarP(p *int64, name, shorthand string, value int64, usage string)
Int64VarP is like Int64Var, but accepts a shorthand letter that can be used after a single dash.
func Int8(name string, value int8, usage string) *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 Int8P(name, shorthand string, value int8, usage string) *int8
Int8P is like Int8, but accepts a shorthand letter that can be used after a single dash.
func Int8Var(p *int8, name string, value int8, usage string)
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 Int8VarP(p *int8, name, shorthand string, value int8, usage string)
Int8VarP is like Int8Var, but accepts a shorthand letter that can be used after a single dash.
func IntP(name, shorthand string, value int, usage string) *int
IntP is like Int, but accepts a shorthand letter that can be used after a single dash.
func IntSlice(name string, value []int, usage string) *[]int
IntSlice defines a []int flag with specified name, default value, and usage string. The return value is the address of a []int variable that stores the value of the flag.
func IntSliceP(name, shorthand string, value []int, usage string) *[]int
IntSliceP is like IntSlice, but accepts a shorthand letter that can be used after a single dash.
func IntSliceVar(p *[]int, name string, value []int, usage string)
IntSliceVar defines a int[] flag with specified name, default value, and usage string. The argument p points to a int[] variable in which to store the value of the flag.
func IntSliceVarP(p *[]int, name, shorthand string, value []int, usage string)
IntSliceVarP is like IntSliceVar, but accepts a shorthand letter that can be used after a single dash.
func IntVar(p *int, name string, value int, usage string)
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 IntVarP(p *int, name, shorthand string, value int, usage string)
IntVarP is like IntVar, but accepts a shorthand letter that can be used after a single dash.
func NArg() int
NArg is the number of arguments remaining after flags have been processed.
func NFlag() int
NFlag returns the number of command-line flags that have been set.
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 ParseAll(fn func(flag *Flag, value string) error)
ParseAll parses the command-line flags from os.Args[1:] and called fn for each. The arguments for fn are flag and value. Must be called after all flags are defined and before flags are accessed by the program.
func ParseIPv4Mask(s string) net.IPMask
ParseIPv4Mask written in IP form (e.g. 255.255.255.0). This function should really belong to the net package.
func Parsed() bool
Parsed returns true if the command-line flags have been parsed.
func PrintDefaults()
PrintDefaults prints to standard error the default values of all defined command-line flags.
func Set(name, value string) error
Set sets the value of the named command-line flag.
func SetInterspersed(interspersed bool)
SetInterspersed sets whether to support interspersed option/non-option arguments.
func String(name string, value string, usage string) *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 StringArray(name string, value []string, usage string) *[]string
StringArray 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. The value of each argument will not try to be separated by comma. Use a StringSlice for that.
func StringArrayP(name, shorthand string, value []string, usage string) *[]string
StringArrayP is like StringArray, but accepts a shorthand letter that can be used after a single dash.
func StringArrayVar(p *[]string, name string, value []string, usage string)
StringArrayVar 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. The value of each argument will not try to be separated by comma. Use a StringSlice for that.
func StringArrayVarP(p *[]string, name, shorthand string, value []string, usage string)
StringArrayVarP is like StringArrayVar, but accepts a shorthand letter that can be used after a single dash.
func StringP(name, shorthand string, value string, usage string) *string
StringP is like String, but accepts a shorthand letter that can be used after a single dash.
func StringSlice(name string, value []string, usage string) *[]string
StringSlice 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. Compared to StringArray flags, StringSlice flags take comma-separated value as arguments and split them accordingly. For example:
--ss="v1,v2" --ss="v3"
will result in
[]string{"v1", "v2", "v3"}
func StringSliceP(name, shorthand string, value []string, usage string) *[]string
StringSliceP is like StringSlice, but accepts a shorthand letter that can be used after a single dash.
func StringSliceVar(p *[]string, name string, value []string, usage string)
StringSliceVar 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. Compared to StringArray flags, StringSlice flags take comma-separated value as arguments and split them accordingly. For example:
--ss="v1,v2" --ss="v3"
will result in
[]string{"v1", "v2", "v3"}
func StringSliceVarP(p *[]string, name, shorthand string, value []string, usage string)
StringSliceVarP is like StringSliceVar, but accepts a shorthand letter that can be used after a single dash.
func StringToInt(name string, value map[string]int, usage string) *map[string]int
StringToInt defines a string flag with specified name, default value, and usage string. The return value is the address of a map[string]int variable that stores the value of the flag. The value of each argument will not try to be separated by comma
func StringToInt64(name string, value map[string]int64, usage string) *map[string]int64
StringToInt64 defines a string flag with specified name, default value, and usage string. The return value is the address of a map[string]int64 variable that stores the value of the flag. The value of each argument will not try to be separated by comma
func StringToInt64P(name, shorthand string, value map[string]int64, usage string) *map[string]int64
StringToInt64P is like StringToInt64, but accepts a shorthand letter that can be used after a single dash.
func StringToInt64Var(p *map[string]int64, name string, value map[string]int64, usage string)
StringToInt64Var defines a string flag with specified name, default value, and usage string. The argument p point64s to a map[string]int64 variable in which to store the value of the flag. The value of each argument will not try to be separated by comma
func StringToInt64VarP(p *map[string]int64, name, shorthand string, value map[string]int64, usage string)
StringToInt64VarP is like StringToInt64Var, but accepts a shorthand letter that can be used after a single dash.
func StringToIntP(name, shorthand string, value map[string]int, usage string) *map[string]int
StringToIntP is like StringToInt, but accepts a shorthand letter that can be used after a single dash.
func StringToIntVar(p *map[string]int, name string, value map[string]int, usage string)
StringToIntVar defines a string flag with specified name, default value, and usage string. The argument p points to a map[string]int variable in which to store the value of the flag. The value of each argument will not try to be separated by comma
func StringToIntVarP(p *map[string]int, name, shorthand string, value map[string]int, usage string)
StringToIntVarP is like StringToIntVar, but accepts a shorthand letter that can be used after a single dash.
func StringToString(name string, value map[string]string, usage string) *map[string]string
StringToString defines a string flag with specified name, default value, and usage string. The return value is the address of a map[string]string variable that stores the value of the flag. The value of each argument will not try to be separated by comma
func StringToStringP(name, shorthand string, value map[string]string, usage string) *map[string]string
StringToStringP is like StringToString, but accepts a shorthand letter that can be used after a single dash.
func StringToStringVar(p *map[string]string, name string, value map[string]string, usage string)
StringToStringVar defines a string flag with specified name, default value, and usage string. The argument p points to a map[string]string variable in which to store the value of the flag. The value of each argument will not try to be separated by comma
func StringToStringVarP(p *map[string]string, name, shorthand string, value map[string]string, usage string)
StringToStringVarP is like StringToStringVar, but accepts a shorthand letter that can be used after a single dash.
func StringVar(p *string, name string, value string, usage string)
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 StringVarP(p *string, name, shorthand string, value string, usage string)
StringVarP is like StringVar, but accepts a shorthand letter that can be used after a single dash.
func Uint(name string, value uint, usage string) *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(name string, value uint16, usage string) *uint16
Uint16 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 Uint16P(name, shorthand string, value uint16, usage string) *uint16
Uint16P is like Uint16, but accepts a shorthand letter that can be used after a single dash.
func Uint16Var(p *uint16, name string, value uint16, usage string)
Uint16Var 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 Uint16VarP(p *uint16, name, shorthand string, value uint16, usage string)
Uint16VarP is like Uint16Var, but accepts a shorthand letter that can be used after a single dash.
func Uint32(name string, value uint32, usage string) *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 Uint32P(name, shorthand string, value uint32, usage string) *uint32
Uint32P is like Uint32, but accepts a shorthand letter that can be used after a single dash.
func Uint32Var(p *uint32, name string, value uint32, usage string)
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 Uint32VarP(p *uint32, name, shorthand string, value uint32, usage string)
Uint32VarP is like Uint32Var, but accepts a shorthand letter that can be used after a single dash.
func Uint64(name string, value uint64, usage string) *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 Uint64P(name, shorthand string, value uint64, usage string) *uint64
Uint64P is like Uint64, but accepts a shorthand letter that can be used after a single dash.
func Uint64Var(p *uint64, name string, value uint64, usage string)
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 Uint64VarP(p *uint64, name, shorthand string, value uint64, usage string)
Uint64VarP is like Uint64Var, but accepts a shorthand letter that can be used after a single dash.
func Uint8(name string, value uint8, usage string) *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 Uint8P(name, shorthand string, value uint8, usage string) *uint8
Uint8P is like Uint8, but accepts a shorthand letter that can be used after a single dash.
func Uint8Var(p *uint8, name string, value uint8, usage string)
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 Uint8VarP(p *uint8, name, shorthand string, value uint8, usage string)
Uint8VarP is like Uint8Var, but accepts a shorthand letter that can be used after a single dash.
func UintP(name, shorthand string, value uint, usage string) *uint
UintP is like Uint, but accepts a shorthand letter that can be used after a single dash.
func UintSlice(name string, value []uint, usage string) *[]uint
UintSlice 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 UintSliceP(name, shorthand string, value []uint, usage string) *[]uint
UintSliceP is like UintSlice, but accepts a shorthand letter that can be used after a single dash.
func UintSliceVar(p *[]uint, name string, value []uint, usage string)
UintSliceVar 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 UintSliceVarP(p *[]uint, name, shorthand string, value []uint, usage string)
UintSliceVarP is like the UintSliceVar, but accepts a shorthand letter that can be used after a single dash.
func UintVar(p *uint, name string, value uint, usage string)
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 UintVarP(p *uint, name, shorthand string, value uint, usage string)
UintVarP is like UintVar, but accepts a shorthand letter that can be used after a single dash.
func UnquoteUsage(flag *Flag) (name string, usage string)
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(value Value, name string, usage string)
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.
func VarP(value Value, name, shorthand, usage string)
VarP is like Var, but accepts a shorthand letter that can be used after a single dash.
func Visit(fn func(*Flag))
Visit visits the command-line flags in lexicographical order or in primordial order if f.SortFlags is false, calling fn for each. It visits only those flags that have been set.
func VisitAll(fn func(*Flag))
VisitAll visits the command-line flags in lexicographical order or in primordial order if f.SortFlags is false, calling fn for each. It visits all flags, even those not set.
ErrorHandling defines how to handle flag parsing errors.
type ErrorHandling int
const ( // ContinueOnError will return an err from Parse() if an error is found ContinueOnError ErrorHandling = iota // ExitOnError will call os.Exit(2) if an error is found when parsing ExitOnError // PanicOnError will panic() if an error is found when parsing flags PanicOnError )
A Flag represents the state of a flag.
type Flag struct { Name string // name as it appears on command line Shorthand string // one-letter abbreviated flag Usage string // help message Value Value // value as set DefValue string // default value (as text); for usage message Changed bool // If the user set the value (or if left to default) NoOptDefVal string // default value (as text); if the flag is on the command line without any options Deprecated string // If this flag is deprecated, this string is the new or now thing to use Hidden bool // used by cobra.Command to allow flags to be hidden from help/usage text ShorthandDeprecated string // If the shorthand of this flag is deprecated, this string is the new or now thing to use Annotations map[string][]string // used by cobra.Command bash autocomple code }
func Lookup(name string) *Flag
Lookup returns the Flag structure of the named command-line flag, returning nil if none exists.
func PFlagFromGoFlag(goflag *goflag.Flag) *Flag
PFlagFromGoFlag will return a *pflag.Flag given a *flag.Flag If the *flag.Flag.Name was a single character (ex: `v`) it will be accessiblei with both `-v` and `--v` in flags. If the golang flag was more than a single character (ex: `verbose`) it will only be accessible via `--verbose`
func ShorthandLookup(name string) *Flag
ShorthandLookup returns the Flag structure of the short handed flag, returning nil if none exists.
▹ Example
A FlagSet represents a set of defined flags.
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() // SortFlags is used to indicate, if user wants to have sorted flags in // help/usage messages. SortFlags bool // ParseErrorsWhitelist is used to configure a whitelist of errors ParseErrorsWhitelist ParseErrorsWhitelist // contains filtered or unexported fields }
func NewFlagSet(name string, errorHandling ErrorHandling) *FlagSet
NewFlagSet returns a new, empty flag set with the specified name, error handling property and SortFlags set to true.
func (f *FlagSet) AddFlag(flag *Flag)
AddFlag will add the flag to the FlagSet
func (f *FlagSet) AddFlagSet(newSet *FlagSet)
AddFlagSet adds one FlagSet to another. If a flag is already present in f the flag from newSet will be ignored.
func (f *FlagSet) AddGoFlag(goflag *goflag.Flag)
AddGoFlag will add the given *flag.Flag to the pflag.FlagSet
func (f *FlagSet) AddGoFlagSet(newSet *goflag.FlagSet)
AddGoFlagSet will add the given *flag.FlagSet to the pflag.FlagSet
func (f *FlagSet) Arg(i int) string
Arg returns the i'th argument. Arg(0) is the first remaining argument after flags have been processed.
func (f *FlagSet) Args() []string
Args returns the non-flag arguments.
func (f *FlagSet) ArgsLenAtDash() int
ArgsLenAtDash will return the length of f.Args at the moment when a -- was found during arg parsing. This allows your program to know which args were before the -- and which came after.
func (f *FlagSet) Bool(name string, value bool, usage string) *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 (f *FlagSet) BoolP(name, shorthand string, value bool, usage string) *bool
BoolP is like Bool, but accepts a shorthand letter that can be used after a single dash.
func (f *FlagSet) BoolSlice(name string, value []bool, usage string) *[]bool
BoolSlice 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 (f *FlagSet) BoolSliceP(name, shorthand string, value []bool, usage string) *[]bool
BoolSliceP is like BoolSlice, but accepts a shorthand letter that can be used after a single dash.
func (f *FlagSet) BoolSliceVar(p *[]bool, name string, value []bool, usage string)
BoolSliceVar defines a boolSlice 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 (f *FlagSet) BoolSliceVarP(p *[]bool, name, shorthand string, value []bool, usage string)
BoolSliceVarP is like BoolSliceVar, but accepts a shorthand letter that can be used after a single dash.
func (f *FlagSet) BoolVar(p *bool, name string, value bool, usage string)
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 (f *FlagSet) BoolVarP(p *bool, name, shorthand string, value bool, usage string)
BoolVarP is like BoolVar, but accepts a shorthand letter that can be used after a single dash.
func (f *FlagSet) BytesBase64(name string, value []byte, usage string) *[]byte
BytesBase64 defines an []byte flag with specified name, default value, and usage string. The return value is the address of an []byte variable that stores the value of the flag.
func (f *FlagSet) BytesBase64P(name, shorthand string, value []byte, usage string) *[]byte
BytesBase64P is like BytesBase64, but accepts a shorthand letter that can be used after a single dash.
func (f *FlagSet) BytesBase64Var(p *[]byte, name string, value []byte, usage string)
BytesBase64Var defines an []byte flag with specified name, default value, and usage string. The argument p points to an []byte variable in which to store the value of the flag.
func (f *FlagSet) BytesBase64VarP(p *[]byte, name, shorthand string, value []byte, usage string)
BytesBase64VarP is like BytesBase64Var, but accepts a shorthand letter that can be used after a single dash.
func (f *FlagSet) BytesHex(name string, value []byte, usage string) *[]byte
BytesHex defines an []byte flag with specified name, default value, and usage string. The return value is the address of an []byte variable that stores the value of the flag.
func (f *FlagSet) BytesHexP(name, shorthand string, value []byte, usage string) *[]byte
BytesHexP is like BytesHex, but accepts a shorthand letter that can be used after a single dash.
func (f *FlagSet) BytesHexVar(p *[]byte, name string, value []byte, usage string)
BytesHexVar defines an []byte flag with specified name, default value, and usage string. The argument p points to an []byte variable in which to store the value of the flag.
func (f *FlagSet) BytesHexVarP(p *[]byte, name, shorthand string, value []byte, usage string)
BytesHexVarP is like BytesHexVar, but accepts a shorthand letter that can be used after a single dash.
func (f *FlagSet) Changed(name string) bool
Changed returns true if the flag was explicitly set during Parse() and false otherwise
func (f *FlagSet) Count(name string, usage string) *int
Count defines a count 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. A count flag will add 1 to its value every time it is found on the command line
func (f *FlagSet) CountP(name, shorthand string, usage string) *int
CountP is like Count only takes a shorthand for the flag name.
func (f *FlagSet) CountVar(p *int, name string, usage string)
CountVar defines a count 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. A count flag will add 1 to its value every time it is found on the command line
func (f *FlagSet) CountVarP(p *int, name, shorthand string, usage string)
CountVarP is like CountVar only take a shorthand for the flag name.
func (f *FlagSet) Duration(name string, value time.Duration, usage string) *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.
func (f *FlagSet) DurationP(name, shorthand string, value time.Duration, usage string) *time.Duration
DurationP is like Duration, but accepts a shorthand letter that can be used after a single dash.
func (f *FlagSet) DurationSlice(name string, value []time.Duration, usage string) *[]time.Duration
DurationSlice 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 (f *FlagSet) DurationSliceP(name, shorthand string, value []time.Duration, usage string) *[]time.Duration
DurationSliceP is like DurationSlice, but accepts a shorthand letter that can be used after a single dash.
func (f *FlagSet) DurationSliceVar(p *[]time.Duration, name string, value []time.Duration, usage string)
DurationSliceVar defines a durationSlice 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 (f *FlagSet) DurationSliceVarP(p *[]time.Duration, name, shorthand string, value []time.Duration, usage string)
DurationSliceVarP is like DurationSliceVar, but accepts a shorthand letter that can be used after a single dash.
func (f *FlagSet) DurationVar(p *time.Duration, name string, value time.Duration, usage string)
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 (f *FlagSet) DurationVarP(p *time.Duration, name, shorthand string, value time.Duration, usage string)
DurationVarP is like DurationVar, but accepts a shorthand letter that can be used after a single dash.
func (f *FlagSet) FlagUsages() string
FlagUsages returns a string containing the usage information for all flags in the FlagSet
func (f *FlagSet) FlagUsagesWrapped(cols int) string
FlagUsagesWrapped returns a string containing the usage information for all flags in the FlagSet. Wrapped to `cols` columns (0 for no wrapping)
func (f *FlagSet) Float32(name string, value float32, usage string) *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 (f *FlagSet) Float32P(name, shorthand string, value float32, usage string) *float32
Float32P is like Float32, but accepts a shorthand letter that can be used after a single dash.
func (f *FlagSet) Float32Slice(name string, value []float32, usage string) *[]float32
Float32Slice 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 (f *FlagSet) Float32SliceP(name, shorthand string, value []float32, usage string) *[]float32
Float32SliceP is like Float32Slice, but accepts a shorthand letter that can be used after a single dash.
func (f *FlagSet) Float32SliceVar(p *[]float32, name string, value []float32, usage string)
Float32SliceVar defines a float32Slice 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 (f *FlagSet) Float32SliceVarP(p *[]float32, name, shorthand string, value []float32, usage string)
Float32SliceVarP is like Float32SliceVar, but accepts a shorthand letter that can be used after a single dash.
func (f *FlagSet) Float32Var(p *float32, name string, value float32, usage string)
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 (f *FlagSet) Float32VarP(p *float32, name, shorthand string, value float32, usage string)
Float32VarP is like Float32Var, but accepts a shorthand letter that can be used after a single dash.
func (f *FlagSet) Float64(name string, value float64, usage string) *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 (f *FlagSet) Float64P(name, shorthand string, value float64, usage string) *float64
Float64P is like Float64, but accepts a shorthand letter that can be used after a single dash.
func (f *FlagSet) Float64Slice(name string, value []float64, usage string) *[]float64
Float64Slice 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 (f *FlagSet) Float64SliceP(name, shorthand string, value []float64, usage string) *[]float64
Float64SliceP is like Float64Slice, but accepts a shorthand letter that can be used after a single dash.
func (f *FlagSet) Float64SliceVar(p *[]float64, name string, value []float64, usage string)
Float64SliceVar defines a float64Slice 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 (f *FlagSet) Float64SliceVarP(p *[]float64, name, shorthand string, value []float64, usage string)
Float64SliceVarP is like Float64SliceVar, but accepts a shorthand letter that can be used after a single dash.
func (f *FlagSet) Float64Var(p *float64, name string, value float64, usage string)
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 (f *FlagSet) Float64VarP(p *float64, name, shorthand string, value float64, usage string)
Float64VarP is like Float64Var, but accepts a shorthand letter that can be used after a single dash.
func (f *FlagSet) GetBool(name string) (bool, error)
GetBool return the bool value of a flag with the given name
func (f *FlagSet) GetBoolSlice(name string) ([]bool, error)
GetBoolSlice returns the []bool value of a flag with the given name.
func (f *FlagSet) GetBytesBase64(name string) ([]byte, error)
GetBytesBase64 return the []byte value of a flag with the given name
func (f *FlagSet) GetBytesHex(name string) ([]byte, error)
GetBytesHex return the []byte value of a flag with the given name
func (f *FlagSet) GetCount(name string) (int, error)
GetCount return the int value of a flag with the given name
func (f *FlagSet) GetDuration(name string) (time.Duration, error)
GetDuration return the duration value of a flag with the given name
func (f *FlagSet) GetDurationSlice(name string) ([]time.Duration, error)
GetDurationSlice returns the []time.Duration value of a flag with the given name
func (f *FlagSet) GetFloat32(name string) (float32, error)
GetFloat32 return the float32 value of a flag with the given name
func (f *FlagSet) GetFloat32Slice(name string) ([]float32, error)
GetFloat32Slice return the []float32 value of a flag with the given name
func (f *FlagSet) GetFloat64(name string) (float64, error)
GetFloat64 return the float64 value of a flag with the given name
func (f *FlagSet) GetFloat64Slice(name string) ([]float64, error)
GetFloat64Slice return the []float64 value of a flag with the given name
func (f *FlagSet) GetIP(name string) (net.IP, error)
GetIP return the net.IP value of a flag with the given name
func (f *FlagSet) GetIPNet(name string) (net.IPNet, error)
GetIPNet return the net.IPNet value of a flag with the given name
func (f *FlagSet) GetIPSlice(name string) ([]net.IP, error)
GetIPSlice returns the []net.IP value of a flag with the given name
func (f *FlagSet) GetIPv4Mask(name string) (net.IPMask, error)
GetIPv4Mask return the net.IPv4Mask value of a flag with the given name
func (f *FlagSet) GetInt(name string) (int, error)
GetInt return the int value of a flag with the given name
func (f *FlagSet) GetInt16(name string) (int16, error)
GetInt16 returns the int16 value of a flag with the given name
func (f *FlagSet) GetInt32(name string) (int32, error)
GetInt32 return the int32 value of a flag with the given name
func (f *FlagSet) GetInt32Slice(name string) ([]int32, error)
GetInt32Slice return the []int32 value of a flag with the given name
func (f *FlagSet) GetInt64(name string) (int64, error)
GetInt64 return the int64 value of a flag with the given name
func (f *FlagSet) GetInt64Slice(name string) ([]int64, error)
GetInt64Slice return the []int64 value of a flag with the given name
func (f *FlagSet) GetInt8(name string) (int8, error)
GetInt8 return the int8 value of a flag with the given name
func (f *FlagSet) GetIntSlice(name string) ([]int, error)
GetIntSlice return the []int value of a flag with the given name
func (f *FlagSet) GetNormalizeFunc() func(f *FlagSet, name string) NormalizedName
GetNormalizeFunc returns the previously set NormalizeFunc of a function which does no translation, if not set previously.
func (f *FlagSet) GetString(name string) (string, error)
GetString return the string value of a flag with the given name
func (f *FlagSet) GetStringArray(name string) ([]string, error)
GetStringArray return the []string value of a flag with the given name
func (f *FlagSet) GetStringSlice(name string) ([]string, error)
GetStringSlice return the []string value of a flag with the given name
func (f *FlagSet) GetStringToInt(name string) (map[string]int, error)
GetStringToInt return the map[string]int value of a flag with the given name
func (f *FlagSet) GetStringToInt64(name string) (map[string]int64, error)
GetStringToInt64 return the map[string]int64 value of a flag with the given name
func (f *FlagSet) GetStringToString(name string) (map[string]string, error)
GetStringToString return the map[string]string value of a flag with the given name
func (f *FlagSet) GetUint(name string) (uint, error)
GetUint return the uint value of a flag with the given name
func (f *FlagSet) GetUint16(name string) (uint16, error)
GetUint16 return the uint16 value of a flag with the given name
func (f *FlagSet) GetUint32(name string) (uint32, error)
GetUint32 return the uint32 value of a flag with the given name
func (f *FlagSet) GetUint64(name string) (uint64, error)
GetUint64 return the uint64 value of a flag with the given name
func (f *FlagSet) GetUint8(name string) (uint8, error)
GetUint8 return the uint8 value of a flag with the given name
func (f *FlagSet) GetUintSlice(name string) ([]uint, error)
GetUintSlice returns the []uint value of a flag with the given name.
func (f *FlagSet) HasAvailableFlags() bool
HasAvailableFlags returns a bool to indicate if the FlagSet has any flags that are not hidden.
func (f *FlagSet) HasFlags() bool
HasFlags returns a bool to indicate if the FlagSet has any flags defined.
func (f *FlagSet) IP(name string, value net.IP, usage string) *net.IP
IP defines an net.IP flag with specified name, default value, and usage string. The return value is the address of an net.IP variable that stores the value of the flag.
func (f *FlagSet) IPMask(name string, value net.IPMask, usage string) *net.IPMask
IPMask defines an net.IPMask flag with specified name, default value, and usage string. The return value is the address of an net.IPMask variable that stores the value of the flag.
func (f *FlagSet) IPMaskP(name, shorthand string, value net.IPMask, usage string) *net.IPMask
IPMaskP is like IPMask, but accepts a shorthand letter that can be used after a single dash.
func (f *FlagSet) IPMaskVar(p *net.IPMask, name string, value net.IPMask, usage string)
IPMaskVar defines an net.IPMask flag with specified name, default value, and usage string. The argument p points to an net.IPMask variable in which to store the value of the flag.
func (f *FlagSet) IPMaskVarP(p *net.IPMask, name, shorthand string, value net.IPMask, usage string)
IPMaskVarP is like IPMaskVar, but accepts a shorthand letter that can be used after a single dash.
func (f *FlagSet) IPNet(name string, value net.IPNet, usage string) *net.IPNet
IPNet defines an net.IPNet flag with specified name, default value, and usage string. The return value is the address of an net.IPNet variable that stores the value of the flag.
func (f *FlagSet) IPNetP(name, shorthand string, value net.IPNet, usage string) *net.IPNet
IPNetP is like IPNet, but accepts a shorthand letter that can be used after a single dash.
func (f *FlagSet) IPNetVar(p *net.IPNet, name string, value net.IPNet, usage string)
IPNetVar defines an net.IPNet flag with specified name, default value, and usage string. The argument p points to an net.IPNet variable in which to store the value of the flag.
func (f *FlagSet) IPNetVarP(p *net.IPNet, name, shorthand string, value net.IPNet, usage string)
IPNetVarP is like IPNetVar, but accepts a shorthand letter that can be used after a single dash.
func (f *FlagSet) IPP(name, shorthand string, value net.IP, usage string) *net.IP
IPP is like IP, but accepts a shorthand letter that can be used after a single dash.
func (f *FlagSet) IPSlice(name string, value []net.IP, usage string) *[]net.IP
IPSlice defines a []net.IP flag with specified name, default value, and usage string. The return value is the address of a []net.IP variable that stores the value of that flag.
func (f *FlagSet) IPSliceP(name, shorthand string, value []net.IP, usage string) *[]net.IP
IPSliceP is like IPSlice, but accepts a shorthand letter that can be used after a single dash.
func (f *FlagSet) IPSliceVar(p *[]net.IP, name string, value []net.IP, usage string)
IPSliceVar defines a ipSlice flag with specified name, default value, and usage string. The argument p points to a []net.IP variable in which to store the value of the flag.
func (f *FlagSet) IPSliceVarP(p *[]net.IP, name, shorthand string, value []net.IP, usage string)
IPSliceVarP is like IPSliceVar, but accepts a shorthand letter that can be used after a single dash.
func (f *FlagSet) IPVar(p *net.IP, name string, value net.IP, usage string)
IPVar defines an net.IP flag with specified name, default value, and usage string. The argument p points to an net.IP variable in which to store the value of the flag.
func (f *FlagSet) IPVarP(p *net.IP, name, shorthand string, value net.IP, usage string)
IPVarP is like IPVar, but accepts a shorthand letter that can be used after a single dash.
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 (f *FlagSet) Int(name string, value int, usage string) *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 (f *FlagSet) Int16(name string, value int16, usage string) *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 (f *FlagSet) Int16P(name, shorthand string, value int16, usage string) *int16
Int16P is like Int16, but accepts a shorthand letter that can be used after a single dash.
func (f *FlagSet) Int16Var(p *int16, name string, value int16, usage string)
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 (f *FlagSet) Int16VarP(p *int16, name, shorthand string, value int16, usage string)
Int16VarP is like Int16Var, but accepts a shorthand letter that can be used after a single dash.
func (f *FlagSet) Int32(name string, value int32, usage string) *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 (f *FlagSet) Int32P(name, shorthand string, value int32, usage string) *int32
Int32P is like Int32, but accepts a shorthand letter that can be used after a single dash.
func (f *FlagSet) Int32Slice(name string, value []int32, usage string) *[]int32
Int32Slice defines a []int32 flag with specified name, default value, and usage string. The return value is the address of a []int32 variable that stores the value of the flag.
func (f *FlagSet) Int32SliceP(name, shorthand string, value []int32, usage string) *[]int32
Int32SliceP is like Int32Slice, but accepts a shorthand letter that can be used after a single dash.
func (f *FlagSet) Int32SliceVar(p *[]int32, name string, value []int32, usage string)
Int32SliceVar defines a int32Slice flag with specified name, default value, and usage string. The argument p points to a []int32 variable in which to store the value of the flag.
func (f *FlagSet) Int32SliceVarP(p *[]int32, name, shorthand string, value []int32, usage string)
Int32SliceVarP is like Int32SliceVar, but accepts a shorthand letter that can be used after a single dash.
func (f *FlagSet) Int32Var(p *int32, name string, value int32, usage string)
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 (f *FlagSet) Int32VarP(p *int32, name, shorthand string, value int32, usage string)
Int32VarP is like Int32Var, but accepts a shorthand letter that can be used after a single dash.
func (f *FlagSet) Int64(name string, value int64, usage string) *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 (f *FlagSet) Int64P(name, shorthand string, value int64, usage string) *int64
Int64P is like Int64, but accepts a shorthand letter that can be used after a single dash.
func (f *FlagSet) Int64Slice(name string, value []int64, usage string) *[]int64
Int64Slice defines a []int64 flag with specified name, default value, and usage string. The return value is the address of a []int64 variable that stores the value of the flag.
func (f *FlagSet) Int64SliceP(name, shorthand string, value []int64, usage string) *[]int64
Int64SliceP is like Int64Slice, but accepts a shorthand letter that can be used after a single dash.
func (f *FlagSet) Int64SliceVar(p *[]int64, name string, value []int64, usage string)
Int64SliceVar defines a int64Slice flag with specified name, default value, and usage string. The argument p points to a []int64 variable in which to store the value of the flag.
func (f *FlagSet) Int64SliceVarP(p *[]int64, name, shorthand string, value []int64, usage string)
Int64SliceVarP is like Int64SliceVar, but accepts a shorthand letter that can be used after a single dash.
func (f *FlagSet) Int64Var(p *int64, name string, value int64, usage string)
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 (f *FlagSet) Int64VarP(p *int64, name, shorthand string, value int64, usage string)
Int64VarP is like Int64Var, but accepts a shorthand letter that can be used after a single dash.
func (f *FlagSet) Int8(name string, value int8, usage string) *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 (f *FlagSet) Int8P(name, shorthand string, value int8, usage string) *int8
Int8P is like Int8, but accepts a shorthand letter that can be used after a single dash.
func (f *FlagSet) Int8Var(p *int8, name string, value int8, usage string)
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 (f *FlagSet) Int8VarP(p *int8, name, shorthand string, value int8, usage string)
Int8VarP is like Int8Var, but accepts a shorthand letter that can be used after a single dash.
func (f *FlagSet) IntP(name, shorthand string, value int, usage string) *int
IntP is like Int, but accepts a shorthand letter that can be used after a single dash.
func (f *FlagSet) IntSlice(name string, value []int, usage string) *[]int
IntSlice defines a []int flag with specified name, default value, and usage string. The return value is the address of a []int variable that stores the value of the flag.
func (f *FlagSet) IntSliceP(name, shorthand string, value []int, usage string) *[]int
IntSliceP is like IntSlice, but accepts a shorthand letter that can be used after a single dash.
func (f *FlagSet) IntSliceVar(p *[]int, name string, value []int, usage string)
IntSliceVar defines a intSlice flag with specified name, default value, and usage string. The argument p points to a []int variable in which to store the value of the flag.
func (f *FlagSet) IntSliceVarP(p *[]int, name, shorthand string, value []int, usage string)
IntSliceVarP is like IntSliceVar, but accepts a shorthand letter that can be used after a single dash.
func (f *FlagSet) IntVar(p *int, name string, value int, usage string)
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 (f *FlagSet) IntVarP(p *int, name, shorthand string, value int, usage string)
IntVarP is like IntVar, but accepts a shorthand letter that can be used after a single dash.
func (f *FlagSet) Lookup(name string) *Flag
Lookup returns the Flag structure of the named flag, returning nil if none exists.
func (f *FlagSet) MarkDeprecated(name string, usageMessage string) error
MarkDeprecated indicated that a flag is deprecated in your program. It will continue to function but will not show up in help or usage messages. Using this flag will also print the given usageMessage.
func (f *FlagSet) MarkHidden(name string) error
MarkHidden sets a flag to 'hidden' in your program. It will continue to function but will not show up in help or usage messages.
func (f *FlagSet) MarkShorthandDeprecated(name string, usageMessage string) error
MarkShorthandDeprecated will mark the shorthand of a flag deprecated in your program. It will continue to function but will not show up in help or usage messages. Using this flag will also print the given usageMessage.
func (f *FlagSet) NArg() int
NArg is the number of arguments remaining after flags have been processed.
func (f *FlagSet) NFlag() int
NFlag returns the number of flags that have been set.
func (f *FlagSet) Parse(arguments []string) 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. The return value will be ErrHelp if -help was set but not defined.
func (f *FlagSet) ParseAll(arguments []string, fn func(flag *Flag, value string) error) error
ParseAll parses flag definitions from the argument list, which should not include the command name. The arguments for fn are flag and value. 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 (f *FlagSet) Parsed() bool
Parsed reports whether f.Parse has been called.
func (f *FlagSet) PrintDefaults()
PrintDefaults prints, to standard error unless configured otherwise, the default values of all defined flags in the set.
func (f *FlagSet) Set(name, value string) error
Set sets the value of the named flag.
func (f *FlagSet) SetAnnotation(name, key string, values []string) error
SetAnnotation allows one to set arbitrary annotations on a flag in the FlagSet. This is sometimes used by spf13/cobra programs which want to generate additional bash completion information.
func (f *FlagSet) SetInterspersed(interspersed bool)
SetInterspersed sets whether to support interspersed option/non-option arguments.
func (f *FlagSet) SetNormalizeFunc(n func(f *FlagSet, name string) NormalizedName)
SetNormalizeFunc allows you to add a function which can translate flag names. Flags added to the FlagSet will be translated and then when anything tries to look up the flag that will also be translated. So it would be possible to create a flag named "getURL" and have it translated to "geturl". A user could then pass "--getUrl" which may also be translated to "geturl" and everything will work.
func (f *FlagSet) SetOutput(output io.Writer)
SetOutput sets the destination for usage and error messages. If output is nil, os.Stderr is used.
func (f *FlagSet) ShorthandLookup(name string) *Flag
ShorthandLookup returns the Flag structure of the short handed flag, returning nil if none exists. It panics, if len(name) > 1.
▹ Example
func (f *FlagSet) String(name string, value string, usage string) *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 (f *FlagSet) StringArray(name string, value []string, usage string) *[]string
StringArray 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. The value of each argument will not try to be separated by comma. Use a StringSlice for that.
func (f *FlagSet) StringArrayP(name, shorthand string, value []string, usage string) *[]string
StringArrayP is like StringArray, but accepts a shorthand letter that can be used after a single dash.
func (f *FlagSet) StringArrayVar(p *[]string, name string, value []string, usage string)
StringArrayVar 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 values of the multiple flags. The value of each argument will not try to be separated by comma. Use a StringSlice for that.
func (f *FlagSet) StringArrayVarP(p *[]string, name, shorthand string, value []string, usage string)
StringArrayVarP is like StringArrayVar, but accepts a shorthand letter that can be used after a single dash.
func (f *FlagSet) StringP(name, shorthand string, value string, usage string) *string
StringP is like String, but accepts a shorthand letter that can be used after a single dash.
func (f *FlagSet) StringSlice(name string, value []string, usage string) *[]string
StringSlice 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. Compared to StringArray flags, StringSlice flags take comma-separated value as arguments and split them accordingly. For example:
--ss="v1,v2" --ss="v3"
will result in
[]string{"v1", "v2", "v3"}
func (f *FlagSet) StringSliceP(name, shorthand string, value []string, usage string) *[]string
StringSliceP is like StringSlice, but accepts a shorthand letter that can be used after a single dash.
func (f *FlagSet) StringSliceVar(p *[]string, name string, value []string, usage string)
StringSliceVar 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. Compared to StringArray flags, StringSlice flags take comma-separated value as arguments and split them accordingly. For example:
--ss="v1,v2" --ss="v3"
will result in
[]string{"v1", "v2", "v3"}
func (f *FlagSet) StringSliceVarP(p *[]string, name, shorthand string, value []string, usage string)
StringSliceVarP is like StringSliceVar, but accepts a shorthand letter that can be used after a single dash.
func (f *FlagSet) StringToInt(name string, value map[string]int, usage string) *map[string]int
StringToInt defines a string flag with specified name, default value, and usage string. The return value is the address of a map[string]int variable that stores the value of the flag. The value of each argument will not try to be separated by comma
func (f *FlagSet) StringToInt64(name string, value map[string]int64, usage string) *map[string]int64
StringToInt64 defines a string flag with specified name, default value, and usage string. The return value is the address of a map[string]int64 variable that stores the value of the flag. The value of each argument will not try to be separated by comma
func (f *FlagSet) StringToInt64P(name, shorthand string, value map[string]int64, usage string) *map[string]int64
StringToInt64P is like StringToInt64, but accepts a shorthand letter that can be used after a single dash.
func (f *FlagSet) StringToInt64Var(p *map[string]int64, name string, value map[string]int64, usage string)
StringToInt64Var defines a string flag with specified name, default value, and usage string. The argument p point64s to a map[string]int64 variable in which to store the values of the multiple flags. The value of each argument will not try to be separated by comma
func (f *FlagSet) StringToInt64VarP(p *map[string]int64, name, shorthand string, value map[string]int64, usage string)
StringToInt64VarP is like StringToInt64Var, but accepts a shorthand letter that can be used after a single dash.
func (f *FlagSet) StringToIntP(name, shorthand string, value map[string]int, usage string) *map[string]int
StringToIntP is like StringToInt, but accepts a shorthand letter that can be used after a single dash.
func (f *FlagSet) StringToIntVar(p *map[string]int, name string, value map[string]int, usage string)
StringToIntVar defines a string flag with specified name, default value, and usage string. The argument p points to a map[string]int variable in which to store the values of the multiple flags. The value of each argument will not try to be separated by comma
func (f *FlagSet) StringToIntVarP(p *map[string]int, name, shorthand string, value map[string]int, usage string)
StringToIntVarP is like StringToIntVar, but accepts a shorthand letter that can be used after a single dash.
func (f *FlagSet) StringToString(name string, value map[string]string, usage string) *map[string]string
StringToString defines a string flag with specified name, default value, and usage string. The return value is the address of a map[string]string variable that stores the value of the flag. The value of each argument will not try to be separated by comma
func (f *FlagSet) StringToStringP(name, shorthand string, value map[string]string, usage string) *map[string]string
StringToStringP is like StringToString, but accepts a shorthand letter that can be used after a single dash.
func (f *FlagSet) StringToStringVar(p *map[string]string, name string, value map[string]string, usage string)
StringToStringVar defines a string flag with specified name, default value, and usage string. The argument p points to a map[string]string variable in which to store the values of the multiple flags. The value of each argument will not try to be separated by comma
func (f *FlagSet) StringToStringVarP(p *map[string]string, name, shorthand string, value map[string]string, usage string)
StringToStringVarP is like StringToStringVar, but accepts a shorthand letter that can be used after a single dash.
func (f *FlagSet) StringVar(p *string, name string, value string, usage string)
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 (f *FlagSet) StringVarP(p *string, name, shorthand string, value string, usage string)
StringVarP is like StringVar, but accepts a shorthand letter that can be used after a single dash.
func (f *FlagSet) Uint(name string, value uint, usage string) *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 (f *FlagSet) Uint16(name string, value uint16, usage string) *uint16
Uint16 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 (f *FlagSet) Uint16P(name, shorthand string, value uint16, usage string) *uint16
Uint16P is like Uint16, but accepts a shorthand letter that can be used after a single dash.
func (f *FlagSet) Uint16Var(p *uint16, name string, value uint16, usage string)
Uint16Var 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 (f *FlagSet) Uint16VarP(p *uint16, name, shorthand string, value uint16, usage string)
Uint16VarP is like Uint16Var, but accepts a shorthand letter that can be used after a single dash.
func (f *FlagSet) Uint32(name string, value uint32, usage string) *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 (f *FlagSet) Uint32P(name, shorthand string, value uint32, usage string) *uint32
Uint32P is like Uint32, but accepts a shorthand letter that can be used after a single dash.
func (f *FlagSet) Uint32Var(p *uint32, name string, value uint32, usage string)
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 (f *FlagSet) Uint32VarP(p *uint32, name, shorthand string, value uint32, usage string)
Uint32VarP is like Uint32Var, but accepts a shorthand letter that can be used after a single dash.
func (f *FlagSet) Uint64(name string, value uint64, usage string) *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 (f *FlagSet) Uint64P(name, shorthand string, value uint64, usage string) *uint64
Uint64P is like Uint64, but accepts a shorthand letter that can be used after a single dash.
func (f *FlagSet) Uint64Var(p *uint64, name string, value uint64, usage string)
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 (f *FlagSet) Uint64VarP(p *uint64, name, shorthand string, value uint64, usage string)
Uint64VarP is like Uint64Var, but accepts a shorthand letter that can be used after a single dash.
func (f *FlagSet) Uint8(name string, value uint8, usage string) *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 (f *FlagSet) Uint8P(name, shorthand string, value uint8, usage string) *uint8
Uint8P is like Uint8, but accepts a shorthand letter that can be used after a single dash.
func (f *FlagSet) Uint8Var(p *uint8, name string, value uint8, usage string)
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 (f *FlagSet) Uint8VarP(p *uint8, name, shorthand string, value uint8, usage string)
Uint8VarP is like Uint8Var, but accepts a shorthand letter that can be used after a single dash.
func (f *FlagSet) UintP(name, shorthand string, value uint, usage string) *uint
UintP is like Uint, but accepts a shorthand letter that can be used after a single dash.
func (f *FlagSet) UintSlice(name string, value []uint, usage string) *[]uint
UintSlice 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 (f *FlagSet) UintSliceP(name, shorthand string, value []uint, usage string) *[]uint
UintSliceP is like UintSlice, but accepts a shorthand letter that can be used after a single dash.
func (f *FlagSet) UintSliceVar(p *[]uint, name string, value []uint, usage string)
UintSliceVar defines a uintSlice 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 (f *FlagSet) UintSliceVarP(p *[]uint, name, shorthand string, value []uint, usage string)
UintSliceVarP is like UintSliceVar, but accepts a shorthand letter that can be used after a single dash.
func (f *FlagSet) UintVar(p *uint, name string, value uint, usage string)
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 (f *FlagSet) UintVarP(p *uint, name, shorthand string, value uint, usage string)
UintVarP is like UintVar, but accepts a shorthand letter that can be used after a single dash.
func (f *FlagSet) Var(value Value, name string, usage string)
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.
func (f *FlagSet) VarP(value Value, name, shorthand, usage string)
VarP is like Var, but accepts a shorthand letter that can be used after a single dash.
func (f *FlagSet) VarPF(value Value, name, shorthand, usage string) *Flag
VarPF is like VarP, but returns the flag created
func (f *FlagSet) Visit(fn func(*Flag))
Visit visits the flags in lexicographical order or in primordial order if f.SortFlags is false, calling fn for each. It visits only those flags that have been set.
func (f *FlagSet) VisitAll(fn func(*Flag))
VisitAll visits the flags in lexicographical order or in primordial order if f.SortFlags is false, calling fn for each. It visits all flags, even those not set.
NormalizedName is a flag name that has been normalized according to rules for the FlagSet (e.g. making '-' and '_' equivalent).
type NormalizedName string
ParseErrorsWhitelist defines the parsing errors that can be ignored
type ParseErrorsWhitelist struct { // UnknownFlags will ignore unknown flags errors and continue parsing rest of the flags UnknownFlags bool }
SliceValue is a secondary interface to all flags which hold a list of values. This allows full control over the value of list flags, and avoids complicated marshalling and unmarshalling to csv.
type SliceValue interface { // Append adds the specified value to the end of the flag value list. Append(string) error // Replace will fully overwrite any data currently in the flag value list. Replace([]string) error // GetSlice returns the flag value list as an array of strings. GetSlice() []string }
Value is the interface to the dynamic value stored in a flag. (The default value is represented as a string.)
type Value interface { String() string Set(string) error Type() string }