pflag
packagemoduleThis package is not in the latest version of its module.
Details
Validgo.mod file
The Go module system was introduced in Go 1.11 and is the official dependency management solution for Go.
Redistributable license
Redistributable licenses place minimal restrictions on how software can be used, modified, and redistributed.
Tagged version
Modules with tagged versions give importers more predictable builds.
Stable version
When a project reaches major version v1 it is considered stable.
- Learn more about best practices
Repository
Links
README¶
Description
pflag is a drop-in replacement for Go's flag package, implementingPOSIX/GNU-style --flags.
pflag is compatible with theGNU extensions to the POSIX recommendationsfor command-line options. For a more precise description, see the"Command-line flag syntax" section below.
pflag is available under the same style of BSD license as the Go language,which can be found in the LICENSE file.
Installation
pflag is available using the standardgo get command.
Install by running:
go get github.com/spf13/pflagRun tests by running:
go test github.com/spf13/pflagUsage
pflag is a drop-in replacement of Go's native flag package. If you importpflag under the name "flag" then all code should continue to functionwith no changes.
import flag "github.com/spf13/pflag"There is one exception to this: if you directly instantiate the Flag structthere is one more field "Shorthand" that you will need to set.Most code never instantiates this struct directly, and instead usesfunctions such as String(), BoolVar(), and Var(), and is thereforeunaffected.
Define flags using flag.String(), Bool(), Int(), etc.
This declares an integer flag, -flagname, stored in the pointer ip, with type *int.
var ip *int = 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 intfunc init() { flag.IntVar(&flagvar, "flagname", 1234, "help message for flagname")}Or you can create custom flags that satisfy the Value interface (withpointer 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)There are helper functions available to get the value stored in a Flag if you have a FlagSet but findit difficult to keep up with all of the pointers in your code.If you have a pflag.FlagSet with a flag called 'flagname' of type int youcan use GetInt() to get the int value. But notice that 'flagname' must existand it must be an int. GetString("flagname") will fail.
i, err := flagset.GetInt("flagname")After parsing, the arguments after the flag are available as theslice 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 boolfunc 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.
The default set of command-line flags is controlled bytop-level functions. The FlagSet type allows one to defineindependent sets of flags, such as to implement subcommandsin a command-line interface. The methods of FlagSet areanalogous to the top-level functions for the command-lineflag set.
Setting no option default values for flags
After you create a flag it is possible to set the pflag.NoOptDefVal forthe given flag. Doing this changes the meaning of the flag slightly. Ifa flag has a NoOptDefVal and the flag is set on the command line withoutan option the flag will be set to the NoOptDefVal. For example given:
var ip = flag.IntP("flagname", "f", 1234, "help message")flag.Lookup("flagname").NoOptDefVal = "4321"Would result in something like
| Parsed Arguments | Resulting Value |
|---|---|
| --flagname=1357 | ip=1357 |
| --flagname | ip=4321 |
| [nothing] | ip=1234 |
Command line flag syntax
--flag // boolean flags, or flags with no option default values--flag x // only on flags without a default value--flag=xUnlike the flag package, a single dash before an option means somethingdifferent than a double dash. Single dashes signify a series of shorthandletters for flags. All but the last shorthand letter must be boolean flagsor a flag with a default value
// boolean or flags where the 'no option default value' is set-f-f=true-abcbut-b true is INVALID// non-boolean and flags without a 'no option default value'-n 1234-n=1234-n1234// mixed-abcs "hello"-absd="hello"-abcs1234Flag parsing stops after the terminator "--". Unlike the flag package,flags can be interspersed with arguments anywhere on the command linebefore 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.
Mutating or "Normalizing" Flag names
It is possible to set a custom flag name 'normalization function.' It allows flag names to be mutated both when created in the code and when used on the command line to some 'normalized' form. The 'normalized' form is used for comparison. Two examples of using the custom normalization func follow.
Example #1: You want -, _, and . in flags to compare the same. aka --my-flag == --my_flag == --my.flag
func wordSepNormalizeFunc(f *pflag.FlagSet, name string) pflag.NormalizedName {from := []string{"-", "_"}to := "."for _, sep := range from {name = strings.Replace(name, sep, to, -1)}return pflag.NormalizedName(name)}myFlagSet.SetNormalizeFunc(wordSepNormalizeFunc)Example #2: You want to alias two flags. aka --old-flag-name == --new-flag-name
func aliasNormalizeFunc(f *pflag.FlagSet, name string) pflag.NormalizedName {switch name {case "old-flag-name":name = "new-flag-name"break}return pflag.NormalizedName(name)}myFlagSet.SetNormalizeFunc(aliasNormalizeFunc)Deprecating a flag or its shorthand
It is possible to deprecate a flag, or just its shorthand. Deprecating a flag/shorthand hides it from help text and prints a usage message when the deprecated flag/shorthand is used.
Example #1: You want to deprecate a flag named "badflag" as well as inform the users what flag they should use instead.
// deprecate a flag by specifying its name and a usage messageflags.MarkDeprecated("badflag", "please use --good-flag instead")This hides "badflag" from help text, and printsFlag --badflag has been deprecated, please use --good-flag instead when "badflag" is used.
Example #2: You want to keep a flag name "noshorthandflag" but deprecate its shortname "n".
// deprecate a flag shorthand by specifying its flag name and a usage messageflags.MarkShorthandDeprecated("noshorthandflag", "please use --noshorthandflag only")This hides the shortname "n" from help text, and printsFlag shorthand -n has been deprecated, please use --noshorthandflag only when the shorthand "n" is used.
Note that usage message is essential here, and it should not be empty.
Hidden flags
It is possible to mark a flag as hidden, meaning it will still function as normal, however will not show up in usage/help text.
Example: You have a flag named "secretFlag" that you need for internal use only and don't want it showing up in help text, or for its usage text to be available.
// hide a flag by specifying its nameflags.MarkHidden("secretFlag")Disable sorting of flags
pflag allows you to disable sorting of flags for help and usage message.
Example:
flags.BoolP("verbose", "v", false, "verbose output")flags.String("coolflag", "yeaah", "it's really cool flag")flags.Int("usefulflag", 777, "sometimes it's very useful")flags.SortFlags = falseflags.PrintDefaults()Output:
-v, --verbose verbose output --coolflag string it's really cool flag (default "yeaah") --usefulflag int sometimes it's very useful (default 777)Supporting Go flags when using pflag
In order to support flags defined using Go'sflag package, they must be added to thepflag flagset. This is usually necessaryto support flags defined by third-party dependencies (e.g.golang/glog).
Example: You want to add the Go flags to theCommandLine flagset
import (goflag "flag"flag "github.com/spf13/pflag")var ip *int = flag.Int("flagname", 1234, "help message for flagname")func main() {flag.CommandLine.AddGoFlagSet(goflag.CommandLine)flag.Parse()}Using pflag with go test
pflag does not parse the shorthand versions of go test's built-in flags (i.e., those starting with-test.).For more context, see issues#63 and#238 for more details.
For example, if you use pflag in yourTestMain function and callpflag.Parse() after defining your custom flags, running a test like this:
go test /your/tests -run ^YourTest -v --your-test-pflagswill result in the-v flag being ignored. This happens because of the way pflag handles flag parsing, skipping over go test's built-in shorthand flags.To work around this, you can use theParseSkippedFlags function, which ensures that go test's flags are parsed separately using the standard flag package.
Example: You want to parse go test flags that are otherwise ignore bypflag.Parse()
import (goflag "flag"flag "github.com/spf13/pflag")var ip *int = flag.Int("flagname", 1234, "help message for flagname")func main() {flag.CommandLine.AddGoFlagSet(goflag.CommandLine) flag.ParseSkippedFlags(os.Args[1:], goflag.CommandLine)flag.Parse()}More info
You can see the full reference documentation of the pflag packageat godoc.org, or through go's standard documentation system byrunninggodoc -http=:6060 and browsing tohttp://localhost:6060/pkg/github.com/spf13/pflag afterinstallation.
Documentation¶
Overview¶
Package pflag is a drop-in replacement for Go's flag package, implementingPOSIX/GNU-style --flags.
pflag is compatible with the GNU extensions to the POSIX recommendationsfor command-line options. Seehttp://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 importpflag under the name "flag" then all code should continue to functionwith no changes.
import flag "github.com/spf13/pflag"
There is one exception to this: if you directly instantiate the Flag structthere is one more field "Shorthand" that you will need to set.Most code never instantiates this struct directly, and instead usesfunctions such as String(), BoolVar(), and Var(), and is thereforeunaffected.
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 intfunc init() {flag.IntVar(&flagvar, "flagname", 1234, "help message for flagname")}Or you can create custom flags that satisfy the Value interface (withpointer 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 theslice 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 boolfunc 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 somethingdifferent than a double dash. Single dashes signify a series of shorthandletters 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 linebefore 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 bytop-level functions. The FlagSet type allows one to defineindependent sets of flags, such as to implement subcommandsin a command-line interface. The methods of FlagSet areanalogous to the top-level functions for the command-lineflag set.
Index¶
- Variables
- func Arg(i int) string
- func Args() []string
- func Bool(name string, value bool, usage string) *bool
- func BoolFunc(name string, usage string, fn func(string) error)
- func BoolFuncP(name, shorthand string, usage string, fn func(string) error)
- func BoolP(name, shorthand string, value bool, usage string) *bool
- func BoolSlice(name string, value []bool, usage string) *[]bool
- func BoolSliceP(name, shorthand string, value []bool, usage string) *[]bool
- func BoolSliceVar(p *[]bool, name string, value []bool, usage string)
- func BoolSliceVarP(p *[]bool, name, shorthand string, value []bool, usage string)
- func BoolVar(p *bool, name string, value bool, usage string)
- func BoolVarP(p *bool, name, shorthand string, value bool, usage string)
- func BytesBase64(name string, value []byte, usage string) *[]byte
- func BytesBase64P(name, shorthand string, value []byte, usage string) *[]byte
- func BytesBase64Var(p *[]byte, name string, value []byte, usage string)
- func BytesBase64VarP(p *[]byte, name, shorthand string, value []byte, usage string)
- func BytesHex(name string, value []byte, usage string) *[]byte
- func BytesHexP(name, shorthand string, value []byte, usage string) *[]byte
- func BytesHexVar(p *[]byte, name string, value []byte, usage string)
- func BytesHexVarP(p *[]byte, name, shorthand string, value []byte, usage string)
- func Count(name string, usage string) *int
- func CountP(name, shorthand string, usage string) *int
- func CountVar(p *int, name string, usage string)
- func CountVarP(p *int, name, shorthand string, usage string)
- func Duration(name string, value time.Duration, usage string) *time.Duration
- func DurationP(name, shorthand string, value time.Duration, usage string) *time.Duration
- func DurationSlice(name string, value []time.Duration, usage string) *[]time.Duration
- func DurationSliceP(name, shorthand string, value []time.Duration, usage string) *[]time.Duration
- func DurationSliceVar(p *[]time.Duration, name string, value []time.Duration, usage string)
- func DurationSliceVarP(p *[]time.Duration, name, shorthand string, value []time.Duration, ...)
- func DurationVar(p *time.Duration, name string, value time.Duration, usage string)
- func DurationVarP(p *time.Duration, name, shorthand string, value time.Duration, usage string)
- func Float32(name string, value float32, usage string) *float32
- func Float32P(name, shorthand string, value float32, usage string) *float32
- func Float32Slice(name string, value []float32, usage string) *[]float32
- func Float32SliceP(name, shorthand string, value []float32, usage string) *[]float32
- func Float32SliceVar(p *[]float32, name string, value []float32, usage string)
- func Float32SliceVarP(p *[]float32, name, shorthand string, value []float32, usage string)
- func Float32Var(p *float32, name string, value float32, usage string)
- func Float32VarP(p *float32, name, shorthand string, value float32, usage string)
- func Float64(name string, value float64, usage string) *float64
- func Float64P(name, shorthand string, value float64, usage string) *float64
- func Float64Slice(name string, value []float64, usage string) *[]float64
- func Float64SliceP(name, shorthand string, value []float64, usage string) *[]float64
- func Float64SliceVar(p *[]float64, name string, value []float64, usage string)
- func Float64SliceVarP(p *[]float64, name, shorthand string, value []float64, usage string)
- func Float64Var(p *float64, name string, value float64, usage string)
- func Float64VarP(p *float64, name, shorthand string, value float64, usage string)
- func Func(name string, usage string, fn func(string) error)
- func FuncP(name, shorthand string, usage string, fn func(string) error)
- func IP(name string, value net.IP, usage string) *net.IP
- func IPMask(name string, value net.IPMask, usage string) *net.IPMask
- func IPMaskP(name, shorthand string, value net.IPMask, usage string) *net.IPMask
- func IPMaskVar(p *net.IPMask, name string, value net.IPMask, usage string)
- func IPMaskVarP(p *net.IPMask, name, shorthand string, value net.IPMask, usage string)
- func IPNet(name string, value net.IPNet, usage string) *net.IPNet
- func IPNetP(name, shorthand string, value net.IPNet, usage string) *net.IPNet
- func IPNetSlice(name string, value []net.IPNet, usage string) *[]net.IPNet
- func IPNetSliceP(name, shorthand string, value []net.IPNet, usage string) *[]net.IPNet
- func IPNetSliceVar(p *[]net.IPNet, name string, value []net.IPNet, usage string)
- func IPNetSliceVarP(p *[]net.IPNet, name, shorthand string, value []net.IPNet, usage string)
- func IPNetVar(p *net.IPNet, name string, value net.IPNet, usage string)
- func IPNetVarP(p *net.IPNet, name, shorthand string, value net.IPNet, usage string)
- func IPP(name, shorthand string, value net.IP, usage string) *net.IP
- func IPSlice(name string, value []net.IP, usage string) *[]net.IP
- func IPSliceP(name, shorthand string, value []net.IP, usage string) *[]net.IP
- func IPSliceVar(p *[]net.IP, name string, value []net.IP, usage string)
- func IPSliceVarP(p *[]net.IP, name, shorthand string, value []net.IP, usage string)
- func IPVar(p *net.IP, name string, value net.IP, usage string)
- func IPVarP(p *net.IP, name, shorthand string, value net.IP, usage string)
- func Int(name string, value int, usage string) *int
- func Int16(name string, value int16, usage string) *int16
- func Int16P(name, shorthand string, value int16, usage string) *int16
- func Int16Var(p *int16, name string, value int16, usage string)
- func Int16VarP(p *int16, name, shorthand string, value int16, usage string)
- func Int32(name string, value int32, usage string) *int32
- func Int32P(name, shorthand string, value int32, usage string) *int32
- func Int32Slice(name string, value []int32, usage string) *[]int32
- func Int32SliceP(name, shorthand string, value []int32, usage string) *[]int32
- func Int32SliceVar(p *[]int32, name string, value []int32, usage string)
- func Int32SliceVarP(p *[]int32, name, shorthand string, value []int32, usage string)
- func Int32Var(p *int32, name string, value int32, usage string)
- func Int32VarP(p *int32, name, shorthand string, value int32, usage string)
- func Int64(name string, value int64, usage string) *int64
- func Int64P(name, shorthand string, value int64, usage string) *int64
- func Int64Slice(name string, value []int64, usage string) *[]int64
- func Int64SliceP(name, shorthand string, value []int64, usage string) *[]int64
- func Int64SliceVar(p *[]int64, name string, value []int64, usage string)
- func Int64SliceVarP(p *[]int64, name, shorthand string, value []int64, usage string)
- func Int64Var(p *int64, name string, value int64, usage string)
- func Int64VarP(p *int64, name, shorthand string, value int64, usage string)
- func Int8(name string, value int8, usage string) *int8
- func Int8P(name, shorthand string, value int8, usage string) *int8
- func Int8Var(p *int8, name string, value int8, usage string)
- func Int8VarP(p *int8, name, shorthand string, value int8, usage string)
- func IntP(name, shorthand string, value int, usage string) *int
- func IntSlice(name string, value []int, usage string) *[]int
- func IntSliceP(name, shorthand string, value []int, usage string) *[]int
- func IntSliceVar(p *[]int, name string, value []int, usage string)
- func IntSliceVarP(p *[]int, name, shorthand string, value []int, usage string)
- func IntVar(p *int, name string, value int, usage string)
- func IntVarP(p *int, name, shorthand string, value int, usage string)
- func NArg() int
- func NFlag() int
- func Parse()
- func ParseAll(fn func(flag *Flag, value string) error)
- func ParseIPv4Mask(s string) net.IPMask
- func ParseSkippedFlags(osArgs []string, goFlagSet *goflag.FlagSet) error
- func Parsed() bool
- func PrintDefaults()
- func Set(name, value string) error
- func SetInterspersed(interspersed bool)
- func String(name string, value string, usage string) *string
- func StringArray(name string, value []string, usage string) *[]string
- func StringArrayP(name, shorthand string, value []string, usage string) *[]string
- func StringArrayVar(p *[]string, name string, value []string, usage string)
- func StringArrayVarP(p *[]string, name, shorthand string, value []string, usage string)
- func StringP(name, shorthand string, value string, usage string) *string
- func StringSlice(name string, value []string, usage string) *[]string
- func StringSliceP(name, shorthand string, value []string, usage string) *[]string
- func StringSliceVar(p *[]string, name string, value []string, usage string)
- func StringSliceVarP(p *[]string, name, shorthand string, value []string, usage string)
- func StringToInt(name string, value map[string]int, usage string) *map[string]int
- func StringToInt64(name string, value map[string]int64, usage string) *map[string]int64
- func StringToInt64P(name, shorthand string, value map[string]int64, usage string) *map[string]int64
- func StringToInt64Var(p *map[string]int64, name string, value map[string]int64, usage string)
- func StringToInt64VarP(p *map[string]int64, name, shorthand string, value map[string]int64, ...)
- func StringToIntP(name, shorthand string, value map[string]int, usage string) *map[string]int
- func StringToIntVar(p *map[string]int, name string, value map[string]int, usage string)
- func StringToIntVarP(p *map[string]int, name, shorthand string, value map[string]int, usage string)
- func StringToString(name string, value map[string]string, usage string) *map[string]string
- func StringToStringP(name, shorthand string, value map[string]string, usage string) *map[string]string
- func StringToStringVar(p *map[string]string, name string, value map[string]string, usage string)
- func StringToStringVarP(p *map[string]string, name, shorthand string, value map[string]string, ...)
- func StringVar(p *string, name string, value string, usage string)
- func StringVarP(p *string, name, shorthand string, value string, usage string)
- func TextVar(p encoding.TextUnmarshaler, name string, value encoding.TextMarshaler, ...)
- func TextVarP(p encoding.TextUnmarshaler, name, shorthand string, ...)
- func Time(name string, value time.Time, formats []string, usage string) *time.Time
- func TimeP(name, shorthand string, value time.Time, formats []string, usage string) *time.Time
- func TimeVar(p *time.Time, name string, value time.Time, formats []string, usage string)
- func TimeVarP(p *time.Time, name, shorthand string, value time.Time, formats []string, ...)
- func Uint(name string, value uint, usage string) *uint
- func Uint16(name string, value uint16, usage string) *uint16
- func Uint16P(name, shorthand string, value uint16, usage string) *uint16
- func Uint16Var(p *uint16, name string, value uint16, usage string)
- func Uint16VarP(p *uint16, name, shorthand string, value uint16, usage string)
- func Uint32(name string, value uint32, usage string) *uint32
- func Uint32P(name, shorthand string, value uint32, usage string) *uint32
- func Uint32Var(p *uint32, name string, value uint32, usage string)
- func Uint32VarP(p *uint32, name, shorthand string, value uint32, usage string)
- func Uint64(name string, value uint64, usage string) *uint64
- func Uint64P(name, shorthand string, value uint64, usage string) *uint64
- func Uint64Var(p *uint64, name string, value uint64, usage string)
- func Uint64VarP(p *uint64, name, shorthand string, value uint64, usage string)
- func Uint8(name string, value uint8, usage string) *uint8
- func Uint8P(name, shorthand string, value uint8, usage string) *uint8
- func Uint8Var(p *uint8, name string, value uint8, usage string)
- func Uint8VarP(p *uint8, name, shorthand string, value uint8, usage string)
- func UintP(name, shorthand string, value uint, usage string) *uint
- func UintSlice(name string, value []uint, usage string) *[]uint
- func UintSliceP(name, shorthand string, value []uint, usage string) *[]uint
- func UintSliceVar(p *[]uint, name string, value []uint, usage string)
- func UintSliceVarP(p *[]uint, name, shorthand string, value []uint, usage string)
- func UintVar(p *uint, name string, value uint, usage string)
- func UintVarP(p *uint, name, shorthand string, value uint, usage string)
- func UnquoteUsage(flag *Flag) (name string, usage string)
- func Var(value Value, name string, usage string)
- func VarP(value Value, name, shorthand, usage string)
- func Visit(fn func(*Flag))
- func VisitAll(fn func(*Flag))
- type ErrorHandling
- type Flag
- type FlagSet
- func (f *FlagSet) AddFlag(flag *Flag)
- func (f *FlagSet) AddFlagSet(newSet *FlagSet)
- func (f *FlagSet) AddGoFlag(goflag *goflag.Flag)
- func (f *FlagSet) AddGoFlagSet(newSet *goflag.FlagSet)
- func (f *FlagSet) Arg(i int) string
- func (f *FlagSet) Args() []string
- func (f *FlagSet) ArgsLenAtDash() int
- func (f *FlagSet) Bool(name string, value bool, usage string) *bool
- func (f *FlagSet) BoolFunc(name string, usage string, fn func(string) error)
- func (f *FlagSet) BoolFuncP(name, shorthand string, usage string, fn func(string) error)
- func (f *FlagSet) BoolP(name, shorthand string, value bool, usage string) *bool
- func (f *FlagSet) BoolSlice(name string, value []bool, usage string) *[]bool
- func (f *FlagSet) BoolSliceP(name, shorthand string, value []bool, usage string) *[]bool
- func (f *FlagSet) BoolSliceVar(p *[]bool, name string, value []bool, usage string)
- func (f *FlagSet) BoolSliceVarP(p *[]bool, name, shorthand string, value []bool, usage string)
- func (f *FlagSet) BoolVar(p *bool, name string, value bool, usage string)
- func (f *FlagSet) BoolVarP(p *bool, name, shorthand string, value bool, usage string)
- func (f *FlagSet) BytesBase64(name string, value []byte, usage string) *[]byte
- func (f *FlagSet) BytesBase64P(name, shorthand string, value []byte, usage string) *[]byte
- func (f *FlagSet) BytesBase64Var(p *[]byte, name string, value []byte, usage string)
- func (f *FlagSet) BytesBase64VarP(p *[]byte, name, shorthand string, value []byte, usage string)
- func (f *FlagSet) BytesHex(name string, value []byte, usage string) *[]byte
- func (f *FlagSet) BytesHexP(name, shorthand string, value []byte, usage string) *[]byte
- func (f *FlagSet) BytesHexVar(p *[]byte, name string, value []byte, usage string)
- func (f *FlagSet) BytesHexVarP(p *[]byte, name, shorthand string, value []byte, usage string)
- func (f *FlagSet) Changed(name string) bool
- func (f *FlagSet) CopyToGoFlagSet(newSet *goflag.FlagSet)
- func (f *FlagSet) Count(name string, usage string) *int
- func (f *FlagSet) CountP(name, shorthand string, usage string) *int
- func (f *FlagSet) CountVar(p *int, name string, usage string)
- func (f *FlagSet) CountVarP(p *int, name, shorthand string, usage string)
- func (f *FlagSet) Duration(name string, value time.Duration, usage string) *time.Duration
- func (f *FlagSet) DurationP(name, shorthand string, value time.Duration, usage string) *time.Duration
- func (f *FlagSet) DurationSlice(name string, value []time.Duration, usage string) *[]time.Duration
- func (f *FlagSet) DurationSliceP(name, shorthand string, value []time.Duration, usage string) *[]time.Duration
- func (f *FlagSet) DurationSliceVar(p *[]time.Duration, name string, value []time.Duration, usage string)
- func (f *FlagSet) DurationSliceVarP(p *[]time.Duration, name, shorthand string, value []time.Duration, ...)
- func (f *FlagSet) DurationVar(p *time.Duration, name string, value time.Duration, usage string)
- func (f *FlagSet) DurationVarP(p *time.Duration, name, shorthand string, value time.Duration, usage string)
- func (f *FlagSet) FlagUsages() string
- func (f *FlagSet) FlagUsagesWrapped(cols int) string
- func (f *FlagSet) Float32(name string, value float32, usage string) *float32
- func (f *FlagSet) Float32P(name, shorthand string, value float32, usage string) *float32
- func (f *FlagSet) Float32Slice(name string, value []float32, usage string) *[]float32
- func (f *FlagSet) Float32SliceP(name, shorthand string, value []float32, usage string) *[]float32
- func (f *FlagSet) Float32SliceVar(p *[]float32, name string, value []float32, usage string)
- func (f *FlagSet) Float32SliceVarP(p *[]float32, name, shorthand string, value []float32, usage string)
- func (f *FlagSet) Float32Var(p *float32, name string, value float32, usage string)
- func (f *FlagSet) Float32VarP(p *float32, name, shorthand string, value float32, usage string)
- func (f *FlagSet) Float64(name string, value float64, usage string) *float64
- func (f *FlagSet) Float64P(name, shorthand string, value float64, usage string) *float64
- func (f *FlagSet) Float64Slice(name string, value []float64, usage string) *[]float64
- func (f *FlagSet) Float64SliceP(name, shorthand string, value []float64, usage string) *[]float64
- func (f *FlagSet) Float64SliceVar(p *[]float64, name string, value []float64, usage string)
- func (f *FlagSet) Float64SliceVarP(p *[]float64, name, shorthand string, value []float64, usage string)
- func (f *FlagSet) Float64Var(p *float64, name string, value float64, usage string)
- func (f *FlagSet) Float64VarP(p *float64, name, shorthand string, value float64, usage string)
- func (f *FlagSet) Func(name string, usage string, fn func(string) error)
- func (f *FlagSet) FuncP(name string, shorthand string, usage string, fn func(string) error)
- func (f *FlagSet) GetBool(name string) (bool, error)
- func (f *FlagSet) GetBoolSlice(name string) ([]bool, error)
- func (f *FlagSet) GetBytesBase64(name string) ([]byte, error)
- func (f *FlagSet) GetBytesHex(name string) ([]byte, error)
- func (f *FlagSet) GetCount(name string) (int, error)
- func (f *FlagSet) GetDuration(name string) (time.Duration, error)
- func (f *FlagSet) GetDurationSlice(name string) ([]time.Duration, error)
- func (f *FlagSet) GetFloat32(name string) (float32, error)
- func (f *FlagSet) GetFloat32Slice(name string) ([]float32, error)
- func (f *FlagSet) GetFloat64(name string) (float64, error)
- func (f *FlagSet) GetFloat64Slice(name string) ([]float64, error)
- func (f *FlagSet) GetIP(name string) (net.IP, error)
- func (f *FlagSet) GetIPNet(name string) (net.IPNet, error)
- func (f *FlagSet) GetIPNetSlice(name string) ([]net.IPNet, error)
- func (f *FlagSet) GetIPSlice(name string) ([]net.IP, error)
- func (f *FlagSet) GetIPv4Mask(name string) (net.IPMask, error)
- func (f *FlagSet) GetInt(name string) (int, error)
- func (f *FlagSet) GetInt16(name string) (int16, error)
- func (f *FlagSet) GetInt32(name string) (int32, error)
- func (f *FlagSet) GetInt32Slice(name string) ([]int32, error)
- func (f *FlagSet) GetInt64(name string) (int64, error)
- func (f *FlagSet) GetInt64Slice(name string) ([]int64, error)
- func (f *FlagSet) GetInt8(name string) (int8, error)
- func (f *FlagSet) GetIntSlice(name string) ([]int, error)
- func (f *FlagSet) GetNormalizeFunc() func(f *FlagSet, name string) NormalizedName
- func (f *FlagSet) GetString(name string) (string, error)
- func (f *FlagSet) GetStringArray(name string) ([]string, error)
- func (f *FlagSet) GetStringSlice(name string) ([]string, error)
- func (f *FlagSet) GetStringToInt(name string) (map[string]int, error)
- func (f *FlagSet) GetStringToInt64(name string) (map[string]int64, error)
- func (f *FlagSet) GetStringToString(name string) (map[string]string, error)
- func (f *FlagSet) GetText(name string, out encoding.TextUnmarshaler) error
- func (f *FlagSet) GetTime(name string) (time.Time, error)
- func (f *FlagSet) GetUint(name string) (uint, error)
- func (f *FlagSet) GetUint16(name string) (uint16, error)
- func (f *FlagSet) GetUint32(name string) (uint32, error)
- func (f *FlagSet) GetUint64(name string) (uint64, error)
- func (f *FlagSet) GetUint8(name string) (uint8, error)
- func (f *FlagSet) GetUintSlice(name string) ([]uint, error)
- func (f *FlagSet) HasAvailableFlags() bool
- func (f *FlagSet) HasFlags() bool
- func (f *FlagSet) IP(name string, value net.IP, usage string) *net.IP
- func (f *FlagSet) IPMask(name string, value net.IPMask, usage string) *net.IPMask
- func (f *FlagSet) IPMaskP(name, shorthand string, value net.IPMask, usage string) *net.IPMask
- func (f *FlagSet) IPMaskVar(p *net.IPMask, name string, value net.IPMask, usage string)
- func (f *FlagSet) IPMaskVarP(p *net.IPMask, name, shorthand string, value net.IPMask, usage string)
- func (f *FlagSet) IPNet(name string, value net.IPNet, usage string) *net.IPNet
- func (f *FlagSet) IPNetP(name, shorthand string, value net.IPNet, usage string) *net.IPNet
- func (f *FlagSet) IPNetSlice(name string, value []net.IPNet, usage string) *[]net.IPNet
- func (f *FlagSet) IPNetSliceP(name, shorthand string, value []net.IPNet, usage string) *[]net.IPNet
- func (f *FlagSet) IPNetSliceVar(p *[]net.IPNet, name string, value []net.IPNet, usage string)
- func (f *FlagSet) IPNetSliceVarP(p *[]net.IPNet, name, shorthand string, value []net.IPNet, usage string)
- func (f *FlagSet) IPNetVar(p *net.IPNet, name string, value net.IPNet, usage string)
- func (f *FlagSet) IPNetVarP(p *net.IPNet, name, shorthand string, value net.IPNet, usage string)
- func (f *FlagSet) IPP(name, shorthand string, value net.IP, usage string) *net.IP
- func (f *FlagSet) IPSlice(name string, value []net.IP, usage string) *[]net.IP
- func (f *FlagSet) IPSliceP(name, shorthand string, value []net.IP, usage string) *[]net.IP
- func (f *FlagSet) IPSliceVar(p *[]net.IP, name string, value []net.IP, usage string)
- func (f *FlagSet) IPSliceVarP(p *[]net.IP, name, shorthand string, value []net.IP, usage string)
- func (f *FlagSet) IPVar(p *net.IP, name string, value net.IP, usage string)
- func (f *FlagSet) IPVarP(p *net.IP, name, shorthand string, value net.IP, usage string)
- func (f *FlagSet) Init(name string, errorHandling ErrorHandling)
- func (f *FlagSet) Int(name string, value int, usage string) *int
- func (f *FlagSet) Int16(name string, value int16, usage string) *int16
- func (f *FlagSet) Int16P(name, shorthand string, value int16, usage string) *int16
- func (f *FlagSet) Int16Var(p *int16, name string, value int16, usage string)
- func (f *FlagSet) Int16VarP(p *int16, name, shorthand string, value int16, usage string)
- func (f *FlagSet) Int32(name string, value int32, usage string) *int32
- func (f *FlagSet) Int32P(name, shorthand string, value int32, usage string) *int32
- func (f *FlagSet) Int32Slice(name string, value []int32, usage string) *[]int32
- func (f *FlagSet) Int32SliceP(name, shorthand string, value []int32, usage string) *[]int32
- func (f *FlagSet) Int32SliceVar(p *[]int32, name string, value []int32, usage string)
- func (f *FlagSet) Int32SliceVarP(p *[]int32, name, shorthand string, value []int32, usage string)
- func (f *FlagSet) Int32Var(p *int32, name string, value int32, usage string)
- func (f *FlagSet) Int32VarP(p *int32, name, shorthand string, value int32, usage string)
- func (f *FlagSet) Int64(name string, value int64, usage string) *int64
- func (f *FlagSet) Int64P(name, shorthand string, value int64, usage string) *int64
- func (f *FlagSet) Int64Slice(name string, value []int64, usage string) *[]int64
- func (f *FlagSet) Int64SliceP(name, shorthand string, value []int64, usage string) *[]int64
- func (f *FlagSet) Int64SliceVar(p *[]int64, name string, value []int64, usage string)
- func (f *FlagSet) Int64SliceVarP(p *[]int64, name, shorthand string, value []int64, usage string)
- func (f *FlagSet) Int64Var(p *int64, name string, value int64, usage string)
- func (f *FlagSet) Int64VarP(p *int64, name, shorthand string, value int64, usage string)
- func (f *FlagSet) Int8(name string, value int8, usage string) *int8
- func (f *FlagSet) Int8P(name, shorthand string, value int8, usage string) *int8
- func (f *FlagSet) Int8Var(p *int8, name string, value int8, usage string)
- func (f *FlagSet) Int8VarP(p *int8, name, shorthand string, value int8, usage string)
- func (f *FlagSet) IntP(name, shorthand string, value int, usage string) *int
- func (f *FlagSet) IntSlice(name string, value []int, usage string) *[]int
- func (f *FlagSet) IntSliceP(name, shorthand string, value []int, usage string) *[]int
- func (f *FlagSet) IntSliceVar(p *[]int, name string, value []int, usage string)
- func (f *FlagSet) IntSliceVarP(p *[]int, name, shorthand string, value []int, usage string)
- func (f *FlagSet) IntVar(p *int, name string, value int, usage string)
- func (f *FlagSet) IntVarP(p *int, name, shorthand string, value int, usage string)
- func (f *FlagSet) Lookup(name string) *Flag
- func (f *FlagSet) MarkDeprecated(name string, usageMessage string) error
- func (f *FlagSet) MarkHidden(name string) error
- func (f *FlagSet) MarkShorthandDeprecated(name string, usageMessage string) error
- func (f *FlagSet) NArg() int
- func (f *FlagSet) NFlag() int
- func (f *FlagSet) Name() string
- func (f *FlagSet) Output() io.Writer
- func (f *FlagSet) Parse(arguments []string) error
- func (f *FlagSet) ParseAll(arguments []string, fn func(flag *Flag, value string) error) error
- func (f *FlagSet) Parsed() bool
- func (f *FlagSet) PrintDefaults()
- func (f *FlagSet) Set(name, value string) error
- func (f *FlagSet) SetAnnotation(name, key string, values []string) error
- func (f *FlagSet) SetInterspersed(interspersed bool)
- func (f *FlagSet) SetNormalizeFunc(n func(f *FlagSet, name string) NormalizedName)
- func (f *FlagSet) SetOutput(output io.Writer)
- func (f *FlagSet) ShorthandLookup(name string) *Flag
- func (f *FlagSet) String(name string, value string, usage string) *string
- func (f *FlagSet) StringArray(name string, value []string, usage string) *[]string
- func (f *FlagSet) StringArrayP(name, shorthand string, value []string, usage string) *[]string
- func (f *FlagSet) StringArrayVar(p *[]string, name string, value []string, usage string)
- func (f *FlagSet) StringArrayVarP(p *[]string, name, shorthand string, value []string, usage string)
- func (f *FlagSet) StringP(name, shorthand string, value string, usage string) *string
- func (f *FlagSet) StringSlice(name string, value []string, usage string) *[]string
- func (f *FlagSet) StringSliceP(name, shorthand string, value []string, usage string) *[]string
- func (f *FlagSet) StringSliceVar(p *[]string, name string, value []string, usage string)
- func (f *FlagSet) StringSliceVarP(p *[]string, name, shorthand string, value []string, usage string)
- func (f *FlagSet) StringToInt(name string, value map[string]int, usage string) *map[string]int
- func (f *FlagSet) StringToInt64(name string, value map[string]int64, usage string) *map[string]int64
- func (f *FlagSet) StringToInt64P(name, shorthand string, value map[string]int64, usage string) *map[string]int64
- func (f *FlagSet) StringToInt64Var(p *map[string]int64, name string, value map[string]int64, usage string)
- func (f *FlagSet) StringToInt64VarP(p *map[string]int64, name, shorthand string, value map[string]int64, ...)
- func (f *FlagSet) StringToIntP(name, shorthand string, value map[string]int, usage string) *map[string]int
- func (f *FlagSet) StringToIntVar(p *map[string]int, name string, value map[string]int, usage string)
- func (f *FlagSet) StringToIntVarP(p *map[string]int, name, shorthand string, value map[string]int, usage string)
- func (f *FlagSet) StringToString(name string, value map[string]string, usage string) *map[string]string
- func (f *FlagSet) StringToStringP(name, shorthand string, value map[string]string, usage string) *map[string]string
- func (f *FlagSet) StringToStringVar(p *map[string]string, name string, value map[string]string, usage string)
- func (f *FlagSet) StringToStringVarP(p *map[string]string, name, shorthand string, value map[string]string, ...)
- func (f *FlagSet) StringVar(p *string, name string, value string, usage string)
- func (f *FlagSet) StringVarP(p *string, name, shorthand string, value string, usage string)
- func (f *FlagSet) TextVar(p encoding.TextUnmarshaler, name string, value encoding.TextMarshaler, ...)
- func (f *FlagSet) TextVarP(p encoding.TextUnmarshaler, name, shorthand string, ...)
- func (f *FlagSet) Time(name string, value time.Time, formats []string, usage string) *time.Time
- func (f *FlagSet) TimeP(name, shorthand string, value time.Time, formats []string, usage string) *time.Time
- func (f *FlagSet) TimeVar(p *time.Time, name string, value time.Time, formats []string, usage string)
- func (f *FlagSet) TimeVarP(p *time.Time, name, shorthand string, value time.Time, formats []string, ...)
- func (f *FlagSet) Uint(name string, value uint, usage string) *uint
- func (f *FlagSet) Uint16(name string, value uint16, usage string) *uint16
- func (f *FlagSet) Uint16P(name, shorthand string, value uint16, usage string) *uint16
- func (f *FlagSet) Uint16Var(p *uint16, name string, value uint16, usage string)
- func (f *FlagSet) Uint16VarP(p *uint16, name, shorthand string, value uint16, usage string)
- func (f *FlagSet) Uint32(name string, value uint32, usage string) *uint32
- func (f *FlagSet) Uint32P(name, shorthand string, value uint32, usage string) *uint32
- func (f *FlagSet) Uint32Var(p *uint32, name string, value uint32, usage string)
- func (f *FlagSet) Uint32VarP(p *uint32, name, shorthand string, value uint32, usage string)
- func (f *FlagSet) Uint64(name string, value uint64, usage string) *uint64
- func (f *FlagSet) Uint64P(name, shorthand string, value uint64, usage string) *uint64
- func (f *FlagSet) Uint64Var(p *uint64, name string, value uint64, usage string)
- func (f *FlagSet) Uint64VarP(p *uint64, name, shorthand string, value uint64, usage string)
- func (f *FlagSet) Uint8(name string, value uint8, usage string) *uint8
- func (f *FlagSet) Uint8P(name, shorthand string, value uint8, usage string) *uint8
- func (f *FlagSet) Uint8Var(p *uint8, name string, value uint8, usage string)
- func (f *FlagSet) Uint8VarP(p *uint8, name, shorthand string, value uint8, usage string)
- func (f *FlagSet) UintP(name, shorthand string, value uint, usage string) *uint
- func (f *FlagSet) UintSlice(name string, value []uint, usage string) *[]uint
- func (f *FlagSet) UintSliceP(name, shorthand string, value []uint, usage string) *[]uint
- func (f *FlagSet) UintSliceVar(p *[]uint, name string, value []uint, usage string)
- func (f *FlagSet) UintSliceVarP(p *[]uint, name, shorthand string, value []uint, usage string)
- func (f *FlagSet) UintVar(p *uint, name string, value uint, usage string)
- func (f *FlagSet) UintVarP(p *uint, name, shorthand string, value uint, usage string)
- func (f *FlagSet) Var(value Value, name string, usage string)
- func (f *FlagSet) VarP(value Value, name, shorthand, usage string)
- func (f *FlagSet) VarPF(value Value, name, shorthand, usage string) *Flag
- func (f *FlagSet) Visit(fn func(*Flag))
- func (f *FlagSet) VisitAll(fn func(*Flag))
- type InvalidSyntaxError
- type InvalidValueError
- type NormalizedName
- type NotExistError
- type ParseErrorsAllowlist
- type ParseErrorsWhitelistdeprecated
- type SliceValue
- type Value
- type ValueRequiredError
Examples¶
Constants¶
This section is empty.
Variables¶
var CommandLine =NewFlagSet(os.Args[0],ExitOnError)CommandLine is the default set of command-line flags, parsed from os.Args.
var ErrHelp =errors.New("pflag: help requested")ErrHelp is the error returned if the flag -help is invoked but no such flag is defined.
var Usage = func() {fmt.Fprintf(os.Stderr, "Usage of %s:\n",os.Args[0])PrintDefaults()}
Usage prints to standard error a usage message documenting all defined command-line flags.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 theformat of the output and how to control it, see the documentation for PrintDefaults.
Functions¶
funcArg¶
Arg returns the i'th command-line argument. Arg(0) is the first remaining argumentafter flags have been processed.
funcBool¶
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.
funcBoolFunc¶added inv1.0.7
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 parsedon the command line.
funcBoolFuncP¶added inv1.0.7
BoolFuncP is like BoolFunc, but accepts a shorthand letter that can be used after a single dash.
funcBoolSlice¶
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.
funcBoolSliceP¶
BoolSliceP is like BoolSlice, but accepts a shorthand letter that can be used after a single dash.
funcBoolSliceVar¶
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.
funcBoolSliceVarP¶
BoolSliceVarP is like BoolSliceVar, but accepts a shorthand letter that can be used after a single dash.
funcBoolVar¶
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.
funcBoolVarP¶
BoolVarP is like BoolVar, but accepts a shorthand letter that can be used after a single dash.
funcBytesBase64¶added inv1.0.2
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.
funcBytesBase64P¶added inv1.0.2
BytesBase64P is like BytesBase64, but accepts a shorthand letter that can be used after a single dash.
funcBytesBase64Var¶added inv1.0.2
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.
funcBytesBase64VarP¶added inv1.0.2
BytesBase64VarP is like BytesBase64Var, but accepts a shorthand letter that can be used after a single dash.
funcBytesHex¶added inv1.0.1
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.
funcBytesHexP¶added inv1.0.1
BytesHexP is like BytesHex, but accepts a shorthand letter that can be used after a single dash.
funcBytesHexVar¶added inv1.0.1
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.
funcBytesHexVarP¶added inv1.0.1
BytesHexVarP is like BytesHexVar, but accepts a shorthand letter that can be used after a single dash.
funcCount¶
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
funcCountVar¶
CountVar like CountVar only the flag is placed on the CommandLine instead of a given flag set
funcDuration¶
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.
funcDurationP¶
DurationP is like Duration, but accepts a shorthand letter that can be used after a single dash.
funcDurationSlice¶added inv1.0.1
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.
funcDurationSliceP¶added inv1.0.1
DurationSliceP is like DurationSlice, but accepts a shorthand letter that can be used after a single dash.
funcDurationSliceVar¶added inv1.0.1
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.
funcDurationSliceVarP¶added inv1.0.1
func DurationSliceVarP(p *[]time.Duration, name, shorthandstring, value []time.Duration, usagestring)
DurationSliceVarP is like DurationSliceVar, but accepts a shorthand letter that can be used after a single dash.
funcDurationVar¶
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.
funcDurationVarP¶
DurationVarP is like DurationVar, but accepts a shorthand letter that can be used after a single dash.
funcFloat32¶
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.
funcFloat32P¶
Float32P is like Float32, but accepts a shorthand letter that can be used after a single dash.
funcFloat32Slice¶added inv1.0.5
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.
funcFloat32SliceP¶added inv1.0.5
Float32SliceP is like Float32Slice, but accepts a shorthand letter that can be used after a single dash.
funcFloat32SliceVar¶added inv1.0.5
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.
funcFloat32SliceVarP¶added inv1.0.5
Float32SliceVarP is like Float32SliceVar, but accepts a shorthand letter that can be used after a single dash.
funcFloat32Var¶
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.
funcFloat32VarP¶
Float32VarP is like Float32Var, but accepts a shorthand letter that can be used after a single dash.
funcFloat64¶
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.
funcFloat64P¶
Float64P is like Float64, but accepts a shorthand letter that can be used after a single dash.
funcFloat64Slice¶added inv1.0.5
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.
funcFloat64SliceP¶added inv1.0.5
Float64SliceP is like Float64Slice, but accepts a shorthand letter that can be used after a single dash.
funcFloat64SliceVar¶added inv1.0.5
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.
funcFloat64SliceVarP¶added inv1.0.5
Float64SliceVarP is like Float64SliceVar, but accepts a shorthand letter that can be used after a single dash.
funcFloat64Var¶
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.
funcFloat64VarP¶
Float64VarP is like Float64Var, but accepts a shorthand letter that can be used after a single dash.
funcFunc¶added inv1.0.7
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) isparsed on the command line, with "{value}" as an argument.
funcFuncP¶added inv1.0.7
FuncP is like Func, but accepts a shorthand letter that can be used after a single dash.
funcIP¶
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.
funcIPMask¶
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.
funcIPMaskP¶
IPMaskP is like IP, but accepts a shorthand letter that can be used after a single dash.
funcIPMaskVar¶
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.
funcIPMaskVarP¶
IPMaskVarP is like IPMaskVar, but accepts a shorthand letter that can be used after a single dash.
funcIPNet¶
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.
funcIPNetP¶
IPNetP is like IPNet, but accepts a shorthand letter that can be used after a single dash.
funcIPNetSlice¶added inv1.0.6
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.
funcIPNetSliceP¶added inv1.0.6
IPNetSliceP is like IPNetSlice, but accepts a shorthand letter that can be used after a single dash.
funcIPNetSliceVar¶added inv1.0.6
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.
funcIPNetSliceVarP¶added inv1.0.6
IPNetSliceVarP is like IPNetSliceVar, but accepts a shorthand letter that can be used after a single dash.
funcIPNetVar¶
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.
funcIPNetVarP¶
IPNetVarP is like IPNetVar, but accepts a shorthand letter that can be used after a single dash.
funcIPSlice¶
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.
funcIPSliceP¶
IPSliceP is like IPSlice, but accepts a shorthand letter that can be used after a single dash.
funcIPSliceVar¶
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.
funcIPSliceVarP¶
IPSliceVarP is like IPSliceVar, but accepts a shorthand letter that can be used after a single dash.
funcIPVar¶
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.
funcIPVarP¶
IPVarP is like IPVar, but accepts a shorthand letter that can be used after a single dash.
funcInt¶
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.
funcInt16¶added inv1.0.1
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.
funcInt16P¶added inv1.0.1
Int16P is like Int16, but accepts a shorthand letter that can be used after a single dash.
funcInt16Var¶added inv1.0.1
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.
funcInt16VarP¶added inv1.0.1
Int16VarP is like Int16Var, but accepts a shorthand letter that can be used after a single dash.
funcInt32¶
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.
funcInt32P¶
Int32P is like Int32, but accepts a shorthand letter that can be used after a single dash.
funcInt32Slice¶added inv1.0.5
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.
funcInt32SliceP¶added inv1.0.5
Int32SliceP is like Int32Slice, but accepts a shorthand letter that can be used after a single dash.
funcInt32SliceVar¶added inv1.0.5
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.
funcInt32SliceVarP¶added inv1.0.5
Int32SliceVarP is like Int32SliceVar, but accepts a shorthand letter that can be used after a single dash.
funcInt32Var¶
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.
funcInt32VarP¶
Int32VarP is like Int32Var, but accepts a shorthand letter that can be used after a single dash.
funcInt64¶
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.
funcInt64P¶
Int64P is like Int64, but accepts a shorthand letter that can be used after a single dash.
funcInt64Slice¶added inv1.0.5
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.
funcInt64SliceP¶added inv1.0.5
Int64SliceP is like Int64Slice, but accepts a shorthand letter that can be used after a single dash.
funcInt64SliceVar¶added inv1.0.5
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.
funcInt64SliceVarP¶added inv1.0.5
Int64SliceVarP is like Int64SliceVar, but accepts a shorthand letter that can be used after a single dash.
funcInt64Var¶
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.
funcInt64VarP¶
Int64VarP is like Int64Var, but accepts a shorthand letter that can be used after a single dash.
funcInt8¶
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.
funcInt8Var¶
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.
funcInt8VarP¶
Int8VarP is like Int8Var, but accepts a shorthand letter that can be used after a single dash.
funcIntSlice¶
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.
funcIntSliceP¶
IntSliceP is like IntSlice, but accepts a shorthand letter that can be used after a single dash.
funcIntSliceVar¶
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.
funcIntSliceVarP¶
IntSliceVarP is like IntSliceVar, but accepts a shorthand letter that can be used after a single dash.
funcIntVar¶
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.
funcIntVarP¶
IntVarP is like IntVar, but accepts a shorthand letter that can be used after a single dash.
funcParse¶
func Parse()
Parse parses the command-line flags from os.Args[1:]. Must be calledafter all flags are defined and before flags are accessed by the program.
funcParseAll¶
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 aredefined and before flags are accessed by the program.
funcParseIPv4Mask¶
ParseIPv4Mask written in IP form (e.g. 255.255.255.0).This function should really belong to the net package.
funcParseSkippedFlags¶added inv1.0.7
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)`
funcPrintDefaults¶
func PrintDefaults()
PrintDefaults prints to standard error the default values of all defined command-line flags.
funcSetInterspersed¶
func SetInterspersed(interspersedbool)
SetInterspersed sets whether to support interspersed option/non-option arguments.
funcString¶
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.
funcStringArray¶
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.
funcStringArrayP¶
StringArrayP is like StringArray, but accepts a shorthand letter that can be used after a single dash.
funcStringArrayVar¶
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.
funcStringArrayVarP¶
StringArrayVarP is like StringArrayVar, but accepts a shorthand letter that can be used after a single dash.
funcStringP¶
StringP is like String, but accepts a shorthand letter that can be used after a single dash.
funcStringSlice¶
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"}funcStringSliceP¶
StringSliceP is like StringSlice, but accepts a shorthand letter that can be used after a single dash.
funcStringSliceVar¶
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"}funcStringSliceVarP¶
StringSliceVarP is like StringSliceVar, but accepts a shorthand letter that can be used after a single dash.
funcStringToInt¶added inv1.0.3
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
funcStringToInt64¶added inv1.0.5
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
funcStringToInt64P¶added inv1.0.5
StringToInt64P is like StringToInt64, but accepts a shorthand letter that can be used after a single dash.
funcStringToInt64Var¶added inv1.0.5
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
funcStringToInt64VarP¶added inv1.0.5
func StringToInt64VarP(p *map[string]int64, name, shorthandstring, value map[string]int64, usagestring)
StringToInt64VarP is like StringToInt64Var, but accepts a shorthand letter that can be used after a single dash.
funcStringToIntP¶added inv1.0.3
StringToIntP is like StringToInt, but accepts a shorthand letter that can be used after a single dash.
funcStringToIntVar¶added inv1.0.3
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
funcStringToIntVarP¶added inv1.0.3
StringToIntVarP is like StringToIntVar, but accepts a shorthand letter that can be used after a single dash.
funcStringToString¶added inv1.0.3
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
funcStringToStringP¶added inv1.0.3
func StringToStringP(name, shorthandstring, value map[string]string, usagestring) *map[string]string
StringToStringP is like StringToString, but accepts a shorthand letter that can be used after a single dash.
funcStringToStringVar¶added inv1.0.3
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
funcStringToStringVarP¶added inv1.0.3
func StringToStringVarP(p *map[string]string, name, shorthandstring, value map[string]string, usagestring)
StringToStringVarP is like StringToStringVar, but accepts a shorthand letter that can be used after a single dash.
funcStringVar¶
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.
funcStringVarP¶
StringVarP is like StringVar, but accepts a shorthand letter that can be used after a single dash.
funcTextVar¶added inv1.0.7
func TextVar(pencoding.TextUnmarshaler, namestring, valueencoding.TextMarshaler, usagestring)
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.
funcTextVarP¶added inv1.0.7
func TextVarP(pencoding.TextUnmarshaler, name, shorthandstring, valueencoding.TextMarshaler, usagestring)
TextVarP is like TextVar, but accepts a shorthand letter that can be used after a single dash.
funcTime¶added inv1.0.7
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.
funcTimeP¶added inv1.0.7
TimeP is like Time, but accepts a shorthand letter that can be used after a single dash.
funcTimeVar¶added inv1.0.7
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.
funcTimeVarP¶added inv1.0.7
TimeVarP is like TimeVar, but accepts a shorthand letter that can be used after a single dash.
funcUint¶
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.
funcUint16¶
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.
funcUint16P¶
Uint16P is like Uint16, but accepts a shorthand letter that can be used after a single dash.
funcUint16Var¶
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.
funcUint16VarP¶
Uint16VarP is like Uint16Var, but accepts a shorthand letter that can be used after a single dash.
funcUint32¶
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.
funcUint32P¶
Uint32P is like Uint32, but accepts a shorthand letter that can be used after a single dash.
funcUint32Var¶
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.
funcUint32VarP¶
Uint32VarP is like Uint32Var, but accepts a shorthand letter that can be used after a single dash.
funcUint64¶
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.
funcUint64P¶
Uint64P is like Uint64, but accepts a shorthand letter that can be used after a single dash.
funcUint64Var¶
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.
funcUint64VarP¶
Uint64VarP is like Uint64Var, but accepts a shorthand letter that can be used after a single dash.
funcUint8¶
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.
funcUint8P¶
Uint8P is like Uint8, but accepts a shorthand letter that can be used after a single dash.
funcUint8Var¶
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.
funcUint8VarP¶
Uint8VarP is like Uint8Var, but accepts a shorthand letter that can be used after a single dash.
funcUintSlice¶
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.
funcUintSliceP¶
UintSliceP is like UintSlice, but accepts a shorthand letter that can be used after a single dash.
funcUintSliceVar¶
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.
funcUintSliceVarP¶
UintSliceVarP is like the UintSliceVar, but accepts a shorthand letter that can be used after a single dash.
funcUintVar¶
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.
funcUintVarP¶
UintVarP is like UintVar, but accepts a shorthand letter that can be used after a single dash.
funcUnquoteUsage¶
UnquoteUsage extracts a back-quoted name from the usagestring 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 thetype of the flag's value, or the empty string if the flag is boolean.
funcVar¶
Var defines a flag with the specified name and usage string. The type andvalue of the flag are represented by the first argument, of type Value, whichtypically holds a user-defined implementation of Value. For instance, thecaller could create a flag that turns a comma-separated string into a sliceof strings by giving the slice the methods of Value; in particular, Set woulddecompose the comma-separated string into the slice.
Types¶
typeErrorHandling¶
type ErrorHandlingint
ErrorHandling defines how to handle flag parsing errors.
const (// ContinueOnError will return an err from Parse() if an error is foundContinueOnErrorErrorHandling =iota// ExitOnError will call os.Exit(2) if an error is found when parsingExitOnError// PanicOnError will panic() if an error is found when parsing flagsPanicOnError)
typeFlag¶
type Flag struct {Namestring// name as it appears on command lineShorthandstring// one-letter abbreviated flagUsagestring// help messageValueValue// value as setDefValuestring// default value (as text); for usage messageChangedbool// If the user set the value (or if left to default)NoOptDefValstring// default value (as text); if the flag is on the command line without any optionsDeprecatedstring// If this flag is deprecated, this string is the new or now thing to useHiddenbool// used by cobra.Command to allow flags to be hidden from help/usage textShorthandDeprecatedstring// If the shorthand of this flag is deprecated, this string is the new or now thing to useAnnotations map[string][]string// used by cobra.Command bash autocomple code}A Flag represents the state of a flag.
funcLookup¶
Lookup returns the Flag structure of the named command-line flag,returning nil if none exists.
funcPFlagFromGoFlag¶
PFlagFromGoFlag will return a *pflag.Flag given a *flag.FlagIf the *flag.Flag.Name was a single character (ex: `v`) it will be accessibleiwith both `-v` and `--v` in flags. If the golang flag was more than a singlecharacter (ex: `verbose`) it will only be accessible via `--verbose`
funcShorthandLookup¶
ShorthandLookup returns the Flag structure of the short handed flag,returning nil if none exists.
Example¶
package mainimport ("fmt""github.com/spf13/pflag")func main() {name := "verbose"short := name[:1]pflag.BoolP(name, short, false, "verbose output")// len(short) must be == 1flag := pflag.ShorthandLookup(short)fmt.Println(flag.Name)}typeFlagSet¶
type FlagSet struct {// Usage is the function called when an error occurs while parsing flags.// The field is a function (not a method) that may be changed to point to// a custom error handler.Usage func()// SortFlags is used to indicate, if user wants to have sorted flags in// help/usage messages.SortFlagsbool// ParseErrorsAllowlist is used to configure an allowlist of errorsParseErrorsAllowlistParseErrorsAllowlist// ParseErrorsAllowlist is used to configure an allowlist of errors.//// Deprecated: use [FlagSet.ParseErrorsAllowlist] instead. This field will be removed in a future release.ParseErrorsWhitelistParseErrorsAllowlist// contains filtered or unexported fields}A FlagSet represents a set of defined flags.
funcNewFlagSet¶
func NewFlagSet(namestring, errorHandlingErrorHandling) *FlagSet
NewFlagSet returns a new, empty flag set with the specified name,error handling property and SortFlags set to true.
func (*FlagSet)AddFlagSet¶
AddFlagSet adds one FlagSet to another. If a flag is already present in fthe flag from newSet will be ignored.
func (*FlagSet)AddGoFlagSet¶
AddGoFlagSet will add the given *flag.FlagSet to the pflag.FlagSet
func (*FlagSet)Arg¶
Arg returns the i'th argument. Arg(0) is the first remaining argumentafter flags have been processed.
func (*FlagSet)ArgsLenAtDash¶
ArgsLenAtDash will return the length of f.Args at the moment when a -- wasfound during arg parsing. This allows your program to know which args werebefore the -- and which came after.
func (*FlagSet)Bool¶
Bool defines a bool flag with specified name, default value, and usage string.The return value is the address of a bool variable that stores the value of the flag.
func (*FlagSet)BoolFunc¶added inv1.0.7
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 parsedon the command line.
func (*FlagSet)BoolFuncP¶added inv1.0.7
BoolFuncP is like BoolFunc, but accepts a shorthand letter that can be used after a single dash.
func (*FlagSet)BoolP¶
BoolP is like Bool, but accepts a shorthand letter that can be used after a single dash.
func (*FlagSet)BoolSlice¶
BoolSlice defines a []bool flag with specified name, default value, and usage string.The return value is the address of a []bool variable that stores the value of the flag.
func (*FlagSet)BoolSliceP¶
BoolSliceP is like BoolSlice, but accepts a shorthand letter that can be used after a single dash.
func (*FlagSet)BoolSliceVar¶
BoolSliceVar defines a boolSlice flag with specified name, default value, and usage string.The argument p points to a []bool variable in which to store the value of the flag.
func (*FlagSet)BoolSliceVarP¶
BoolSliceVarP is like BoolSliceVar, but accepts a shorthand letter that can be used after a single dash.
func (*FlagSet)BoolVar¶
BoolVar defines a bool flag with specified name, default value, and usage string.The argument p points to a bool variable in which to store the value of the flag.
func (*FlagSet)BoolVarP¶
BoolVarP is like BoolVar, but accepts a shorthand letter that can be used after a single dash.
func (*FlagSet)BytesBase64¶added inv1.0.2
BytesBase64 defines an []byte flag with specified name, default value, and usage string.The return value is the address of an []byte variable that stores the value of the flag.
func (*FlagSet)BytesBase64P¶added inv1.0.2
BytesBase64P is like BytesBase64, but accepts a shorthand letter that can be used after a single dash.
func (*FlagSet)BytesBase64Var¶added inv1.0.2
BytesBase64Var defines an []byte flag with specified name, default value, and usage string.The argument p points to an []byte variable in which to store the value of the flag.
func (*FlagSet)BytesBase64VarP¶added inv1.0.2
BytesBase64VarP is like BytesBase64Var, but accepts a shorthand letter that can be used after a single dash.
func (*FlagSet)BytesHex¶added inv1.0.1
BytesHex defines an []byte flag with specified name, default value, and usage string.The return value is the address of an []byte variable that stores the value of the flag.
func (*FlagSet)BytesHexP¶added inv1.0.1
BytesHexP is like BytesHex, but accepts a shorthand letter that can be used after a single dash.
func (*FlagSet)BytesHexVar¶added inv1.0.1
BytesHexVar defines an []byte flag with specified name, default value, and usage string.The argument p points to an []byte variable in which to store the value of the flag.
func (*FlagSet)BytesHexVarP¶added inv1.0.1
BytesHexVarP is like BytesHexVar, but accepts a shorthand letter that can be used after a single dash.
func (*FlagSet)Changed¶
Changed returns true if the flag was explicitly set during Parse() and falseotherwise
func (*FlagSet)CopyToGoFlagSet¶added inv1.0.8
CopyToGoFlagSet will add all current flags to the given Go flag set.Deprecation remarks get copied into the usage description.Whenever possible, a flag gets added for which Go flags showsa proper type in the help message.
func (*FlagSet)Count¶
Count defines a count flag with specified name, default value, and usage string.The return value is the address of an int variable that stores the value of the flag.A count flag will add 1 to its value every time it is found on the command line
func (*FlagSet)CountVar¶
CountVar defines a count flag with specified name, default value, and usage string.The argument p points to an int variable in which to store the value of the flag.A count flag will add 1 to its value every time it is found on the command line
func (*FlagSet)Duration¶
Duration defines a time.Duration flag with specified name, default value, and usage string.The return value is the address of a time.Duration variable that stores the value of the flag.
func (*FlagSet)DurationP¶
DurationP is like Duration, but accepts a shorthand letter that can be used after a single dash.
func (*FlagSet)DurationSlice¶added inv1.0.1
DurationSlice defines a []time.Duration flag with specified name, default value, and usage string.The return value is the address of a []time.Duration variable that stores the value of the flag.
func (*FlagSet)DurationSliceP¶added inv1.0.1
func (f *FlagSet) DurationSliceP(name, shorthandstring, value []time.Duration, usagestring) *[]time.Duration
DurationSliceP is like DurationSlice, but accepts a shorthand letter that can be used after a single dash.
func (*FlagSet)DurationSliceVar¶added inv1.0.1
func (f *FlagSet) DurationSliceVar(p *[]time.Duration, namestring, value []time.Duration, usagestring)
DurationSliceVar defines a durationSlice flag with specified name, default value, and usage string.The argument p points to a []time.Duration variable in which to store the value of the flag.
func (*FlagSet)DurationSliceVarP¶added inv1.0.1
func (f *FlagSet) DurationSliceVarP(p *[]time.Duration, name, shorthandstring, value []time.Duration, usagestring)
DurationSliceVarP is like DurationSliceVar, but accepts a shorthand letter that can be used after a single dash.
func (*FlagSet)DurationVar¶
DurationVar defines a time.Duration flag with specified name, default value, and usage string.The argument p points to a time.Duration variable in which to store the value of the flag.
func (*FlagSet)DurationVarP¶
func (f *FlagSet) DurationVarP(p *time.Duration, name, shorthandstring, valuetime.Duration, usagestring)
DurationVarP is like DurationVar, but accepts a shorthand letter that can be used after a single dash.
func (*FlagSet)FlagUsages¶
FlagUsages returns a string containing the usage information for all flags inthe FlagSet
func (*FlagSet)FlagUsagesWrapped¶
FlagUsagesWrapped returns a string containing the usage informationfor all flags in the FlagSet. Wrapped to `cols` columns (0 for nowrapping)
func (*FlagSet)Float32¶
Float32 defines a float32 flag with specified name, default value, and usage string.The return value is the address of a float32 variable that stores the value of the flag.
func (*FlagSet)Float32P¶
Float32P is like Float32, but accepts a shorthand letter that can be used after a single dash.
func (*FlagSet)Float32Slice¶added inv1.0.5
Float32Slice defines a []float32 flag with specified name, default value, and usage string.The return value is the address of a []float32 variable that stores the value of the flag.
func (*FlagSet)Float32SliceP¶added inv1.0.5
Float32SliceP is like Float32Slice, but accepts a shorthand letter that can be used after a single dash.
func (*FlagSet)Float32SliceVar¶added inv1.0.5
Float32SliceVar defines a float32Slice flag with specified name, default value, and usage string.The argument p points to a []float32 variable in which to store the value of the flag.
func (*FlagSet)Float32SliceVarP¶added inv1.0.5
func (f *FlagSet) Float32SliceVarP(p *[]float32, name, shorthandstring, value []float32, usagestring)
Float32SliceVarP is like Float32SliceVar, but accepts a shorthand letter that can be used after a single dash.
func (*FlagSet)Float32Var¶
Float32Var defines a float32 flag with specified name, default value, and usage string.The argument p points to a float32 variable in which to store the value of the flag.
func (*FlagSet)Float32VarP¶
Float32VarP is like Float32Var, but accepts a shorthand letter that can be used after a single dash.
func (*FlagSet)Float64¶
Float64 defines a float64 flag with specified name, default value, and usage string.The return value is the address of a float64 variable that stores the value of the flag.
func (*FlagSet)Float64P¶
Float64P is like Float64, but accepts a shorthand letter that can be used after a single dash.
func (*FlagSet)Float64Slice¶added inv1.0.5
Float64Slice defines a []float64 flag with specified name, default value, and usage string.The return value is the address of a []float64 variable that stores the value of the flag.
func (*FlagSet)Float64SliceP¶added inv1.0.5
Float64SliceP is like Float64Slice, but accepts a shorthand letter that can be used after a single dash.
func (*FlagSet)Float64SliceVar¶added inv1.0.5
Float64SliceVar defines a float64Slice flag with specified name, default value, and usage string.The argument p points to a []float64 variable in which to store the value of the flag.
func (*FlagSet)Float64SliceVarP¶added inv1.0.5
func (f *FlagSet) Float64SliceVarP(p *[]float64, name, shorthandstring, value []float64, usagestring)
Float64SliceVarP is like Float64SliceVar, but accepts a shorthand letter that can be used after a single dash.
func (*FlagSet)Float64Var¶
Float64Var defines a float64 flag with specified name, default value, and usage string.The argument p points to a float64 variable in which to store the value of the flag.
func (*FlagSet)Float64VarP¶
Float64VarP is like Float64Var, but accepts a shorthand letter that can be used after a single dash.
func (*FlagSet)Func¶added inv1.0.7
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) isparsed on the command line, with "{value}" as an argument.
func (*FlagSet)FuncP¶added inv1.0.7
FuncP is like Func, but accepts a shorthand letter that can be used after a single dash.
func (*FlagSet)GetBoolSlice¶
GetBoolSlice returns the []bool value of a flag with the given name.
func (*FlagSet)GetBytesBase64¶added inv1.0.2
GetBytesBase64 return the []byte value of a flag with the given name
func (*FlagSet)GetBytesHex¶added inv1.0.1
GetBytesHex return the []byte value of a flag with the given name
func (*FlagSet)GetDuration¶
GetDuration return the duration value of a flag with the given name
func (*FlagSet)GetDurationSlice¶added inv1.0.1
GetDurationSlice returns the []time.Duration value of a flag with the given name
func (*FlagSet)GetFloat32¶
GetFloat32 return the float32 value of a flag with the given name
func (*FlagSet)GetFloat32Slice¶added inv1.0.5
GetFloat32Slice return the []float32 value of a flag with the given name
func (*FlagSet)GetFloat64¶
GetFloat64 return the float64 value of a flag with the given name
func (*FlagSet)GetFloat64Slice¶added inv1.0.5
GetFloat64Slice return the []float64 value of a flag with the given name
func (*FlagSet)GetIPNetSlice¶added inv1.0.6
GetIPNetSlice returns the []net.IPNet value of a flag with the given name
func (*FlagSet)GetIPSlice¶
GetIPSlice returns the []net.IP value of a flag with the given name
func (*FlagSet)GetIPv4Mask¶
GetIPv4Mask return the net.IPv4Mask value of a flag with the given name
func (*FlagSet)GetInt16¶added inv1.0.1
GetInt16 returns the int16 value of a flag with the given name
func (*FlagSet)GetInt32Slice¶added inv1.0.5
GetInt32Slice return the []int32 value of a flag with the given name
func (*FlagSet)GetInt64Slice¶added inv1.0.5
GetInt64Slice return the []int64 value of a flag with the given name
func (*FlagSet)GetIntSlice¶
GetIntSlice return the []int value of a flag with the given name
func (*FlagSet)GetNormalizeFunc¶
func (f *FlagSet) GetNormalizeFunc() func(f *FlagSet, namestring)NormalizedName
GetNormalizeFunc returns the previously set NormalizeFunc of a function whichdoes no translation, if not set previously.
func (*FlagSet)GetStringArray¶
GetStringArray return the []string value of a flag with the given name
func (*FlagSet)GetStringSlice¶
GetStringSlice return the []string value of a flag with the given name
func (*FlagSet)GetStringToInt¶added inv1.0.3
GetStringToInt return the map[string]int value of a flag with the given name
func (*FlagSet)GetStringToInt64¶added inv1.0.5
GetStringToInt64 return the map[string]int64 value of a flag with the given name
func (*FlagSet)GetStringToString¶added inv1.0.3
GetStringToString return the map[string]string value of a flag with the given name
func (*FlagSet)GetText¶added inv1.0.7
func (f *FlagSet) GetText(namestring, outencoding.TextUnmarshaler)error
GetText set out, which implements encoding.UnmarshalText, to the value of a flag with given name
func (*FlagSet)GetUintSlice¶
GetUintSlice returns the []uint value of a flag with the given name.
func (*FlagSet)HasAvailableFlags¶
HasAvailableFlags returns a bool to indicate if the FlagSet has any flagsthat are not hidden.
func (*FlagSet)IP¶
IP defines an net.IP flag with specified name, default value, and usage string.The return value is the address of an net.IP variable that stores the value of the flag.
func (*FlagSet)IPMask¶
IPMask defines an net.IPMask flag with specified name, default value, and usage string.The return value is the address of an net.IPMask variable that stores the value of the flag.
func (*FlagSet)IPMaskP¶
IPMaskP is like IPMask, but accepts a shorthand letter that can be used after a single dash.
func (*FlagSet)IPMaskVar¶
IPMaskVar defines an net.IPMask flag with specified name, default value, and usage string.The argument p points to an net.IPMask variable in which to store the value of the flag.
func (*FlagSet)IPMaskVarP¶
IPMaskVarP is like IPMaskVar, but accepts a shorthand letter that can be used after a single dash.
func (*FlagSet)IPNet¶
IPNet defines an net.IPNet flag with specified name, default value, and usage string.The return value is the address of an net.IPNet variable that stores the value of the flag.
func (*FlagSet)IPNetP¶
IPNetP is like IPNet, but accepts a shorthand letter that can be used after a single dash.
func (*FlagSet)IPNetSlice¶added inv1.0.6
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.
func (*FlagSet)IPNetSliceP¶added inv1.0.6
IPNetSliceP is like IPNetSlice, but accepts a shorthand letter that can be used after a single dash.
func (*FlagSet)IPNetSliceVar¶added inv1.0.6
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.
func (*FlagSet)IPNetSliceVarP¶added inv1.0.6
func (f *FlagSet) IPNetSliceVarP(p *[]net.IPNet, name, shorthandstring, value []net.IPNet, usagestring)
IPNetSliceVarP is like IPNetSliceVar, but accepts a shorthand letter that can be used after a single dash.
func (*FlagSet)IPNetVar¶
IPNetVar defines an net.IPNet flag with specified name, default value, and usage string.The argument p points to an net.IPNet variable in which to store the value of the flag.
func (*FlagSet)IPNetVarP¶
IPNetVarP is like IPNetVar, but accepts a shorthand letter that can be used after a single dash.
func (*FlagSet)IPP¶
IPP is like IP, but accepts a shorthand letter that can be used after a single dash.
func (*FlagSet)IPSlice¶
IPSlice defines a []net.IP flag with specified name, default value, and usage string.The return value is the address of a []net.IP variable that stores the value of that flag.
func (*FlagSet)IPSliceP¶
IPSliceP is like IPSlice, but accepts a shorthand letter that can be used after a single dash.
func (*FlagSet)IPSliceVar¶
IPSliceVar defines a ipSlice flag with specified name, default value, and usage string.The argument p points to a []net.IP variable in which to store the value of the flag.
func (*FlagSet)IPSliceVarP¶
IPSliceVarP is like IPSliceVar, but accepts a shorthand letter that can be used after a single dash.
func (*FlagSet)IPVar¶
IPVar defines an net.IP flag with specified name, default value, and usage string.The argument p points to an net.IP variable in which to store the value of the flag.
func (*FlagSet)IPVarP¶
IPVarP is like IPVar, but accepts a shorthand letter that can be used after a single dash.
func (*FlagSet)Init¶
func (f *FlagSet) Init(namestring, errorHandlingErrorHandling)
Init sets the name and error handling property for a flag set.By default, the zero FlagSet uses an empty name and theContinueOnError error handling policy.
func (*FlagSet)Int¶
Int defines an int flag with specified name, default value, and usage string.The return value is the address of an int variable that stores the value of the flag.
func (*FlagSet)Int16¶added inv1.0.1
Int16 defines an int16 flag with specified name, default value, and usage string.The return value is the address of an int16 variable that stores the value of the flag.
func (*FlagSet)Int16P¶added inv1.0.1
Int16P is like Int16, but accepts a shorthand letter that can be used after a single dash.
func (*FlagSet)Int16Var¶added inv1.0.1
Int16Var defines an int16 flag with specified name, default value, and usage string.The argument p points to an int16 variable in which to store the value of the flag.
func (*FlagSet)Int16VarP¶added inv1.0.1
Int16VarP is like Int16Var, but accepts a shorthand letter that can be used after a single dash.
func (*FlagSet)Int32¶
Int32 defines an int32 flag with specified name, default value, and usage string.The return value is the address of an int32 variable that stores the value of the flag.
func (*FlagSet)Int32P¶
Int32P is like Int32, but accepts a shorthand letter that can be used after a single dash.
func (*FlagSet)Int32Slice¶added inv1.0.5
Int32Slice defines a []int32 flag with specified name, default value, and usage string.The return value is the address of a []int32 variable that stores the value of the flag.
func (*FlagSet)Int32SliceP¶added inv1.0.5
Int32SliceP is like Int32Slice, but accepts a shorthand letter that can be used after a single dash.
func (*FlagSet)Int32SliceVar¶added inv1.0.5
Int32SliceVar defines a int32Slice flag with specified name, default value, and usage string.The argument p points to a []int32 variable in which to store the value of the flag.
func (*FlagSet)Int32SliceVarP¶added inv1.0.5
Int32SliceVarP is like Int32SliceVar, but accepts a shorthand letter that can be used after a single dash.
func (*FlagSet)Int32Var¶
Int32Var defines an int32 flag with specified name, default value, and usage string.The argument p points to an int32 variable in which to store the value of the flag.
func (*FlagSet)Int32VarP¶
Int32VarP is like Int32Var, but accepts a shorthand letter that can be used after a single dash.
func (*FlagSet)Int64¶
Int64 defines an int64 flag with specified name, default value, and usage string.The return value is the address of an int64 variable that stores the value of the flag.
func (*FlagSet)Int64P¶
Int64P is like Int64, but accepts a shorthand letter that can be used after a single dash.
func (*FlagSet)Int64Slice¶added inv1.0.5
Int64Slice defines a []int64 flag with specified name, default value, and usage string.The return value is the address of a []int64 variable that stores the value of the flag.
func (*FlagSet)Int64SliceP¶added inv1.0.5
Int64SliceP is like Int64Slice, but accepts a shorthand letter that can be used after a single dash.
func (*FlagSet)Int64SliceVar¶added inv1.0.5
Int64SliceVar defines a int64Slice flag with specified name, default value, and usage string.The argument p points to a []int64 variable in which to store the value of the flag.
func (*FlagSet)Int64SliceVarP¶added inv1.0.5
Int64SliceVarP is like Int64SliceVar, but accepts a shorthand letter that can be used after a single dash.
func (*FlagSet)Int64Var¶
Int64Var defines an int64 flag with specified name, default value, and usage string.The argument p points to an int64 variable in which to store the value of the flag.
func (*FlagSet)Int64VarP¶
Int64VarP is like Int64Var, but accepts a shorthand letter that can be used after a single dash.
func (*FlagSet)Int8¶
Int8 defines an int8 flag with specified name, default value, and usage string.The return value is the address of an int8 variable that stores the value of the flag.
func (*FlagSet)Int8P¶
Int8P is like Int8, but accepts a shorthand letter that can be used after a single dash.
func (*FlagSet)Int8Var¶
Int8Var defines an int8 flag with specified name, default value, and usage string.The argument p points to an int8 variable in which to store the value of the flag.
func (*FlagSet)Int8VarP¶
Int8VarP is like Int8Var, but accepts a shorthand letter that can be used after a single dash.
func (*FlagSet)IntP¶
IntP is like Int, but accepts a shorthand letter that can be used after a single dash.
func (*FlagSet)IntSlice¶
IntSlice defines a []int flag with specified name, default value, and usage string.The return value is the address of a []int variable that stores the value of the flag.
func (*FlagSet)IntSliceP¶
IntSliceP is like IntSlice, but accepts a shorthand letter that can be used after a single dash.
func (*FlagSet)IntSliceVar¶
IntSliceVar defines a intSlice flag with specified name, default value, and usage string.The argument p points to a []int variable in which to store the value of the flag.
func (*FlagSet)IntSliceVarP¶
IntSliceVarP is like IntSliceVar, but accepts a shorthand letter that can be used after a single dash.
func (*FlagSet)IntVar¶
IntVar defines an int flag with specified name, default value, and usage string.The argument p points to an int variable in which to store the value of the flag.
func (*FlagSet)IntVarP¶
IntVarP is like IntVar, but accepts a shorthand letter that can be used after a single dash.
func (*FlagSet)Lookup¶
Lookup returns the Flag structure of the named flag, returning nil if none exists.
func (*FlagSet)MarkDeprecated¶
MarkDeprecated indicated that a flag is deprecated in your program. It willcontinue to function but will not show up in help or usage messages. Usingthis flag will also print the given usageMessage.
func (*FlagSet)MarkHidden¶
MarkHidden sets a flag to 'hidden' in your program. It will continue tofunction but will not show up in help or usage messages.
func (*FlagSet)MarkShorthandDeprecated¶
MarkShorthandDeprecated will mark the shorthand of a flag deprecated in yourprogram. It will continue to function but will not show up in help or usagemessages. Using this flag will also print the given usageMessage.
func (*FlagSet)Output¶added inv1.0.6
Output returns the destination for usage and error messages. os.Stderr is returned ifoutput was not set or was set to nil.
func (*FlagSet)Parse¶
Parse parses flag definitions from the argument list, which should notinclude the command name. Must be called after all flags in the FlagSetare defined and before flags are accessed by the program.The return value will be ErrHelp if -help was set but not defined.
func (*FlagSet)ParseAll¶
ParseAll parses flag definitions from the argument list, which should notinclude the command name. The arguments for fn are flag and value. Must becalled after all flags in the FlagSet are defined and before flags areaccessed by the program. The return value will be ErrHelp if -help was setbut not defined.
func (*FlagSet)PrintDefaults¶
func (f *FlagSet) PrintDefaults()
PrintDefaults prints, to standard error unless configuredotherwise, the default values of all defined flags in the set.
func (*FlagSet)SetAnnotation¶
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 additionalbash completion information.
func (*FlagSet)SetInterspersed¶
SetInterspersed sets whether to support interspersed option/non-option arguments.
func (*FlagSet)SetNormalizeFunc¶
func (f *FlagSet) SetNormalizeFunc(n func(f *FlagSet, namestring)NormalizedName)
SetNormalizeFunc allows you to add a function which can translate flag names.Flags added to the FlagSet will be translated and then when anything tries tolook up the flag that will also be translated. So it would be possible to createa flag named "getURL" and have it translated to "geturl". A user could then pass"--getUrl" which may also be translated to "geturl" and everything will work.
func (*FlagSet)SetOutput¶
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.
Example¶
package mainimport ("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 == 1flag := fs.ShorthandLookup(short)fmt.Println(flag.Name)}func (*FlagSet)String¶
String defines a string flag with specified name, default value, and usage string.The return value is the address of a string variable that stores the value of the flag.
func (*FlagSet)StringArray¶
StringArray defines a string flag with specified name, default value, and usage string.The return value is the address of a []string variable that stores the value of the flag.The value of each argument will not try to be separated by comma. Use a StringSlice for that.
func (*FlagSet)StringArrayP¶
StringArrayP is like StringArray, but accepts a shorthand letter that can be used after a single dash.
func (*FlagSet)StringArrayVar¶
StringArrayVar defines a string flag with specified name, default value, and usage string.The argument p points to a []string variable in which to store the values of the multiple flags.The value of each argument will not try to be separated by comma. Use a StringSlice for that.
func (*FlagSet)StringArrayVarP¶
StringArrayVarP is like StringArrayVar, but accepts a shorthand letter that can be used after a single dash.
func (*FlagSet)StringP¶
StringP is like String, but accepts a shorthand letter that can be used after a single dash.
func (*FlagSet)StringSlice¶
StringSlice defines a string flag with specified name, default value, and usage string.The return value is the address of a []string variable that stores the value of the flag.Compared to StringArray flags, StringSlice flags take comma-separated value as arguments and split them accordingly.For example:
--ss="v1,v2" --ss="v3"
will result in
[]string{"v1", "v2", "v3"}func (*FlagSet)StringSliceP¶
StringSliceP is like StringSlice, but accepts a shorthand letter that can be used after a single dash.
func (*FlagSet)StringSliceVar¶
StringSliceVar defines a string flag with specified name, default value, and usage string.The argument p points to a []string variable in which to store the value of the flag.Compared to StringArray flags, StringSlice flags take comma-separated value as arguments and split them accordingly.For example:
--ss="v1,v2" --ss="v3"
will result in
[]string{"v1", "v2", "v3"}func (*FlagSet)StringSliceVarP¶
StringSliceVarP is like StringSliceVar, but accepts a shorthand letter that can be used after a single dash.
func (*FlagSet)StringToInt¶added inv1.0.3
StringToInt defines a string flag with specified name, default value, and usage string.The return value is the address of a map[string]int variable that stores the value of the flag.The value of each argument will not try to be separated by comma
func (*FlagSet)StringToInt64¶added inv1.0.5
StringToInt64 defines a string flag with specified name, default value, and usage string.The return value is the address of a map[string]int64 variable that stores the value of the flag.The value of each argument will not try to be separated by comma
func (*FlagSet)StringToInt64P¶added inv1.0.5
func (f *FlagSet) StringToInt64P(name, shorthandstring, value map[string]int64, usagestring) *map[string]int64
StringToInt64P is like StringToInt64, but accepts a shorthand letter that can be used after a single dash.
func (*FlagSet)StringToInt64Var¶added inv1.0.5
func (f *FlagSet) StringToInt64Var(p *map[string]int64, namestring, value map[string]int64, usagestring)
StringToInt64Var defines a string flag with specified name, default value, and usage string.The argument p point64s to a map[string]int64 variable in which to store the values of the multiple flags.The value of each argument will not try to be separated by comma
func (*FlagSet)StringToInt64VarP¶added inv1.0.5
func (f *FlagSet) StringToInt64VarP(p *map[string]int64, name, shorthandstring, value map[string]int64, usagestring)
StringToInt64VarP is like StringToInt64Var, but accepts a shorthand letter that can be used after a single dash.
func (*FlagSet)StringToIntP¶added inv1.0.3
func (f *FlagSet) StringToIntP(name, shorthandstring, value map[string]int, usagestring) *map[string]int
StringToIntP is like StringToInt, but accepts a shorthand letter that can be used after a single dash.
func (*FlagSet)StringToIntVar¶added inv1.0.3
StringToIntVar defines a string flag with specified name, default value, and usage string.The argument p points to a map[string]int variable in which to store the values of the multiple flags.The value of each argument will not try to be separated by comma
func (*FlagSet)StringToIntVarP¶added inv1.0.3
func (f *FlagSet) StringToIntVarP(p *map[string]int, name, shorthandstring, value map[string]int, usagestring)
StringToIntVarP is like StringToIntVar, but accepts a shorthand letter that can be used after a single dash.
func (*FlagSet)StringToString¶added inv1.0.3
func (f *FlagSet) StringToString(namestring, value map[string]string, usagestring) *map[string]string
StringToString defines a string flag with specified name, default value, and usage string.The return value is the address of a map[string]string variable that stores the value of the flag.The value of each argument will not try to be separated by comma
func (*FlagSet)StringToStringP¶added inv1.0.3
func (f *FlagSet) StringToStringP(name, shorthandstring, value map[string]string, usagestring) *map[string]string
StringToStringP is like StringToString, but accepts a shorthand letter that can be used after a single dash.
func (*FlagSet)StringToStringVar¶added inv1.0.3
func (f *FlagSet) StringToStringVar(p *map[string]string, namestring, value map[string]string, usagestring)
StringToStringVar defines a string flag with specified name, default value, and usage string.The argument p points to a map[string]string variable in which to store the values of the multiple flags.The value of each argument will not try to be separated by comma
func (*FlagSet)StringToStringVarP¶added inv1.0.3
func (f *FlagSet) StringToStringVarP(p *map[string]string, name, shorthandstring, value map[string]string, usagestring)
StringToStringVarP is like StringToStringVar, but accepts a shorthand letter that can be used after a single dash.
func (*FlagSet)StringVar¶
StringVar defines a string flag with specified name, default value, and usage string.The argument p points to a string variable in which to store the value of the flag.
func (*FlagSet)StringVarP¶
StringVarP is like StringVar, but accepts a shorthand letter that can be used after a single dash.
func (*FlagSet)TextVar¶added inv1.0.7
func (f *FlagSet) TextVar(pencoding.TextUnmarshaler, namestring, valueencoding.TextMarshaler, usagestring)
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.
func (*FlagSet)TextVarP¶added inv1.0.7
func (f *FlagSet) TextVarP(pencoding.TextUnmarshaler, name, shorthandstring, valueencoding.TextMarshaler, usagestring)
TextVarP is like TextVar, but accepts a shorthand letter that can be used after a single dash.
func (*FlagSet)Time¶added inv1.0.7
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.
func (*FlagSet)TimeP¶added inv1.0.7
func (f *FlagSet) TimeP(name, shorthandstring, valuetime.Time, formats []string, usagestring) *time.Time
TimeP is like Time, but accepts a shorthand letter that can be used after a single dash.
func (*FlagSet)TimeVar¶added inv1.0.7
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.
func (*FlagSet)TimeVarP¶added inv1.0.7
func (f *FlagSet) TimeVarP(p *time.Time, name, shorthandstring, valuetime.Time, formats []string, usagestring)
TimeVarP is like TimeVar, but accepts a shorthand letter that can be used after a single dash.
func (*FlagSet)Uint¶
Uint defines a uint flag with specified name, default value, and usage string.The return value is the address of a uint variable that stores the value of the flag.
func (*FlagSet)Uint16¶
Uint16 defines a uint flag with specified name, default value, and usage string.The return value is the address of a uint variable that stores the value of the flag.
func (*FlagSet)Uint16P¶
Uint16P is like Uint16, but accepts a shorthand letter that can be used after a single dash.
func (*FlagSet)Uint16Var¶
Uint16Var defines a uint flag with specified name, default value, and usage string.The argument p points to a uint variable in which to store the value of the flag.
func (*FlagSet)Uint16VarP¶
Uint16VarP is like Uint16Var, but accepts a shorthand letter that can be used after a single dash.
func (*FlagSet)Uint32¶
Uint32 defines a uint32 flag with specified name, default value, and usage string.The return value is the address of a uint32 variable that stores the value of the flag.
func (*FlagSet)Uint32P¶
Uint32P is like Uint32, but accepts a shorthand letter that can be used after a single dash.
func (*FlagSet)Uint32Var¶
Uint32Var defines a uint32 flag with specified name, default value, and usage string.The argument p points to a uint32 variable in which to store the value of the flag.
func (*FlagSet)Uint32VarP¶
Uint32VarP is like Uint32Var, but accepts a shorthand letter that can be used after a single dash.
func (*FlagSet)Uint64¶
Uint64 defines a uint64 flag with specified name, default value, and usage string.The return value is the address of a uint64 variable that stores the value of the flag.
func (*FlagSet)Uint64P¶
Uint64P is like Uint64, but accepts a shorthand letter that can be used after a single dash.
func (*FlagSet)Uint64Var¶
Uint64Var defines a uint64 flag with specified name, default value, and usage string.The argument p points to a uint64 variable in which to store the value of the flag.
func (*FlagSet)Uint64VarP¶
Uint64VarP is like Uint64Var, but accepts a shorthand letter that can be used after a single dash.
func (*FlagSet)Uint8¶
Uint8 defines a uint8 flag with specified name, default value, and usage string.The return value is the address of a uint8 variable that stores the value of the flag.
func (*FlagSet)Uint8P¶
Uint8P is like Uint8, but accepts a shorthand letter that can be used after a single dash.
func (*FlagSet)Uint8Var¶
Uint8Var defines a uint8 flag with specified name, default value, and usage string.The argument p points to a uint8 variable in which to store the value of the flag.
func (*FlagSet)Uint8VarP¶
Uint8VarP is like Uint8Var, but accepts a shorthand letter that can be used after a single dash.
func (*FlagSet)UintP¶
UintP is like Uint, but accepts a shorthand letter that can be used after a single dash.
func (*FlagSet)UintSlice¶
UintSlice defines a []uint flag with specified name, default value, and usage string.The return value is the address of a []uint variable that stores the value of the flag.
func (*FlagSet)UintSliceP¶
UintSliceP is like UintSlice, but accepts a shorthand letter that can be used after a single dash.
func (*FlagSet)UintSliceVar¶
UintSliceVar defines a uintSlice flag with specified name, default value, and usage string.The argument p points to a []uint variable in which to store the value of the flag.
func (*FlagSet)UintSliceVarP¶
UintSliceVarP is like UintSliceVar, but accepts a shorthand letter that can be used after a single dash.
func (*FlagSet)UintVar¶
UintVar defines a uint flag with specified name, default value, and usage string.The argument p points to a uint variable in which to store the value of the flag.
func (*FlagSet)UintVarP¶
UintVarP is like UintVar, but accepts a shorthand letter that can be used after a single dash.
func (*FlagSet)Var¶
Var defines a flag with the specified name and usage string. The type andvalue of the flag are represented by the first argument, of type Value, whichtypically holds a user-defined implementation of Value. For instance, thecaller could create a flag that turns a comma-separated string into a sliceof strings by giving the slice the methods of Value; in particular, Set woulddecompose the comma-separated string into the slice.
func (*FlagSet)VarP¶
VarP is like Var, but accepts a shorthand letter that can be used after a single dash.
typeInvalidSyntaxError¶added inv1.0.7
type InvalidSyntaxError struct {// contains filtered or unexported fields}InvalidSyntaxError is the error returned when a bad flag name is passed onthe command line.
func (*InvalidSyntaxError)Error¶added inv1.0.7
func (e *InvalidSyntaxError) Error()string
Error implements error.
func (*InvalidSyntaxError)GetSpecifiedFlag¶added inv1.0.7
func (e *InvalidSyntaxError) GetSpecifiedFlag()string
GetSpecifiedName returns the exact flag (with dashes) as itappeared in the parsed arguments.
typeInvalidValueError¶added inv1.0.7
type InvalidValueError struct {// contains filtered or unexported fields}InvalidValueError is the error returned when an invalid value is usedfor a flag.
func (*InvalidValueError)Error¶added inv1.0.7
func (e *InvalidValueError) Error()string
Error implements error.
func (*InvalidValueError)GetFlag¶added inv1.0.7
func (e *InvalidValueError) GetFlag() *Flag
GetFlag returns the flag for which the error occurred.
func (*InvalidValueError)GetValue¶added inv1.0.7
func (e *InvalidValueError) GetValue()string
GetValue returns the invalid value that was provided.
func (*InvalidValueError)Unwrap¶added inv1.0.7
func (e *InvalidValueError) Unwrap()error
Unwrap implements errors.Unwrap.
typeNormalizedName¶
type NormalizedNamestring
NormalizedName is a flag name that has been normalized according to rulesfor the FlagSet (e.g. making '-' and '_' equivalent).
typeNotExistError¶added inv1.0.7
type NotExistError struct {// contains filtered or unexported fields}NotExistError is the error returned when trying to access a flag thatdoes not exist in the FlagSet.
func (*NotExistError)Error¶added inv1.0.7
func (e *NotExistError) Error()string
Error implements error.
func (*NotExistError)GetSpecifiedName¶added inv1.0.7
func (e *NotExistError) GetSpecifiedName()string
GetSpecifiedName returns the name of the flag (without dashes) as itappeared in the parsed arguments.
func (*NotExistError)GetSpecifiedShortnames¶added inv1.0.7
func (e *NotExistError) GetSpecifiedShortnames()string
GetSpecifiedShortnames returns the group of shorthand arguments(without dashes) that the flag appeared within. If the flag was not in ashorthand group, this will return an empty string.
typeParseErrorsAllowlist¶added inv1.0.8
type ParseErrorsAllowlist struct {// UnknownFlags will ignore unknown flags errors and continue parsing rest of the flagsUnknownFlagsbool}ParseErrorsAllowlist defines the parsing errors that can be ignored
typeParseErrorsWhitelistdeprecatedadded inv1.0.1
type ParseErrorsWhitelist =ParseErrorsAllowlist
ParseErrorsWhitelist defines the parsing errors that can be ignored.
Deprecated: useParseErrorsAllowlist instead. This type will be removed in a future release.
typeSliceValue¶added inv1.0.5
type SliceValue interface {// Append adds the specified value to the end of the flag value list.Append(string)error// Replace will fully overwrite any data currently in the flag value list.Replace([]string)error// GetSlice returns the flag value list as an array of strings.GetSlice() []string}SliceValue is a secondary interface to all flags which hold a listof values. This allows full control over the value of list flags,and avoids complicated marshalling and unmarshalling to csv.
typeValue¶
Value is the interface to the dynamic value stored in a flag.(The default value is represented as a string.)
typeValueRequiredError¶added inv1.0.7
type ValueRequiredError struct {// contains filtered or unexported fields}ValueRequiredError is the error returned when a flag needs an argument butno argument was provided.
func (*ValueRequiredError)Error¶added inv1.0.7
func (e *ValueRequiredError) Error()string
Error implements error.
func (*ValueRequiredError)GetFlag¶added inv1.0.7
func (e *ValueRequiredError) GetFlag() *Flag
GetFlag returns the flag for which the error occurred.
func (*ValueRequiredError)GetSpecifiedName¶added inv1.0.7
func (e *ValueRequiredError) GetSpecifiedName()string
GetSpecifiedName returns the name of the flag (without dashes) as itappeared in the parsed arguments.
func (*ValueRequiredError)GetSpecifiedShortnames¶added inv1.0.7
func (e *ValueRequiredError) GetSpecifiedShortnames()string
GetSpecifiedShortnames returns the group of shorthand arguments(without dashes) that the flag appeared within. If the flag was not in ashorthand group, this will return an empty string.
Source Files¶
- bool.go
- bool_func.go
- bool_slice.go
- bytes.go
- count.go
- duration.go
- duration_slice.go
- errors.go
- flag.go
- float32.go
- float32_slice.go
- float64.go
- float64_slice.go
- func.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
- ipnet_slice.go
- string.go
- string_array.go
- string_slice.go
- string_to_int.go
- string_to_int64.go
- string_to_string.go
- text.go
- time.go
- uint.go
- uint16.go
- uint32.go
- uint64.go
- uint8.go
- uint_slice.go