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.
This section is empty.
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.
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.
BoolFunc defines a func flag with specified name, callback function and usage string.
The callback function will be called every time "--{name}" (or any form that matches the flag) is parsed on the command line.
BoolFuncP is like BoolFunc, but accepts a shorthand letter that can be used after a single dash.
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 every 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.
Func defines a func flag with specified name, callback function and usage string.
The callback function will be called every time "--{name}={value}" (or equivalent) is parsed on the command line, with "{value}" as an argument.
FuncP is like Func, 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.
IPNetSlice defines a []net.IPNet 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.
IPNetSliceP is like IPNetSlice, but accepts a shorthand letter that can be used after a single dash.
IPNetSliceVar defines a []net.IPNet flag with specified name, default value, and usage string. The argument p points to a []net.IPNet variable in which to store the value of the flag.
IPNetSliceVarP is like IPNetSliceVar, 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.
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.
NArg is the number of arguments remaining after flags have been processed.
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.
ParseIPv4Mask written in IP form (e.g. 255.255.255.0). This function should really belong to the net package.
ParseSkippedFlags explicitly Parses go test flags (i.e. the one starting with '-test.') with goflag.Parse(), since by default those are skipped by pflag.Parse(). Typical usage example: `ParseGoTestFlags(os.Args[1:], goflag.CommandLine)`
Parsed returns true if the command-line flags have been parsed.
PrintDefaults prints to standard error the default values of all defined command-line flags.
Set sets the value of the named command-line flag.
func SetInterspersed(interspersed bool)
SetInterspersed sets whether to support interspersed option/non-option arguments.
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.
TextVar defines a flag with a specified name, default value, and usage string. The argument p must be a pointer to a variable that will hold the value of the flag, and p must implement encoding.TextUnmarshaler. If the flag is used, the flag value will be passed to p's UnmarshalText method. The type of the default value must be the same as the type of p.
TextVarP is like TextVar, but accepts a shorthand letter that can be used after a single dash.
Time defines a time.Time flag with specified name, default value, and usage string. The return value is the address of a time.Time variable that stores the value of the flag.
TimeP is like Time, but accepts a shorthand letter that can be used after a single dash.
TimeVar defines a time.Time flag with specified name, default value, and usage string. The argument p points to a time.Time variable in which to store the value of the flag.
TimeVarP is like TimeVar, 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.
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.
type ErrorHandling ¶ErrorHandling defines how to handle flag parsing errors.
A Flag represents the state of a flag.
Lookup returns the Flag structure of the named command-line flag, returning nil if none exists.
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 ¶ShorthandLookup returns the Flag structure of the short handed flag, returning nil if none exists.
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) }
A FlagSet represents a set of defined flags.
NewFlagSet returns a new, empty flag set with the specified name, error handling property and SortFlags set to true.
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.
BoolFunc defines a func flag with specified name, callback function and usage string.
The callback function will be called every time "--{name}" (or any form that matches the flag) is parsed on the command line.
BoolFuncP is like BoolFunc, but accepts a shorthand letter that can be used after a single dash.
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.
Func defines a func flag with specified name, callback function and usage string.
The callback function will be called every time "--{name}={value}" (or equivalent) is parsed on the command line, with "{value}" as an argument.
FuncP is like Func, 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
GetIPNetSlice returns 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
GetText set out, which implements encoding.UnmarshalText, to the value of a flag with given name
GetTime return the time 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.
IPNetSlice defines a []net.IPNet flag with specified name, default value, and usage string. The return value is the address of a []net.IPNet variable that stores the value of that flag.
IPNetSliceP is like IPNetSlice, but accepts a shorthand letter that can be used after a single dash.
IPNetSliceVar defines a ipNetSlice flag with specified name, default value, and usage string. The argument p points to a []net.IPNet variable in which to store the value of the flag.
IPNetSliceVarP is like IPNetSliceVar, 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.
func (*FlagSet) MarkShorthandDeprecated ¶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.
Name returns the name of the flag set.
Output returns the destination for usage and error messages. os.Stderr is returned if output was not set or was set to nil.
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.
func (*FlagSet) ShorthandLookup ¶ShorthandLookup returns the Flag structure of the short handed flag, returning nil if none exists. It panics, if len(name) > 1.
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) }
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.
TextVar defines a flag with a specified name, default value, and usage string. The argument p must be a pointer to a variable that will hold the value of the flag, and p must implement encoding.TextUnmarshaler. If the flag is used, the flag value will be passed to p's UnmarshalText method. The type of the default value must be the same as the type of p.
TextVarP is like TextVar, but accepts a shorthand letter that can be used after a single dash.
Time defines a time.Time flag with specified name, default value, and usage string. The return value is the address of a time.Time variable that stores the value of the flag.
TimeP is like Time, but accepts a shorthand letter that can be used after a single dash.
TimeVar defines a time.Time flag with specified name, default value, and usage string. The argument p points to a time.Time variable in which to store the value of the flag.
TimeVarP is like TimeVar, 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.
type InvalidSyntaxError struct { }
InvalidSyntaxError is the error returned when a bad flag name is passed on the command line.
GetSpecifiedName returns the exact flag (with dashes) as it appeared in the parsed arguments.
type InvalidValueError struct { }
InvalidValueError is the error returned when an invalid value is used for a flag.
GetFlag returns the flag for which the error occurred.
GetValue returns the invalid value that was provided.
Unwrap implements errors.Unwrap.
NormalizedName is a flag name that has been normalized according to rules for the FlagSet (e.g. making '-' and '_' equivalent).
type NotExistError struct { }
NotExistError is the error returned when trying to access a flag that does not exist in the FlagSet.
GetSpecifiedName returns the name of the flag (without dashes) as it appeared in the parsed arguments.
GetSpecifiedShortnames returns the group of shorthand arguments (without dashes) that the flag appeared within. If the flag was not in a shorthand group, this will return an empty string.
type ParseErrorsWhitelist struct { UnknownFlags bool }
ParseErrorsWhitelist defines the parsing errors that can be ignored
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.
Value is the interface to the dynamic value stored in a flag. (The default value is represented as a string.)
type ValueRequiredError struct { }
ValueRequiredError is the error returned when a flag needs an argument but no argument was provided.
GetFlag returns the flag for which the error occurred.
GetSpecifiedName returns the name of the flag (without dashes) as it appeared in the parsed arguments.
GetSpecifiedShortnames returns the group of shorthand arguments (without dashes) that the flag appeared within. If the flag was not in a shorthand group, this will return an empty string.
RetroSearch is an open source project built by @garambo | Open a GitHub Issue
Search and Browse the WWW like it's 1997 | Search results from DuckDuckGo
HTML:
3.2
| Encoding:
UTF-8
| Version:
0.7.4