package pflag

Import Path
	github.com/spf13/pflag (on go.dev)

Dependency Relation
	imports 15 packages, and imported by 2 packages

Involved Source Files bool.go bool_slice.go bytes.go count.go duration.go duration_slice.go Package pflag is a drop-in replacement for Go's flag package, implementing POSIX/GNU-style --flags. pflag is compatible with the GNU extensions to the POSIX recommendations for command-line options. See http://www.gnu.org/software/libc/manual/html_node/Argument-Syntax.html Usage: pflag is a drop-in replacement of Go's native flag package. If you import pflag under the name "flag" then all code should continue to function with no changes. import flag "github.com/spf13/pflag" There is one exception to this: if you directly instantiate the Flag struct there is one more field "Shorthand" that you will need to set. Most code never instantiates this struct directly, and instead uses functions such as String(), BoolVar(), and Var(), and is therefore unaffected. Define flags using flag.String(), Bool(), Int(), etc. This declares an integer flag, -flagname, stored in the pointer ip, with type *int. var ip = flag.Int("flagname", 1234, "help message for flagname") If you like, you can bind the flag to a variable using the Var() functions. var flagvar int func init() { flag.IntVar(&flagvar, "flagname", 1234, "help message for flagname") } Or you can create custom flags that satisfy the Value interface (with pointer receivers) and couple them to flag parsing by flag.Var(&flagVal, "name", "help message for flagname") For such flags, the default value is just the initial value of the variable. After all flags are defined, call flag.Parse() to parse the command line into the defined flags. Flags may then be used directly. If you're using the flags themselves, they are all pointers; if you bind to variables, they're values. fmt.Println("ip has value ", *ip) fmt.Println("flagvar has value ", flagvar) After parsing, the arguments after the flag are available as the slice flag.Args() or individually as flag.Arg(i). The arguments are indexed from 0 through flag.NArg()-1. The pflag package also defines some new functions that are not in flag, that give one-letter shorthands for flags. You can use these by appending 'P' to the name of any function that defines a flag. var ip = flag.IntP("flagname", "f", 1234, "help message") var flagvar bool func init() { flag.BoolVarP(&flagvar, "boolname", "b", true, "help message") } flag.VarP(&flagval, "varname", "v", "help message") Shorthand letters can be used with single dashes on the command line. Boolean shorthand flags can be combined with other shorthand flags. Command line flag syntax: --flag // boolean flags only --flag=x Unlike the flag package, a single dash before an option means something different than a double dash. Single dashes signify a series of shorthand letters for flags. All but the last shorthand letter must be boolean flags. // boolean flags -f -abc // non-boolean flags -n 1234 -Ifile // mixed -abcs "hello" -abcn1234 Flag parsing stops after the terminator "--". Unlike the flag package, flags can be interspersed with arguments anywhere on the command line before this terminator. Integer flags accept 1234, 0664, 0x1234 and may be negative. Boolean flags (in their long form) accept 1, 0, t, f, true, false, TRUE, FALSE, True, False. Duration flags accept any input valid for time.ParseDuration. The default set of command-line flags is controlled by top-level functions. The FlagSet type allows one to define independent sets of flags, such as to implement subcommands in a command-line interface. The methods of FlagSet are analogous to the top-level functions for the command-line flag set. float32.go float32_slice.go float64.go float64_slice.go golangflag.go int.go int16.go int32.go int32_slice.go int64.go int64_slice.go int8.go int_slice.go ip.go ip_slice.go ipmask.go ipnet.go string.go string_array.go string_slice.go string_to_int.go string_to_int64.go string_to_string.go uint.go uint16.go uint32.go uint64.go uint8.go uint_slice.go
Code Examples package main import ( "fmt" "github.com/spf13/pflag" ) func main() { name := "verbose" short := name[:1] fs := pflag.NewFlagSet("Example", pflag.ContinueOnError) fs.BoolP(name, short, false, "verbose output") // len(short) must be == 1 flag := fs.ShorthandLookup(short) fmt.Println(flag.Name) } package main import ( "fmt" "github.com/spf13/pflag" ) func main() { name := "verbose" short := name[:1] pflag.BoolP(name, short, false, "verbose output") // len(short) must be == 1 flag := pflag.ShorthandLookup(short) fmt.Println(flag.Name) }
Package-Level Type Names (total 46, in which 7 are exported)
/* sort exporteds by: | */
ErrorHandling defines how to handle flag parsing errors. func NewFlagSet(name string, errorHandling ErrorHandling) *FlagSet func (*FlagSet).Init(name string, errorHandling ErrorHandling) const ContinueOnError const ExitOnError const PanicOnError
A Flag represents the state of a flag. // used by cobra.Command bash autocomple code // If the user set the value (or if left to default) // default value (as text); for usage message // If this flag is deprecated, this string is the new or now thing to use // used by cobra.Command to allow flags to be hidden from help/usage text // name as it appears on command line // default value (as text); if the flag is on the command line without any options // one-letter abbreviated flag // If the shorthand of this flag is deprecated, this string is the new or now thing to use // help message // value as set func Lookup(name string) *Flag func PFlagFromGoFlag(goflag *goflag.Flag) *Flag func ShorthandLookup(name string) *Flag func (*FlagSet).Lookup(name string) *Flag func (*FlagSet).ShorthandLookup(name string) *Flag func (*FlagSet).VarPF(value Value, name, shorthand, usage string) *Flag func github.com/spf13/cobra.(*Command).Flag(name string) (flag *Flag) func UnquoteUsage(flag *Flag) (name string, usage string) func (*FlagSet).AddFlag(flag *Flag) func github.com/spf13/viper.BindPFlag(key string, flag *Flag) error func github.com/spf13/viper.(*Viper).BindPFlag(key string, flag *Flag) error
A FlagSet represents a set of defined flags. ParseErrorsWhitelist is used to configure a whitelist of errors SortFlags is used to indicate, if user wants to have sorted flags in help/usage messages. 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. AddFlag will add the flag to the FlagSet AddFlagSet adds one FlagSet to another. If a flag is already present in f the flag from newSet will be ignored. AddGoFlag will add the given *flag.Flag to the pflag.FlagSet AddGoFlagSet will add the given *flag.FlagSet to the pflag.FlagSet Arg returns the i'th argument. Arg(0) is the first remaining argument after flags have been processed. Args returns the non-flag arguments. 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. 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. BoolP is like Bool, but accepts a shorthand letter that can be used after a single dash. 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. BoolSliceP is like BoolSlice, but accepts a shorthand letter that can be used after a single dash. 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. BoolSliceVarP is like BoolSliceVar, but accepts a shorthand letter that can be used after a single dash. 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. BoolVarP is like BoolVar, but accepts a shorthand letter that can be used after a single dash. 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. BytesBase64P is like BytesBase64, but accepts a shorthand letter that can be used after a single dash. 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. BytesBase64VarP is like BytesBase64Var, but accepts a shorthand letter that can be used after a single dash. 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. BytesHexP is like BytesHex, but accepts a shorthand letter that can be used after a single dash. 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. BytesHexVarP is like BytesHexVar, but accepts a shorthand letter that can be used after a single dash. Changed returns true if the flag was explicitly set during Parse() and false otherwise 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 CountP is like Count only takes a shorthand for the flag name. 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 CountVarP is like CountVar only take a shorthand for the flag name. 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. DurationP is like Duration, but accepts a shorthand letter that can be used after a single dash. 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. DurationSliceP is like DurationSlice, but accepts a shorthand letter that can be used after a single dash. 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. DurationSliceVarP is like DurationSliceVar, but accepts a shorthand letter that can be used after a single dash. 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. DurationVarP is like DurationVar, but accepts a shorthand letter that can be used after a single dash. FlagUsages returns a string containing the usage information for all flags in the FlagSet FlagUsagesWrapped returns a string containing the usage information for all flags in the FlagSet. Wrapped to `cols` columns (0 for no wrapping) 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. Float32P is like Float32, but accepts a shorthand letter that can be used after a single dash. 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. Float32SliceP is like Float32Slice, but accepts a shorthand letter that can be used after a single dash. 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. Float32SliceVarP is like Float32SliceVar, but accepts a shorthand letter that can be used after a single dash. 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. Float32VarP is like Float32Var, but accepts a shorthand letter that can be used after a single dash. 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. Float64P is like Float64, but accepts a shorthand letter that can be used after a single dash. 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. Float64SliceP is like Float64Slice, but accepts a shorthand letter that can be used after a single dash. 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. Float64SliceVarP is like Float64SliceVar, but accepts a shorthand letter that can be used after a single dash. 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. Float64VarP is like Float64Var, but accepts a shorthand letter that can be used after a single dash. GetBool return the bool value of a flag with the given name GetBoolSlice returns the []bool value of a flag with the given name. GetBytesBase64 return the []byte value of a flag with the given name GetBytesHex return the []byte value of a flag with the given name GetCount return the int value of a flag with the given name GetDuration return the duration value of a flag with the given name GetDurationSlice returns the []time.Duration value of a flag with the given name GetFloat32 return the float32 value of a flag with the given name GetFloat32Slice return the []float32 value of a flag with the given name GetFloat64 return the float64 value of a flag with the given name GetFloat64Slice return the []float64 value of a flag with the given name GetIP return the net.IP value of a flag with the given name GetIPNet return the net.IPNet value of a flag with the given name GetIPSlice returns the []net.IP value of a flag with the given name GetIPv4Mask return the net.IPv4Mask value of a flag with the given name GetInt return the int value of a flag with the given name GetInt16 returns the int16 value of a flag with the given name GetInt32 return the int32 value of a flag with the given name GetInt32Slice return the []int32 value of a flag with the given name GetInt64 return the int64 value of a flag with the given name GetInt64Slice return the []int64 value of a flag with the given name GetInt8 return the int8 value of a flag with the given name GetIntSlice return the []int value of a flag with the given name GetNormalizeFunc returns the previously set NormalizeFunc of a function which does no translation, if not set previously. GetString return the string value of a flag with the given name GetStringArray return the []string value of a flag with the given name GetStringSlice return the []string value of a flag with the given name GetStringToInt return the map[string]int value of a flag with the given name GetStringToInt64 return the map[string]int64 value of a flag with the given name GetStringToString return the map[string]string value of a flag with the given name GetUint return the uint value of a flag with the given name GetUint16 return the uint16 value of a flag with the given name GetUint32 return the uint32 value of a flag with the given name GetUint64 return the uint64 value of a flag with the given name GetUint8 return the uint8 value of a flag with the given name GetUintSlice returns the []uint value of a flag with the given name. HasAvailableFlags returns a bool to indicate if the FlagSet has any flags that are not hidden. HasFlags returns a bool to indicate if the FlagSet has any flags defined. 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. 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. IPMaskP is like IPMask, but accepts a shorthand letter that can be used after a single dash. 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. IPMaskVarP is like IPMaskVar, but accepts a shorthand letter that can be used after a single dash. 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. IPNetP is like IPNet, but accepts a shorthand letter that can be used after a single dash. 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. IPNetVarP is like IPNetVar, but accepts a shorthand letter that can be used after a single dash. IPP is like IP, but accepts a shorthand letter that can be used after a single dash. 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. IPSliceP is like IPSlice, but accepts a shorthand letter that can be used after a single dash. 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. IPSliceVarP is like IPSliceVar, but accepts a shorthand letter that can be used after a single dash. 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. IPVarP is like IPVar, but accepts a shorthand letter that can be used after a single dash. 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. 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. 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. Int16P is like Int16, but accepts a shorthand letter that can be used after a single dash. 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. Int16VarP is like Int16Var, but accepts a shorthand letter that can be used after a single dash. 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. Int32P is like Int32, but accepts a shorthand letter that can be used after a single dash. 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. Int32SliceP is like Int32Slice, but accepts a shorthand letter that can be used after a single dash. 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. Int32SliceVarP is like Int32SliceVar, but accepts a shorthand letter that can be used after a single dash. 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. Int32VarP is like Int32Var, but accepts a shorthand letter that can be used after a single dash. 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. Int64P is like Int64, but accepts a shorthand letter that can be used after a single dash. 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. Int64SliceP is like Int64Slice, but accepts a shorthand letter that can be used after a single dash. 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. Int64SliceVarP is like Int64SliceVar, but accepts a shorthand letter that can be used after a single dash. 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. Int64VarP is like Int64Var, but accepts a shorthand letter that can be used after a single dash. 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. Int8P is like Int8, but accepts a shorthand letter that can be used after a single dash. 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. Int8VarP is like Int8Var, but accepts a shorthand letter that can be used after a single dash. IntP is like Int, but accepts a shorthand letter that can be used after a single dash. 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. IntSliceP is like IntSlice, but accepts a shorthand letter that can be used after a single dash. 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. IntSliceVarP is like IntSliceVar, but accepts a shorthand letter that can be used after a single dash. 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. IntVarP is like IntVar, but accepts a shorthand letter that can be used after a single dash. Lookup returns the Flag structure of the named flag, returning nil if none exists. 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. MarkHidden sets a flag to 'hidden' in your program. It will continue to function but will not show up in help or usage messages. 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. NArg is the number of arguments remaining after flags have been processed. NFlag returns the number of flags that have been set. 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. 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. Parsed reports whether f.Parse has been called. PrintDefaults prints, to standard error unless configured otherwise, the default values of all defined flags in the set. Set sets the value of the named flag. 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. SetInterspersed sets whether to support interspersed option/non-option arguments. 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. SetOutput sets the destination for usage and error messages. If output is nil, os.Stderr is used. ShorthandLookup returns the Flag structure of the short handed flag, returning nil if none exists. It panics, if len(name) > 1. 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. 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. StringArrayP is like StringArray, but accepts a shorthand letter that can be used after a single dash. 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. StringArrayVarP is like StringArrayVar, but accepts a shorthand letter that can be used after a single dash. StringP is like String, but accepts a shorthand letter that can be used after a single dash. 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"} StringSliceP is like StringSlice, but accepts a shorthand letter that can be used after a single dash. 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"} StringSliceVarP is like StringSliceVar, but accepts a shorthand letter that can be used after a single dash. 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 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 StringToInt64P is like StringToInt64, but accepts a shorthand letter that can be used after a single dash. 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 StringToInt64VarP is like StringToInt64Var, but accepts a shorthand letter that can be used after a single dash. StringToIntP is like StringToInt, but accepts a shorthand letter that can be used after a single dash. 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 StringToIntVarP is like StringToIntVar, but accepts a shorthand letter that can be used after a single dash. 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 StringToStringP is like StringToString, but accepts a shorthand letter that can be used after a single dash. 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 StringToStringVarP is like StringToStringVar, but accepts a shorthand letter that can be used after a single dash. 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. StringVarP is like StringVar, but accepts a shorthand letter that can be used after a single dash. 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. 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. Uint16P is like Uint16, but accepts a shorthand letter that can be used after a single dash. 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. Uint16VarP is like Uint16Var, but accepts a shorthand letter that can be used after a single dash. 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. Uint32P is like Uint32, but accepts a shorthand letter that can be used after a single dash. 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. Uint32VarP is like Uint32Var, but accepts a shorthand letter that can be used after a single dash. 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. Uint64P is like Uint64, but accepts a shorthand letter that can be used after a single dash. 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. Uint64VarP is like Uint64Var, but accepts a shorthand letter that can be used after a single dash. 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. Uint8P is like Uint8, but accepts a shorthand letter that can be used after a single dash. 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. Uint8VarP is like Uint8Var, but accepts a shorthand letter that can be used after a single dash. UintP is like Uint, but accepts a shorthand letter that can be used after a single dash. 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. UintSliceP is like UintSlice, but accepts a shorthand letter that can be used after a single dash. 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. UintSliceVarP is like UintSliceVar, but accepts a shorthand letter that can be used after a single dash. 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. UintVarP is like UintVar, but accepts a shorthand letter that can be used after a single dash. 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. VarP is like Var, but accepts a shorthand letter that can be used after a single dash. VarPF is like VarP, but returns the flag created 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. 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. func NewFlagSet(name string, errorHandling ErrorHandling) *FlagSet func github.com/spf13/cobra.(*Command).Flags() *FlagSet func github.com/spf13/cobra.(*Command).InheritedFlags() *FlagSet func github.com/spf13/cobra.(*Command).LocalFlags() *FlagSet func github.com/spf13/cobra.(*Command).LocalNonPersistentFlags() *FlagSet func github.com/spf13/cobra.(*Command).NonInheritedFlags() *FlagSet func github.com/spf13/cobra.(*Command).PersistentFlags() *FlagSet func (*FlagSet).AddFlagSet(newSet *FlagSet) func github.com/spf13/cobra.MarkFlagCustom(flags *FlagSet, name string, f string) error func github.com/spf13/cobra.MarkFlagDirname(flags *FlagSet, name string) error func github.com/spf13/cobra.MarkFlagFilename(flags *FlagSet, name string, extensions ...string) error func github.com/spf13/cobra.MarkFlagRequired(flags *FlagSet, name string) error func github.com/spf13/viper.BindPFlags(flags *FlagSet) error func github.com/spf13/viper.(*Viper).BindPFlags(flags *FlagSet) error var CommandLine *FlagSet
NormalizedName is a flag name that has been normalized according to rules for the FlagSet (e.g. making '-' and '_' equivalent).
ParseErrorsWhitelist defines the parsing errors that can be ignored UnknownFlags will ignore unknown flags errors and continue parsing rest of the flags
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. Append adds the specified value to the end of the flag value list. GetSlice returns the flag value list as an array of strings. Replace will fully overwrite any data currently in the flag value list.
Value is the interface to the dynamic value stored in a flag. (The default value is represented as a string.) ( T) Set(string) error ( T) String() string ( T) Type() string T : flag.Value T : fmt.Stringer func Var(value Value, name string, usage string) func VarP(value Value, name, shorthand, usage string) func (*FlagSet).Var(value Value, name string, usage string) func (*FlagSet).VarP(value Value, name, shorthand, usage string) func (*FlagSet).VarPF(value Value, name, shorthand, usage string) *Flag
Package-Level Functions (total 238, in which 160 are exported)
Arg returns the i'th command-line argument. Arg(0) is the first remaining argument after flags have been processed.
Args returns the non-flag command-line arguments.
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.
BoolP is like Bool, but accepts a shorthand letter that can be used after a single dash.
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.
BoolSliceP is like BoolSlice, but accepts a shorthand letter that can be used after a single dash.
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.
BoolSliceVarP is like BoolSliceVar, but accepts a shorthand letter that can be used after a single dash.
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.
BoolVarP is like BoolVar, but accepts a shorthand letter that can be used after a single dash.
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.
BytesBase64P is like BytesBase64, but accepts a shorthand letter that can be used after a single dash.
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.
BytesBase64VarP is like BytesBase64Var, but accepts a shorthand letter that can be used after a single dash.
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.
BytesHexP is like BytesHex, but accepts a shorthand letter that can be used after a single dash.
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.
BytesHexVarP is like BytesHexVar, but accepts a shorthand letter that can be used after a single dash.
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
CountP is like Count only takes a shorthand for the flag name.
CountVar like CountVar only the flag is placed on the CommandLine instead of a given flag set
CountVarP is like CountVar only take a shorthand for the flag name.
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.
DurationP is like Duration, but accepts a shorthand letter that can be used after a single dash.
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.
DurationSliceP is like DurationSlice, but accepts a shorthand letter that can be used after a single dash.
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.
DurationSliceVarP is like DurationSliceVar, but accepts a shorthand letter that can be used after a single dash.
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.
DurationVarP is like DurationVar, but accepts a shorthand letter that can be used after a single dash.
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.
Float32P is like Float32, but accepts a shorthand letter that can be used after a single dash.
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.
Float32SliceP is like Float32Slice, but accepts a shorthand letter that can be used after a single dash.
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.
Float32SliceVarP is like Float32SliceVar, but accepts a shorthand letter that can be used after a single dash.
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.
Float32VarP is like Float32Var, but accepts a shorthand letter that can be used after a single dash.
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.
Float64P is like Float64, but accepts a shorthand letter that can be used after a single dash.
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.
Float64SliceP is like Float64Slice, but accepts a shorthand letter that can be used after a single dash.
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.
Float64SliceVarP is like Float64SliceVar, but accepts a shorthand letter that can be used after a single dash.
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.
Float64VarP is like Float64Var, but accepts a shorthand letter that can be used after a single dash.
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.
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.
Int16P is like Int16, but accepts a shorthand letter that can be used after a single dash.
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.
Int16VarP is like Int16Var, but accepts a shorthand letter that can be used after a single dash.
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.
Int32P is like Int32, but accepts a shorthand letter that can be used after a single dash.
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.
Int32SliceP is like Int32Slice, but accepts a shorthand letter that can be used after a single dash.
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.
Int32SliceVarP is like Int32SliceVar, but accepts a shorthand letter that can be used after a single dash.
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.
Int32VarP is like Int32Var, but accepts a shorthand letter that can be used after a single dash.
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.
Int64P is like Int64, but accepts a shorthand letter that can be used after a single dash.
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.
Int64SliceP is like Int64Slice, but accepts a shorthand letter that can be used after a single dash.
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.
Int64SliceVarP is like Int64SliceVar, but accepts a shorthand letter that can be used after a single dash.
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.
Int64VarP is like Int64Var, but accepts a shorthand letter that can be used after a single dash.
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.
Int8P is like Int8, but accepts a shorthand letter that can be used after a single dash.
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.
Int8VarP is like Int8Var, but accepts a shorthand letter that can be used after a single dash.
IntP is like Int, but accepts a shorthand letter that can be used after a single dash.
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.
IntSliceP is like IntSlice, but accepts a shorthand letter that can be used after a single dash.
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.
IntSliceVarP is like IntSliceVar, but accepts a shorthand letter that can be used after a single dash.
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.
IntVarP is like IntVar, but accepts a shorthand letter that can be used after a single dash.
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.
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.
IPMaskP is like IP, but accepts a shorthand letter that can be used after a single dash.
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.
IPMaskVarP is like IPMaskVar, but accepts a shorthand letter that can be used after a single dash.
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.
IPNetP is like IPNet, but accepts a shorthand letter that can be used after a single dash.
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.
IPNetVarP is like IPNetVar, but accepts a shorthand letter that can be used after a single dash.
IPP is like IP, but accepts a shorthand letter that can be used after a single dash.
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.
IPSliceP is like IPSlice, but accepts a shorthand letter that can be used after a single dash.
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.
IPSliceVarP is like IPSliceVar, but accepts a shorthand letter that can be used after a single dash.
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.
IPVarP is like IPVar, but accepts a shorthand letter that can be used after a single dash.
Lookup returns the Flag structure of the named command-line flag, returning nil if none exists.
NArg is the number of arguments remaining after flags have been processed.
NewFlagSet returns a new, empty flag set with the specified name, error handling property and SortFlags set to true.
NFlag returns the number of command-line flags that have been set.
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.
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.
Parsed returns true if the command-line flags have been parsed.
ParseIPv4Mask written in IP form (e.g. 255.255.255.0). This function should really belong to the net package.
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`
PrintDefaults prints to standard error the default values of all defined command-line flags.
Set sets the value of the named command-line flag.
SetInterspersed sets whether to support interspersed option/non-option arguments.
ShorthandLookup returns the Flag structure of the short handed flag, returning nil if none exists.
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.
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.
StringArrayP is like StringArray, but accepts a shorthand letter that can be used after a single dash.
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.
StringArrayVarP is like StringArrayVar, but accepts a shorthand letter that can be used after a single dash.
StringP is like String, but accepts a shorthand letter that can be used after a single dash.
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"}
StringSliceP is like StringSlice, but accepts a shorthand letter that can be used after a single dash.
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"}
StringSliceVarP is like StringSliceVar, but accepts a shorthand letter that can be used after a single dash.
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
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
StringToInt64P is like StringToInt64, but accepts a shorthand letter that can be used after a single dash.
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
StringToInt64VarP is like StringToInt64Var, but accepts a shorthand letter that can be used after a single dash.
StringToIntP is like StringToInt, but accepts a shorthand letter that can be used after a single dash.
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
StringToIntVarP is like StringToIntVar, but accepts a shorthand letter that can be used after a single dash.
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
StringToStringP is like StringToString, but accepts a shorthand letter that can be used after a single dash.
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
StringToStringVarP is like StringToStringVar, but accepts a shorthand letter that can be used after a single dash.
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.
StringVarP is like StringVar, but accepts a shorthand letter that can be used after a single dash.
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.
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.
Uint16P is like Uint16, but accepts a shorthand letter that can be used after a single dash.
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.
Uint16VarP is like Uint16Var, but accepts a shorthand letter that can be used after a single dash.
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.
Uint32P is like Uint32, but accepts a shorthand letter that can be used after a single dash.
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.
Uint32VarP is like Uint32Var, but accepts a shorthand letter that can be used after a single dash.
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.
Uint64P is like Uint64, but accepts a shorthand letter that can be used after a single dash.
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.
Uint64VarP is like Uint64Var, but accepts a shorthand letter that can be used after a single dash.
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.
Uint8P is like Uint8, but accepts a shorthand letter that can be used after a single dash.
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.
Uint8VarP is like Uint8Var, but accepts a shorthand letter that can be used after a single dash.
UintP is like Uint, but accepts a shorthand letter that can be used after a single dash.
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.
UintSliceP is like UintSlice, but accepts a shorthand letter that can be used after a single dash.
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.
UintSliceVarP is like the UintSliceVar, but accepts a shorthand letter that can be used after a single dash.
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.
UintVarP is like UintVar, but accepts a shorthand letter that can be used after a single dash.
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.
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.
VarP is like Var, but accepts a shorthand letter that can be used after a single dash.
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.
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.
Package-Level Variables (total 3, all are exported)
CommandLine is the default set of command-line flags, parsed from os.Args.
ErrHelp is the error returned if the flag -help is invoked but no such flag is defined.
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.
Package-Level Constants (total 3, all are exported)
ContinueOnError will return an err from Parse() if an error is found
ExitOnError will call os.Exit(2) if an error is found when parsing
PanicOnError will panic() if an error is found when parsing flags