Movatterモバイル変換


[0]ホーム

URL:


pflag

packagemodule
v1.0.10Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Sep 2, 2025 License:BSD-3-ClauseImports:16Imported by:53,331

Details

Repository

github.com/spf13/pflag

Links

README

Build StatusGo Report CardGoDoc

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/pflag

Run tests by running:

go test github.com/spf13/pflag

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 *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 ArgumentsResulting Value
--flagname=1357ip=1357
--flagnameip=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=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 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"-abcs1234

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.

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-pflags

will 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

Examples

Constants

This section is empty.

Variables

CommandLine is the default set of command-line flags, parsed from os.Args.

View Source
var ErrHelp =errors.New("pflag: help requested")

ErrHelp is the error returned if the flag -help is invoked but no such flag is defined.

View Source
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

func Arg(iint)string

Arg returns the i'th command-line argument. Arg(0) is the first remaining argumentafter flags have been processed.

funcArgs

func Args() []string

Args returns the non-flag command-line arguments.

funcBool

func Bool(namestring, valuebool, usagestring) *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.

funcBoolFuncadded inv1.0.7

func BoolFunc(namestring, usagestring, fn func(string)error)

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.

funcBoolFuncPadded inv1.0.7

func BoolFuncP(name, shorthandstring, usagestring, fn func(string)error)

BoolFuncP is like BoolFunc, but accepts a shorthand letter that can be used after a single dash.

funcBoolP

func BoolP(name, shorthandstring, valuebool, usagestring) *bool

BoolP is like Bool, but accepts a shorthand letter that can be used after a single dash.

funcBoolSlice

func BoolSlice(namestring, value []bool, usagestring) *[]bool

BoolSlice defines a []bool flag with specified name, default value, and usage string.The return value is the address of a []bool variable that stores the value of the flag.

funcBoolSliceP

func BoolSliceP(name, shorthandstring, value []bool, usagestring) *[]bool

BoolSliceP is like BoolSlice, but accepts a shorthand letter that can be used after a single dash.

funcBoolSliceVar

func BoolSliceVar(p *[]bool, namestring, value []bool, usagestring)

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

func BoolSliceVarP(p *[]bool, name, shorthandstring, value []bool, usagestring)

BoolSliceVarP is like BoolSliceVar, but accepts a shorthand letter that can be used after a single dash.

funcBoolVar

func BoolVar(p *bool, namestring, valuebool, usagestring)

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

func BoolVarP(p *bool, name, shorthandstring, valuebool, usagestring)

BoolVarP is like BoolVar, but accepts a shorthand letter that can be used after a single dash.

funcBytesBase64added inv1.0.2

func BytesBase64(namestring, value []byte, usagestring) *[]byte

BytesBase64 defines an []byte flag with specified name, default value, and usage string.The return value is the address of an []byte variable that stores the value of the flag.

funcBytesBase64Padded inv1.0.2

func BytesBase64P(name, shorthandstring, value []byte, usagestring) *[]byte

BytesBase64P is like BytesBase64, but accepts a shorthand letter that can be used after a single dash.

funcBytesBase64Varadded inv1.0.2

func BytesBase64Var(p *[]byte, namestring, value []byte, usagestring)

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.

funcBytesBase64VarPadded inv1.0.2

func BytesBase64VarP(p *[]byte, name, shorthandstring, value []byte, usagestring)

BytesBase64VarP is like BytesBase64Var, but accepts a shorthand letter that can be used after a single dash.

funcBytesHexadded inv1.0.1

func BytesHex(namestring, value []byte, usagestring) *[]byte

BytesHex defines an []byte flag with specified name, default value, and usage string.The return value is the address of an []byte variable that stores the value of the flag.

funcBytesHexPadded inv1.0.1

func BytesHexP(name, shorthandstring, value []byte, usagestring) *[]byte

BytesHexP is like BytesHex, but accepts a shorthand letter that can be used after a single dash.

funcBytesHexVaradded inv1.0.1

func BytesHexVar(p *[]byte, namestring, value []byte, usagestring)

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.

funcBytesHexVarPadded inv1.0.1

func BytesHexVarP(p *[]byte, name, shorthandstring, value []byte, usagestring)

BytesHexVarP is like BytesHexVar, but accepts a shorthand letter that can be used after a single dash.

funcCount

func Count(namestring, usagestring) *int

Count defines a count flag with specified name, default value, and usage string.The return value is the address of an int variable that stores the value of the flag.A count flag will add 1 to its value every time it is found on the command line

funcCountP

func CountP(name, shorthandstring, usagestring) *int

CountP is like Count only takes a shorthand for the flag name.

funcCountVar

func CountVar(p *int, namestring, usagestring)

CountVar like CountVar only the flag is placed on the CommandLine instead of a given flag set

funcCountVarP

func CountVarP(p *int, name, shorthandstring, usagestring)

CountVarP is like CountVar only take a shorthand for the flag name.

funcDuration

func Duration(namestring, valuetime.Duration, usagestring) *time.Duration

Duration defines a time.Duration flag with specified name, default value, and usage string.The return value is the address of a time.Duration variable that stores the value of the flag.

funcDurationP

func DurationP(name, shorthandstring, valuetime.Duration, usagestring) *time.Duration

DurationP is like Duration, but accepts a shorthand letter that can be used after a single dash.

funcDurationSliceadded inv1.0.1

func DurationSlice(namestring, value []time.Duration, usagestring) *[]time.Duration

DurationSlice defines a []time.Duration flag with specified name, default value, and usage string.The return value is the address of a []time.Duration variable that stores the value of the flag.

funcDurationSlicePadded inv1.0.1

func 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.

funcDurationSliceVaradded inv1.0.1

func DurationSliceVar(p *[]time.Duration, namestring, value []time.Duration, usagestring)

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.

funcDurationSliceVarPadded 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

func DurationVar(p *time.Duration, namestring, valuetime.Duration, usagestring)

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

func 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.

funcFloat32

func Float32(namestring, valuefloat32, usagestring) *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.

funcFloat32P

func Float32P(name, shorthandstring, valuefloat32, usagestring) *float32

Float32P is like Float32, but accepts a shorthand letter that can be used after a single dash.

funcFloat32Sliceadded inv1.0.5

func Float32Slice(namestring, value []float32, usagestring) *[]float32

Float32Slice defines a []float32 flag with specified name, default value, and usage string.The return value is the address of a []float32 variable that stores the value of the flag.

funcFloat32SlicePadded inv1.0.5

func Float32SliceP(name, shorthandstring, value []float32, usagestring) *[]float32

Float32SliceP is like Float32Slice, but accepts a shorthand letter that can be used after a single dash.

funcFloat32SliceVaradded inv1.0.5

func Float32SliceVar(p *[]float32, namestring, value []float32, usagestring)

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.

funcFloat32SliceVarPadded inv1.0.5

func 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.

funcFloat32Var

func Float32Var(p *float32, namestring, valuefloat32, usagestring)

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

func Float32VarP(p *float32, name, shorthandstring, valuefloat32, usagestring)

Float32VarP is like Float32Var, but accepts a shorthand letter that can be used after a single dash.

funcFloat64

func Float64(namestring, valuefloat64, usagestring) *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.

funcFloat64P

func Float64P(name, shorthandstring, valuefloat64, usagestring) *float64

Float64P is like Float64, but accepts a shorthand letter that can be used after a single dash.

funcFloat64Sliceadded inv1.0.5

func Float64Slice(namestring, value []float64, usagestring) *[]float64

Float64Slice defines a []float64 flag with specified name, default value, and usage string.The return value is the address of a []float64 variable that stores the value of the flag.

funcFloat64SlicePadded inv1.0.5

func Float64SliceP(name, shorthandstring, value []float64, usagestring) *[]float64

Float64SliceP is like Float64Slice, but accepts a shorthand letter that can be used after a single dash.

funcFloat64SliceVaradded inv1.0.5

func Float64SliceVar(p *[]float64, namestring, value []float64, usagestring)

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.

funcFloat64SliceVarPadded inv1.0.5

func 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.

funcFloat64Var

func Float64Var(p *float64, namestring, valuefloat64, usagestring)

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

func Float64VarP(p *float64, name, shorthandstring, valuefloat64, usagestring)

Float64VarP is like Float64Var, but accepts a shorthand letter that can be used after a single dash.

funcFuncadded inv1.0.7

func Func(namestring, usagestring, fn func(string)error)

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.

funcFuncPadded inv1.0.7

func FuncP(name, shorthandstring, usagestring, fn func(string)error)

FuncP is like Func, but accepts a shorthand letter that can be used after a single dash.

funcIP

func IP(namestring, valuenet.IP, usagestring) *net.IP

IP defines an net.IP flag with specified name, default value, and usage string.The return value is the address of an net.IP variable that stores the value of the flag.

funcIPMask

func IPMask(namestring, valuenet.IPMask, usagestring) *net.IPMask

IPMask defines an net.IPMask flag with specified name, default value, and usage string.The return value is the address of an net.IPMask variable that stores the value of the flag.

funcIPMaskP

func IPMaskP(name, shorthandstring, valuenet.IPMask, usagestring) *net.IPMask

IPMaskP is like IP, but accepts a shorthand letter that can be used after a single dash.

funcIPMaskVar

func IPMaskVar(p *net.IPMask, namestring, valuenet.IPMask, usagestring)

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

func IPMaskVarP(p *net.IPMask, name, shorthandstring, valuenet.IPMask, usagestring)

IPMaskVarP is like IPMaskVar, but accepts a shorthand letter that can be used after a single dash.

funcIPNet

func IPNet(namestring, valuenet.IPNet, usagestring) *net.IPNet

IPNet defines an net.IPNet flag with specified name, default value, and usage string.The return value is the address of an net.IPNet variable that stores the value of the flag.

funcIPNetP

func IPNetP(name, shorthandstring, valuenet.IPNet, usagestring) *net.IPNet

IPNetP is like IPNet, but accepts a shorthand letter that can be used after a single dash.

funcIPNetSliceadded inv1.0.6

func IPNetSlice(namestring, value []net.IPNet, usagestring) *[]net.IPNet

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.

funcIPNetSlicePadded inv1.0.6

func IPNetSliceP(name, shorthandstring, value []net.IPNet, usagestring) *[]net.IPNet

IPNetSliceP is like IPNetSlice, but accepts a shorthand letter that can be used after a single dash.

funcIPNetSliceVaradded inv1.0.6

func IPNetSliceVar(p *[]net.IPNet, namestring, value []net.IPNet, usagestring)

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.

funcIPNetSliceVarPadded inv1.0.6

func 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.

funcIPNetVar

func IPNetVar(p *net.IPNet, namestring, valuenet.IPNet, usagestring)

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

func IPNetVarP(p *net.IPNet, name, shorthandstring, valuenet.IPNet, usagestring)

IPNetVarP is like IPNetVar, but accepts a shorthand letter that can be used after a single dash.

funcIPP

func IPP(name, shorthandstring, valuenet.IP, usagestring) *net.IP

IPP is like IP, but accepts a shorthand letter that can be used after a single dash.

funcIPSlice

func IPSlice(namestring, value []net.IP, usagestring) *[]net.IP

IPSlice defines a []net.IP flag with specified name, default value, and usage string.The return value is the address of a []net.IP variable that stores the value of the flag.

funcIPSliceP

func IPSliceP(name, shorthandstring, value []net.IP, usagestring) *[]net.IP

IPSliceP is like IPSlice, but accepts a shorthand letter that can be used after a single dash.

funcIPSliceVar

func IPSliceVar(p *[]net.IP, namestring, value []net.IP, usagestring)

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

func IPSliceVarP(p *[]net.IP, name, shorthandstring, value []net.IP, usagestring)

IPSliceVarP is like IPSliceVar, but accepts a shorthand letter that can be used after a single dash.

funcIPVar

func IPVar(p *net.IP, namestring, valuenet.IP, usagestring)

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

func IPVarP(p *net.IP, name, shorthandstring, valuenet.IP, usagestring)

IPVarP is like IPVar, but accepts a shorthand letter that can be used after a single dash.

funcInt

func Int(namestring, valueint, usagestring) *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.

funcInt16added inv1.0.1

func Int16(namestring, valueint16, usagestring) *int16

Int16 defines an int16 flag with specified name, default value, and usage string.The return value is the address of an int16 variable that stores the value of the flag.

funcInt16Padded inv1.0.1

func Int16P(name, shorthandstring, valueint16, usagestring) *int16

Int16P is like Int16, but accepts a shorthand letter that can be used after a single dash.

funcInt16Varadded inv1.0.1

func Int16Var(p *int16, namestring, valueint16, usagestring)

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.

funcInt16VarPadded inv1.0.1

func Int16VarP(p *int16, name, shorthandstring, valueint16, usagestring)

Int16VarP is like Int16Var, but accepts a shorthand letter that can be used after a single dash.

funcInt32

func Int32(namestring, valueint32, usagestring) *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.

funcInt32P

func Int32P(name, shorthandstring, valueint32, usagestring) *int32

Int32P is like Int32, but accepts a shorthand letter that can be used after a single dash.

funcInt32Sliceadded inv1.0.5

func Int32Slice(namestring, value []int32, usagestring) *[]int32

Int32Slice defines a []int32 flag with specified name, default value, and usage string.The return value is the address of a []int32 variable that stores the value of the flag.

funcInt32SlicePadded inv1.0.5

func Int32SliceP(name, shorthandstring, value []int32, usagestring) *[]int32

Int32SliceP is like Int32Slice, but accepts a shorthand letter that can be used after a single dash.

funcInt32SliceVaradded inv1.0.5

func Int32SliceVar(p *[]int32, namestring, value []int32, usagestring)

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.

funcInt32SliceVarPadded inv1.0.5

func Int32SliceVarP(p *[]int32, name, shorthandstring, value []int32, usagestring)

Int32SliceVarP is like Int32SliceVar, but accepts a shorthand letter that can be used after a single dash.

funcInt32Var

func Int32Var(p *int32, namestring, valueint32, usagestring)

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

func Int32VarP(p *int32, name, shorthandstring, valueint32, usagestring)

Int32VarP is like Int32Var, but accepts a shorthand letter that can be used after a single dash.

funcInt64

func Int64(namestring, valueint64, usagestring) *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.

funcInt64P

func Int64P(name, shorthandstring, valueint64, usagestring) *int64

Int64P is like Int64, but accepts a shorthand letter that can be used after a single dash.

funcInt64Sliceadded inv1.0.5

func Int64Slice(namestring, value []int64, usagestring) *[]int64

Int64Slice defines a []int64 flag with specified name, default value, and usage string.The return value is the address of a []int64 variable that stores the value of the flag.

funcInt64SlicePadded inv1.0.5

func Int64SliceP(name, shorthandstring, value []int64, usagestring) *[]int64

Int64SliceP is like Int64Slice, but accepts a shorthand letter that can be used after a single dash.

funcInt64SliceVaradded inv1.0.5

func Int64SliceVar(p *[]int64, namestring, value []int64, usagestring)

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.

funcInt64SliceVarPadded inv1.0.5

func Int64SliceVarP(p *[]int64, name, shorthandstring, value []int64, usagestring)

Int64SliceVarP is like Int64SliceVar, but accepts a shorthand letter that can be used after a single dash.

funcInt64Var

func Int64Var(p *int64, namestring, valueint64, usagestring)

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

func Int64VarP(p *int64, name, shorthandstring, valueint64, usagestring)

Int64VarP is like Int64Var, but accepts a shorthand letter that can be used after a single dash.

funcInt8

func Int8(namestring, valueint8, usagestring) *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.

funcInt8P

func Int8P(name, shorthandstring, valueint8, usagestring) *int8

Int8P is like Int8, but accepts a shorthand letter that can be used after a single dash.

funcInt8Var

func Int8Var(p *int8, namestring, valueint8, usagestring)

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

func Int8VarP(p *int8, name, shorthandstring, valueint8, usagestring)

Int8VarP is like Int8Var, but accepts a shorthand letter that can be used after a single dash.

funcIntP

func IntP(name, shorthandstring, valueint, usagestring) *int

IntP is like Int, but accepts a shorthand letter that can be used after a single dash.

funcIntSlice

func IntSlice(namestring, value []int, usagestring) *[]int

IntSlice defines a []int flag with specified name, default value, and usage string.The return value is the address of a []int variable that stores the value of the flag.

funcIntSliceP

func IntSliceP(name, shorthandstring, value []int, usagestring) *[]int

IntSliceP is like IntSlice, but accepts a shorthand letter that can be used after a single dash.

funcIntSliceVar

func IntSliceVar(p *[]int, namestring, value []int, usagestring)

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

func IntSliceVarP(p *[]int, name, shorthandstring, value []int, usagestring)

IntSliceVarP is like IntSliceVar, but accepts a shorthand letter that can be used after a single dash.

funcIntVar

func IntVar(p *int, namestring, valueint, usagestring)

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

func IntVarP(p *int, name, shorthandstring, valueint, usagestring)

IntVarP is like IntVar, but accepts a shorthand letter that can be used after a single dash.

funcNArg

func NArg()int

NArg is the number of arguments remaining after flags have been processed.

funcNFlag

func NFlag()int

NFlag returns the number of command-line flags that have been set.

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

func ParseAll(fn func(flag *Flag, valuestring)error)

ParseAll parses the command-line flags from os.Args[1:] and called fn for each.The arguments for fn are flag and value. Must be called after all flags aredefined and before flags are accessed by the program.

funcParseIPv4Mask

func ParseIPv4Mask(sstring)net.IPMask

ParseIPv4Mask written in IP form (e.g. 255.255.255.0).This function should really belong to the net package.

funcParseSkippedFlagsadded inv1.0.7

func ParseSkippedFlags(osArgs []string, goFlagSet *goflag.FlagSet)error

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)`

funcParsed

func Parsed()bool

Parsed returns true if the command-line flags have been parsed.

funcPrintDefaults

func PrintDefaults()

PrintDefaults prints to standard error the default values of all defined command-line flags.

funcSet

func Set(name, valuestring)error

Set sets the value of the named command-line flag.

funcSetInterspersed

func SetInterspersed(interspersedbool)

SetInterspersed sets whether to support interspersed option/non-option arguments.

funcString

func String(namestring, valuestring, usagestring) *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.

funcStringArray

func StringArray(namestring, value []string, usagestring) *[]string

StringArray defines a string flag with specified name, default value, and usage string.The return value is the address of a []string variable that stores the value of the flag.The value of each argument will not try to be separated by comma. Use a StringSlice for that.

funcStringArrayP

func StringArrayP(name, shorthandstring, value []string, usagestring) *[]string

StringArrayP is like StringArray, but accepts a shorthand letter that can be used after a single dash.

funcStringArrayVar

func StringArrayVar(p *[]string, namestring, value []string, usagestring)

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

func StringArrayVarP(p *[]string, name, shorthandstring, value []string, usagestring)

StringArrayVarP is like StringArrayVar, but accepts a shorthand letter that can be used after a single dash.

funcStringP

func StringP(name, shorthandstring, valuestring, usagestring) *string

StringP is like String, but accepts a shorthand letter that can be used after a single dash.

funcStringSlice

func StringSlice(namestring, value []string, usagestring) *[]string

StringSlice defines a string flag with specified name, default value, and usage string.The return value is the address of a []string variable that stores the value of the flag.Compared to StringArray flags, StringSlice flags take comma-separated value as arguments and split them accordingly.For example:

--ss="v1,v2" --ss="v3"

will result in

[]string{"v1", "v2", "v3"}

funcStringSliceP

func StringSliceP(name, shorthandstring, value []string, usagestring) *[]string

StringSliceP is like StringSlice, but accepts a shorthand letter that can be used after a single dash.

funcStringSliceVar

func StringSliceVar(p *[]string, namestring, value []string, usagestring)

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

func StringSliceVarP(p *[]string, name, shorthandstring, value []string, usagestring)

StringSliceVarP is like StringSliceVar, but accepts a shorthand letter that can be used after a single dash.

funcStringToIntadded inv1.0.3

func StringToInt(namestring, value map[string]int, usagestring) *map[string]int

StringToInt defines a string flag with specified name, default value, and usage string.The return value is the address of a map[string]int variable that stores the value of the flag.The value of each argument will not try to be separated by comma

funcStringToInt64added inv1.0.5

func StringToInt64(namestring, value map[string]int64, usagestring) *map[string]int64

StringToInt64 defines a string flag with specified name, default value, and usage string.The return value is the address of a map[string]int64 variable that stores the value of the flag.The value of each argument will not try to be separated by comma

funcStringToInt64Padded inv1.0.5

func 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.

funcStringToInt64Varadded inv1.0.5

func 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 value of the flag.The value of each argument will not try to be separated by comma

funcStringToInt64VarPadded 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.

funcStringToIntPadded inv1.0.3

func 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.

funcStringToIntVaradded inv1.0.3

func StringToIntVar(p *map[string]int, namestring, value map[string]int, usagestring)

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

funcStringToIntVarPadded inv1.0.3

func 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.

funcStringToStringadded inv1.0.3

func 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

funcStringToStringPadded 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.

funcStringToStringVaradded inv1.0.3

func 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 value of the flag.The value of each argument will not try to be separated by comma

funcStringToStringVarPadded 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

func StringVar(p *string, namestring, valuestring, usagestring)

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

func StringVarP(p *string, name, shorthandstring, valuestring, usagestring)

StringVarP is like StringVar, but accepts a shorthand letter that can be used after a single dash.

funcTextVaradded inv1.0.7

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.

funcTextVarPadded 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.

funcTimeadded inv1.0.7

func Time(namestring, valuetime.Time, formats []string, usagestring) *time.Time

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.

funcTimePadded inv1.0.7

func 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.

funcTimeVaradded inv1.0.7

func TimeVar(p *time.Time, namestring, valuetime.Time, formats []string, usagestring)

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.

funcTimeVarPadded inv1.0.7

func 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.

funcUint

func Uint(namestring, valueuint, usagestring) *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.

funcUint16

func Uint16(namestring, valueuint16, usagestring) *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.

funcUint16P

func Uint16P(name, shorthandstring, valueuint16, usagestring) *uint16

Uint16P is like Uint16, but accepts a shorthand letter that can be used after a single dash.

funcUint16Var

func Uint16Var(p *uint16, namestring, valueuint16, usagestring)

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

func Uint16VarP(p *uint16, name, shorthandstring, valueuint16, usagestring)

Uint16VarP is like Uint16Var, but accepts a shorthand letter that can be used after a single dash.

funcUint32

func Uint32(namestring, valueuint32, usagestring) *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.

funcUint32P

func Uint32P(name, shorthandstring, valueuint32, usagestring) *uint32

Uint32P is like Uint32, but accepts a shorthand letter that can be used after a single dash.

funcUint32Var

func Uint32Var(p *uint32, namestring, valueuint32, usagestring)

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

func Uint32VarP(p *uint32, name, shorthandstring, valueuint32, usagestring)

Uint32VarP is like Uint32Var, but accepts a shorthand letter that can be used after a single dash.

funcUint64

func Uint64(namestring, valueuint64, usagestring) *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.

funcUint64P

func Uint64P(name, shorthandstring, valueuint64, usagestring) *uint64

Uint64P is like Uint64, but accepts a shorthand letter that can be used after a single dash.

funcUint64Var

func Uint64Var(p *uint64, namestring, valueuint64, usagestring)

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

func Uint64VarP(p *uint64, name, shorthandstring, valueuint64, usagestring)

Uint64VarP is like Uint64Var, but accepts a shorthand letter that can be used after a single dash.

funcUint8

func Uint8(namestring, valueuint8, usagestring) *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.

funcUint8P

func Uint8P(name, shorthandstring, valueuint8, usagestring) *uint8

Uint8P is like Uint8, but accepts a shorthand letter that can be used after a single dash.

funcUint8Var

func Uint8Var(p *uint8, namestring, valueuint8, usagestring)

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

func Uint8VarP(p *uint8, name, shorthandstring, valueuint8, usagestring)

Uint8VarP is like Uint8Var, but accepts a shorthand letter that can be used after a single dash.

funcUintP

func UintP(name, shorthandstring, valueuint, usagestring) *uint

UintP is like Uint, but accepts a shorthand letter that can be used after a single dash.

funcUintSlice

func UintSlice(namestring, value []uint, usagestring) *[]uint

UintSlice defines a []uint flag with specified name, default value, and usage string.The return value is the address of a []uint variable that stores the value of the flag.

funcUintSliceP

func UintSliceP(name, shorthandstring, value []uint, usagestring) *[]uint

UintSliceP is like UintSlice, but accepts a shorthand letter that can be used after a single dash.

funcUintSliceVar

func UintSliceVar(p *[]uint, namestring, value []uint, usagestring)

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

func UintSliceVarP(p *[]uint, name, shorthandstring, value []uint, usagestring)

UintSliceVarP is like the UintSliceVar, but accepts a shorthand letter that can be used after a single dash.

funcUintVar

func UintVar(p *uint, namestring, valueuint, usagestring)

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

func UintVarP(p *uint, name, shorthandstring, valueuint, usagestring)

UintVarP is like UintVar, but accepts a shorthand letter that can be used after a single dash.

funcUnquoteUsage

func UnquoteUsage(flag *Flag) (namestring, usagestring)

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

func Var(valueValue, namestring, usagestring)

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.

funcVarP

func VarP(valueValue, name, shorthand, usagestring)

VarP is like Var, but accepts a shorthand letter that can be used after a single dash.

funcVisit

func Visit(fn func(*Flag))

Visit visits the command-line flags in lexicographical order orin primordial order if f.SortFlags is false, calling fn for each.It visits only those flags that have been set.

funcVisitAll

func VisitAll(fn func(*Flag))

VisitAll visits the command-line flags in lexicographical order orin primordial order if f.SortFlags is false, calling fn for each.It visits all flags, even those not set.

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

func Lookup(namestring) *Flag

Lookup returns the Flag structure of the named command-line flag,returning nil if none exists.

funcPFlagFromGoFlag

func PFlagFromGoFlag(goflag *goflag.Flag) *Flag

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

func ShorthandLookup(namestring) *Flag

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)AddFlag

func (f *FlagSet) AddFlag(flag *Flag)

AddFlag will add the flag to the FlagSet

func (*FlagSet)AddFlagSet

func (f *FlagSet) AddFlagSet(newSet *FlagSet)

AddFlagSet adds one FlagSet to another. If a flag is already present in fthe flag from newSet will be ignored.

func (*FlagSet)AddGoFlag

func (f *FlagSet) AddGoFlag(goflag *goflag.Flag)

AddGoFlag will add the given *flag.Flag to the pflag.FlagSet

func (*FlagSet)AddGoFlagSet

func (f *FlagSet) AddGoFlagSet(newSet *goflag.FlagSet)

AddGoFlagSet will add the given *flag.FlagSet to the pflag.FlagSet

func (*FlagSet)Arg

func (f *FlagSet) Arg(iint)string

Arg returns the i'th argument. Arg(0) is the first remaining argumentafter flags have been processed.

func (*FlagSet)Args

func (f *FlagSet) Args() []string

Args returns the non-flag arguments.

func (*FlagSet)ArgsLenAtDash

func (f *FlagSet) ArgsLenAtDash()int

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

func (f *FlagSet) Bool(namestring, valuebool, usagestring) *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)BoolFuncadded inv1.0.7

func (f *FlagSet) BoolFunc(namestring, usagestring, fn func(string)error)

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)BoolFuncPadded inv1.0.7

func (f *FlagSet) BoolFuncP(name, shorthandstring, usagestring, fn func(string)error)

BoolFuncP is like BoolFunc, but accepts a shorthand letter that can be used after a single dash.

func (*FlagSet)BoolP

func (f *FlagSet) BoolP(name, shorthandstring, valuebool, usagestring) *bool

BoolP is like Bool, but accepts a shorthand letter that can be used after a single dash.

func (*FlagSet)BoolSlice

func (f *FlagSet) BoolSlice(namestring, value []bool, usagestring) *[]bool

BoolSlice defines a []bool flag with specified name, default value, and usage string.The return value is the address of a []bool variable that stores the value of the flag.

func (*FlagSet)BoolSliceP

func (f *FlagSet) BoolSliceP(name, shorthandstring, value []bool, usagestring) *[]bool

BoolSliceP is like BoolSlice, but accepts a shorthand letter that can be used after a single dash.

func (*FlagSet)BoolSliceVar

func (f *FlagSet) BoolSliceVar(p *[]bool, namestring, value []bool, usagestring)

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

func (f *FlagSet) BoolSliceVarP(p *[]bool, name, shorthandstring, value []bool, usagestring)

BoolSliceVarP is like BoolSliceVar, but accepts a shorthand letter that can be used after a single dash.

func (*FlagSet)BoolVar

func (f *FlagSet) BoolVar(p *bool, namestring, valuebool, usagestring)

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

func (f *FlagSet) BoolVarP(p *bool, name, shorthandstring, valuebool, usagestring)

BoolVarP is like BoolVar, but accepts a shorthand letter that can be used after a single dash.

func (*FlagSet)BytesBase64added inv1.0.2

func (f *FlagSet) BytesBase64(namestring, value []byte, usagestring) *[]byte

BytesBase64 defines an []byte flag with specified name, default value, and usage string.The return value is the address of an []byte variable that stores the value of the flag.

func (*FlagSet)BytesBase64Padded inv1.0.2

func (f *FlagSet) BytesBase64P(name, shorthandstring, value []byte, usagestring) *[]byte

BytesBase64P is like BytesBase64, but accepts a shorthand letter that can be used after a single dash.

func (*FlagSet)BytesBase64Varadded inv1.0.2

func (f *FlagSet) BytesBase64Var(p *[]byte, namestring, value []byte, usagestring)

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)BytesBase64VarPadded inv1.0.2

func (f *FlagSet) BytesBase64VarP(p *[]byte, name, shorthandstring, value []byte, usagestring)

BytesBase64VarP is like BytesBase64Var, but accepts a shorthand letter that can be used after a single dash.

func (*FlagSet)BytesHexadded inv1.0.1

func (f *FlagSet) BytesHex(namestring, value []byte, usagestring) *[]byte

BytesHex defines an []byte flag with specified name, default value, and usage string.The return value is the address of an []byte variable that stores the value of the flag.

func (*FlagSet)BytesHexPadded inv1.0.1

func (f *FlagSet) BytesHexP(name, shorthandstring, value []byte, usagestring) *[]byte

BytesHexP is like BytesHex, but accepts a shorthand letter that can be used after a single dash.

func (*FlagSet)BytesHexVaradded inv1.0.1

func (f *FlagSet) BytesHexVar(p *[]byte, namestring, value []byte, usagestring)

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)BytesHexVarPadded inv1.0.1

func (f *FlagSet) BytesHexVarP(p *[]byte, name, shorthandstring, value []byte, usagestring)

BytesHexVarP is like BytesHexVar, but accepts a shorthand letter that can be used after a single dash.

func (*FlagSet)Changed

func (f *FlagSet) Changed(namestring)bool

Changed returns true if the flag was explicitly set during Parse() and falseotherwise

func (*FlagSet)CopyToGoFlagSetadded inv1.0.8

func (f *FlagSet) CopyToGoFlagSet(newSet *goflag.FlagSet)

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

func (f *FlagSet) Count(namestring, usagestring) *int

Count defines a count flag with specified name, default value, and usage string.The return value is the address of an int variable that stores the value of the flag.A count flag will add 1 to its value every time it is found on the command line

func (*FlagSet)CountP

func (f *FlagSet) CountP(name, shorthandstring, usagestring) *int

CountP is like Count only takes a shorthand for the flag name.

func (*FlagSet)CountVar

func (f *FlagSet) CountVar(p *int, namestring, usagestring)

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)CountVarP

func (f *FlagSet) CountVarP(p *int, name, shorthandstring, usagestring)

CountVarP is like CountVar only take a shorthand for the flag name.

func (*FlagSet)Duration

func (f *FlagSet) Duration(namestring, valuetime.Duration, usagestring) *time.Duration

Duration defines a time.Duration flag with specified name, default value, and usage string.The return value is the address of a time.Duration variable that stores the value of the flag.

func (*FlagSet)DurationP

func (f *FlagSet) DurationP(name, shorthandstring, valuetime.Duration, usagestring) *time.Duration

DurationP is like Duration, but accepts a shorthand letter that can be used after a single dash.

func (*FlagSet)DurationSliceadded inv1.0.1

func (f *FlagSet) DurationSlice(namestring, value []time.Duration, usagestring) *[]time.Duration

DurationSlice defines a []time.Duration flag with specified name, default value, and usage string.The return value is the address of a []time.Duration variable that stores the value of the flag.

func (*FlagSet)DurationSlicePadded 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)DurationSliceVaradded 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)DurationSliceVarPadded 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

func (f *FlagSet) DurationVar(p *time.Duration, namestring, valuetime.Duration, usagestring)

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

func (f *FlagSet) FlagUsages()string

FlagUsages returns a string containing the usage information for all flags inthe FlagSet

func (*FlagSet)FlagUsagesWrapped

func (f *FlagSet) FlagUsagesWrapped(colsint)string

FlagUsagesWrapped returns a string containing the usage informationfor all flags in the FlagSet. Wrapped to `cols` columns (0 for nowrapping)

func (*FlagSet)Float32

func (f *FlagSet) Float32(namestring, valuefloat32, usagestring) *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

func (f *FlagSet) Float32P(name, shorthandstring, valuefloat32, usagestring) *float32

Float32P is like Float32, but accepts a shorthand letter that can be used after a single dash.

func (*FlagSet)Float32Sliceadded inv1.0.5

func (f *FlagSet) Float32Slice(namestring, value []float32, usagestring) *[]float32

Float32Slice defines a []float32 flag with specified name, default value, and usage string.The return value is the address of a []float32 variable that stores the value of the flag.

func (*FlagSet)Float32SlicePadded inv1.0.5

func (f *FlagSet) Float32SliceP(name, shorthandstring, value []float32, usagestring) *[]float32

Float32SliceP is like Float32Slice, but accepts a shorthand letter that can be used after a single dash.

func (*FlagSet)Float32SliceVaradded inv1.0.5

func (f *FlagSet) Float32SliceVar(p *[]float32, namestring, value []float32, usagestring)

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)Float32SliceVarPadded 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

func (f *FlagSet) Float32Var(p *float32, namestring, valuefloat32, usagestring)

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

func (f *FlagSet) Float32VarP(p *float32, name, shorthandstring, valuefloat32, usagestring)

Float32VarP is like Float32Var, but accepts a shorthand letter that can be used after a single dash.

func (*FlagSet)Float64

func (f *FlagSet) Float64(namestring, valuefloat64, usagestring) *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

func (f *FlagSet) Float64P(name, shorthandstring, valuefloat64, usagestring) *float64

Float64P is like Float64, but accepts a shorthand letter that can be used after a single dash.

func (*FlagSet)Float64Sliceadded inv1.0.5

func (f *FlagSet) Float64Slice(namestring, value []float64, usagestring) *[]float64

Float64Slice defines a []float64 flag with specified name, default value, and usage string.The return value is the address of a []float64 variable that stores the value of the flag.

func (*FlagSet)Float64SlicePadded inv1.0.5

func (f *FlagSet) Float64SliceP(name, shorthandstring, value []float64, usagestring) *[]float64

Float64SliceP is like Float64Slice, but accepts a shorthand letter that can be used after a single dash.

func (*FlagSet)Float64SliceVaradded inv1.0.5

func (f *FlagSet) Float64SliceVar(p *[]float64, namestring, value []float64, usagestring)

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)Float64SliceVarPadded 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

func (f *FlagSet) Float64Var(p *float64, namestring, valuefloat64, usagestring)

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

func (f *FlagSet) Float64VarP(p *float64, name, shorthandstring, valuefloat64, usagestring)

Float64VarP is like Float64Var, but accepts a shorthand letter that can be used after a single dash.

func (*FlagSet)Funcadded inv1.0.7

func (f *FlagSet) Func(namestring, usagestring, fn func(string)error)

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)FuncPadded inv1.0.7

func (f *FlagSet) FuncP(namestring, shorthandstring, usagestring, fn func(string)error)

FuncP is like Func, but accepts a shorthand letter that can be used after a single dash.

func (*FlagSet)GetBool

func (f *FlagSet) GetBool(namestring) (bool,error)

GetBool return the bool value of a flag with the given name

func (*FlagSet)GetBoolSlice

func (f *FlagSet) GetBoolSlice(namestring) ([]bool,error)

GetBoolSlice returns the []bool value of a flag with the given name.

func (*FlagSet)GetBytesBase64added inv1.0.2

func (f *FlagSet) GetBytesBase64(namestring) ([]byte,error)

GetBytesBase64 return the []byte value of a flag with the given name

func (*FlagSet)GetBytesHexadded inv1.0.1

func (f *FlagSet) GetBytesHex(namestring) ([]byte,error)

GetBytesHex return the []byte value of a flag with the given name

func (*FlagSet)GetCount

func (f *FlagSet) GetCount(namestring) (int,error)

GetCount return the int value of a flag with the given name

func (*FlagSet)GetDuration

func (f *FlagSet) GetDuration(namestring) (time.Duration,error)

GetDuration return the duration value of a flag with the given name

func (*FlagSet)GetDurationSliceadded inv1.0.1

func (f *FlagSet) GetDurationSlice(namestring) ([]time.Duration,error)

GetDurationSlice returns the []time.Duration value of a flag with the given name

func (*FlagSet)GetFloat32

func (f *FlagSet) GetFloat32(namestring) (float32,error)

GetFloat32 return the float32 value of a flag with the given name

func (*FlagSet)GetFloat32Sliceadded inv1.0.5

func (f *FlagSet) GetFloat32Slice(namestring) ([]float32,error)

GetFloat32Slice return the []float32 value of a flag with the given name

func (*FlagSet)GetFloat64

func (f *FlagSet) GetFloat64(namestring) (float64,error)

GetFloat64 return the float64 value of a flag with the given name

func (*FlagSet)GetFloat64Sliceadded inv1.0.5

func (f *FlagSet) GetFloat64Slice(namestring) ([]float64,error)

GetFloat64Slice return the []float64 value of a flag with the given name

func (*FlagSet)GetIP

func (f *FlagSet) GetIP(namestring) (net.IP,error)

GetIP return the net.IP value of a flag with the given name

func (*FlagSet)GetIPNet

func (f *FlagSet) GetIPNet(namestring) (net.IPNet,error)

GetIPNet return the net.IPNet value of a flag with the given name

func (*FlagSet)GetIPNetSliceadded inv1.0.6

func (f *FlagSet) GetIPNetSlice(namestring) ([]net.IPNet,error)

GetIPNetSlice returns the []net.IPNet value of a flag with the given name

func (*FlagSet)GetIPSlice

func (f *FlagSet) GetIPSlice(namestring) ([]net.IP,error)

GetIPSlice returns the []net.IP value of a flag with the given name

func (*FlagSet)GetIPv4Mask

func (f *FlagSet) GetIPv4Mask(namestring) (net.IPMask,error)

GetIPv4Mask return the net.IPv4Mask value of a flag with the given name

func (*FlagSet)GetInt

func (f *FlagSet) GetInt(namestring) (int,error)

GetInt return the int value of a flag with the given name

func (*FlagSet)GetInt16added inv1.0.1

func (f *FlagSet) GetInt16(namestring) (int16,error)

GetInt16 returns the int16 value of a flag with the given name

func (*FlagSet)GetInt32

func (f *FlagSet) GetInt32(namestring) (int32,error)

GetInt32 return the int32 value of a flag with the given name

func (*FlagSet)GetInt32Sliceadded inv1.0.5

func (f *FlagSet) GetInt32Slice(namestring) ([]int32,error)

GetInt32Slice return the []int32 value of a flag with the given name

func (*FlagSet)GetInt64

func (f *FlagSet) GetInt64(namestring) (int64,error)

GetInt64 return the int64 value of a flag with the given name

func (*FlagSet)GetInt64Sliceadded inv1.0.5

func (f *FlagSet) GetInt64Slice(namestring) ([]int64,error)

GetInt64Slice return the []int64 value of a flag with the given name

func (*FlagSet)GetInt8

func (f *FlagSet) GetInt8(namestring) (int8,error)

GetInt8 return the int8 value of a flag with the given name

func (*FlagSet)GetIntSlice

func (f *FlagSet) GetIntSlice(namestring) ([]int,error)

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)GetString

func (f *FlagSet) GetString(namestring) (string,error)

GetString return the string value of a flag with the given name

func (*FlagSet)GetStringArray

func (f *FlagSet) GetStringArray(namestring) ([]string,error)

GetStringArray return the []string value of a flag with the given name

func (*FlagSet)GetStringSlice

func (f *FlagSet) GetStringSlice(namestring) ([]string,error)

GetStringSlice return the []string value of a flag with the given name

func (*FlagSet)GetStringToIntadded inv1.0.3

func (f *FlagSet) GetStringToInt(namestring) (map[string]int,error)

GetStringToInt return the map[string]int value of a flag with the given name

func (*FlagSet)GetStringToInt64added inv1.0.5

func (f *FlagSet) GetStringToInt64(namestring) (map[string]int64,error)

GetStringToInt64 return the map[string]int64 value of a flag with the given name

func (*FlagSet)GetStringToStringadded inv1.0.3

func (f *FlagSet) GetStringToString(namestring) (map[string]string,error)

GetStringToString return the map[string]string value of a flag with the given name

func (*FlagSet)GetTextadded 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)GetTimeadded inv1.0.7

func (f *FlagSet) GetTime(namestring) (time.Time,error)

GetTime return the time value of a flag with the given name

func (*FlagSet)GetUint

func (f *FlagSet) GetUint(namestring) (uint,error)

GetUint return the uint value of a flag with the given name

func (*FlagSet)GetUint16

func (f *FlagSet) GetUint16(namestring) (uint16,error)

GetUint16 return the uint16 value of a flag with the given name

func (*FlagSet)GetUint32

func (f *FlagSet) GetUint32(namestring) (uint32,error)

GetUint32 return the uint32 value of a flag with the given name

func (*FlagSet)GetUint64

func (f *FlagSet) GetUint64(namestring) (uint64,error)

GetUint64 return the uint64 value of a flag with the given name

func (*FlagSet)GetUint8

func (f *FlagSet) GetUint8(namestring) (uint8,error)

GetUint8 return the uint8 value of a flag with the given name

func (*FlagSet)GetUintSlice

func (f *FlagSet) GetUintSlice(namestring) ([]uint,error)

GetUintSlice returns the []uint value of a flag with the given name.

func (*FlagSet)HasAvailableFlags

func (f *FlagSet) HasAvailableFlags()bool

HasAvailableFlags returns a bool to indicate if the FlagSet has any flagsthat are not hidden.

func (*FlagSet)HasFlags

func (f *FlagSet) HasFlags()bool

HasFlags returns a bool to indicate if the FlagSet has any flags defined.

func (*FlagSet)IP

func (f *FlagSet) IP(namestring, valuenet.IP, usagestring) *net.IP

IP defines an net.IP flag with specified name, default value, and usage string.The return value is the address of an net.IP variable that stores the value of the flag.

func (*FlagSet)IPMask

func (f *FlagSet) IPMask(namestring, valuenet.IPMask, usagestring) *net.IPMask

IPMask defines an net.IPMask flag with specified name, default value, and usage string.The return value is the address of an net.IPMask variable that stores the value of the flag.

func (*FlagSet)IPMaskP

func (f *FlagSet) IPMaskP(name, shorthandstring, valuenet.IPMask, usagestring) *net.IPMask

IPMaskP is like IPMask, but accepts a shorthand letter that can be used after a single dash.

func (*FlagSet)IPMaskVar

func (f *FlagSet) IPMaskVar(p *net.IPMask, namestring, valuenet.IPMask, usagestring)

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

func (f *FlagSet) IPMaskVarP(p *net.IPMask, name, shorthandstring, valuenet.IPMask, usagestring)

IPMaskVarP is like IPMaskVar, but accepts a shorthand letter that can be used after a single dash.

func (*FlagSet)IPNet

func (f *FlagSet) IPNet(namestring, valuenet.IPNet, usagestring) *net.IPNet

IPNet defines an net.IPNet flag with specified name, default value, and usage string.The return value is the address of an net.IPNet variable that stores the value of the flag.

func (*FlagSet)IPNetP

func (f *FlagSet) IPNetP(name, shorthandstring, valuenet.IPNet, usagestring) *net.IPNet

IPNetP is like IPNet, but accepts a shorthand letter that can be used after a single dash.

func (*FlagSet)IPNetSliceadded inv1.0.6

func (f *FlagSet) IPNetSlice(namestring, value []net.IPNet, usagestring) *[]net.IPNet

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)IPNetSlicePadded inv1.0.6

func (f *FlagSet) IPNetSliceP(name, shorthandstring, value []net.IPNet, usagestring) *[]net.IPNet

IPNetSliceP is like IPNetSlice, but accepts a shorthand letter that can be used after a single dash.

func (*FlagSet)IPNetSliceVaradded inv1.0.6

func (f *FlagSet) IPNetSliceVar(p *[]net.IPNet, namestring, value []net.IPNet, usagestring)

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)IPNetSliceVarPadded 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

func (f *FlagSet) IPNetVar(p *net.IPNet, namestring, valuenet.IPNet, usagestring)

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

func (f *FlagSet) IPNetVarP(p *net.IPNet, name, shorthandstring, valuenet.IPNet, usagestring)

IPNetVarP is like IPNetVar, but accepts a shorthand letter that can be used after a single dash.

func (*FlagSet)IPP

func (f *FlagSet) IPP(name, shorthandstring, valuenet.IP, usagestring) *net.IP

IPP is like IP, but accepts a shorthand letter that can be used after a single dash.

func (*FlagSet)IPSlice

func (f *FlagSet) IPSlice(namestring, value []net.IP, usagestring) *[]net.IP

IPSlice defines a []net.IP flag with specified name, default value, and usage string.The return value is the address of a []net.IP variable that stores the value of that flag.

func (*FlagSet)IPSliceP

func (f *FlagSet) IPSliceP(name, shorthandstring, value []net.IP, usagestring) *[]net.IP

IPSliceP is like IPSlice, but accepts a shorthand letter that can be used after a single dash.

func (*FlagSet)IPSliceVar

func (f *FlagSet) IPSliceVar(p *[]net.IP, namestring, value []net.IP, usagestring)

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

func (f *FlagSet) IPSliceVarP(p *[]net.IP, name, shorthandstring, value []net.IP, usagestring)

IPSliceVarP is like IPSliceVar, but accepts a shorthand letter that can be used after a single dash.

func (*FlagSet)IPVar

func (f *FlagSet) IPVar(p *net.IP, namestring, valuenet.IP, usagestring)

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

func (f *FlagSet) IPVarP(p *net.IP, name, shorthandstring, valuenet.IP, usagestring)

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

func (f *FlagSet) Int(namestring, valueint, usagestring) *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)Int16added inv1.0.1

func (f *FlagSet) Int16(namestring, valueint16, usagestring) *int16

Int16 defines an int16 flag with specified name, default value, and usage string.The return value is the address of an int16 variable that stores the value of the flag.

func (*FlagSet)Int16Padded inv1.0.1

func (f *FlagSet) Int16P(name, shorthandstring, valueint16, usagestring) *int16

Int16P is like Int16, but accepts a shorthand letter that can be used after a single dash.

func (*FlagSet)Int16Varadded inv1.0.1

func (f *FlagSet) Int16Var(p *int16, namestring, valueint16, usagestring)

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)Int16VarPadded inv1.0.1

func (f *FlagSet) Int16VarP(p *int16, name, shorthandstring, valueint16, usagestring)

Int16VarP is like Int16Var, but accepts a shorthand letter that can be used after a single dash.

func (*FlagSet)Int32

func (f *FlagSet) Int32(namestring, valueint32, usagestring) *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

func (f *FlagSet) Int32P(name, shorthandstring, valueint32, usagestring) *int32

Int32P is like Int32, but accepts a shorthand letter that can be used after a single dash.

func (*FlagSet)Int32Sliceadded inv1.0.5

func (f *FlagSet) Int32Slice(namestring, value []int32, usagestring) *[]int32

Int32Slice defines a []int32 flag with specified name, default value, and usage string.The return value is the address of a []int32 variable that stores the value of the flag.

func (*FlagSet)Int32SlicePadded inv1.0.5

func (f *FlagSet) Int32SliceP(name, shorthandstring, value []int32, usagestring) *[]int32

Int32SliceP is like Int32Slice, but accepts a shorthand letter that can be used after a single dash.

func (*FlagSet)Int32SliceVaradded inv1.0.5

func (f *FlagSet) Int32SliceVar(p *[]int32, namestring, value []int32, usagestring)

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)Int32SliceVarPadded inv1.0.5

func (f *FlagSet) Int32SliceVarP(p *[]int32, name, shorthandstring, value []int32, usagestring)

Int32SliceVarP is like Int32SliceVar, but accepts a shorthand letter that can be used after a single dash.

func (*FlagSet)Int32Var

func (f *FlagSet) Int32Var(p *int32, namestring, valueint32, usagestring)

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

func (f *FlagSet) Int32VarP(p *int32, name, shorthandstring, valueint32, usagestring)

Int32VarP is like Int32Var, but accepts a shorthand letter that can be used after a single dash.

func (*FlagSet)Int64

func (f *FlagSet) Int64(namestring, valueint64, usagestring) *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

func (f *FlagSet) Int64P(name, shorthandstring, valueint64, usagestring) *int64

Int64P is like Int64, but accepts a shorthand letter that can be used after a single dash.

func (*FlagSet)Int64Sliceadded inv1.0.5

func (f *FlagSet) Int64Slice(namestring, value []int64, usagestring) *[]int64

Int64Slice defines a []int64 flag with specified name, default value, and usage string.The return value is the address of a []int64 variable that stores the value of the flag.

func (*FlagSet)Int64SlicePadded inv1.0.5

func (f *FlagSet) Int64SliceP(name, shorthandstring, value []int64, usagestring) *[]int64

Int64SliceP is like Int64Slice, but accepts a shorthand letter that can be used after a single dash.

func (*FlagSet)Int64SliceVaradded inv1.0.5

func (f *FlagSet) Int64SliceVar(p *[]int64, namestring, value []int64, usagestring)

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)Int64SliceVarPadded inv1.0.5

func (f *FlagSet) Int64SliceVarP(p *[]int64, name, shorthandstring, value []int64, usagestring)

Int64SliceVarP is like Int64SliceVar, but accepts a shorthand letter that can be used after a single dash.

func (*FlagSet)Int64Var

func (f *FlagSet) Int64Var(p *int64, namestring, valueint64, usagestring)

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

func (f *FlagSet) Int64VarP(p *int64, name, shorthandstring, valueint64, usagestring)

Int64VarP is like Int64Var, but accepts a shorthand letter that can be used after a single dash.

func (*FlagSet)Int8

func (f *FlagSet) Int8(namestring, valueint8, usagestring) *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

func (f *FlagSet) Int8P(name, shorthandstring, valueint8, usagestring) *int8

Int8P is like Int8, but accepts a shorthand letter that can be used after a single dash.

func (*FlagSet)Int8Var

func (f *FlagSet) Int8Var(p *int8, namestring, valueint8, usagestring)

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

func (f *FlagSet) Int8VarP(p *int8, name, shorthandstring, valueint8, usagestring)

Int8VarP is like Int8Var, but accepts a shorthand letter that can be used after a single dash.

func (*FlagSet)IntP

func (f *FlagSet) IntP(name, shorthandstring, valueint, usagestring) *int

IntP is like Int, but accepts a shorthand letter that can be used after a single dash.

func (*FlagSet)IntSlice

func (f *FlagSet) IntSlice(namestring, value []int, usagestring) *[]int

IntSlice defines a []int flag with specified name, default value, and usage string.The return value is the address of a []int variable that stores the value of the flag.

func (*FlagSet)IntSliceP

func (f *FlagSet) IntSliceP(name, shorthandstring, value []int, usagestring) *[]int

IntSliceP is like IntSlice, but accepts a shorthand letter that can be used after a single dash.

func (*FlagSet)IntSliceVar

func (f *FlagSet) IntSliceVar(p *[]int, namestring, value []int, usagestring)

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

func (f *FlagSet) IntSliceVarP(p *[]int, name, shorthandstring, value []int, usagestring)

IntSliceVarP is like IntSliceVar, but accepts a shorthand letter that can be used after a single dash.

func (*FlagSet)IntVar

func (f *FlagSet) IntVar(p *int, namestring, valueint, usagestring)

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

func (f *FlagSet) IntVarP(p *int, name, shorthandstring, valueint, usagestring)

IntVarP is like IntVar, but accepts a shorthand letter that can be used after a single dash.

func (*FlagSet)Lookup

func (f *FlagSet) Lookup(namestring) *Flag

Lookup returns the Flag structure of the named flag, returning nil if none exists.

func (*FlagSet)MarkDeprecated

func (f *FlagSet) MarkDeprecated(namestring, usageMessagestring)error

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

func (f *FlagSet) MarkHidden(namestring)error

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

func (f *FlagSet) MarkShorthandDeprecated(namestring, usageMessagestring)error

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)NArg

func (f *FlagSet) NArg()int

NArg is the number of arguments remaining after flags have been processed.

func (*FlagSet)NFlag

func (f *FlagSet) NFlag()int

NFlag returns the number of flags that have been set.

func (*FlagSet)Nameadded inv1.0.6

func (f *FlagSet) Name()string

Name returns the name of the flag set.

func (*FlagSet)Outputadded inv1.0.6

func (f *FlagSet) Output()io.Writer

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

func (f *FlagSet) Parse(arguments []string)error

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

func (f *FlagSet) ParseAll(arguments []string, fn func(flag *Flag, valuestring)error)error

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)Parsed

func (f *FlagSet) Parsed()bool

Parsed reports whether f.Parse has been called.

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)Set

func (f *FlagSet) Set(name, valuestring)error

Set sets the value of the named flag.

func (*FlagSet)SetAnnotation

func (f *FlagSet) SetAnnotation(name, keystring, values []string)error

SetAnnotation allows one to set arbitrary annotations on a flag in the FlagSet.This is sometimes used by spf13/cobra programs which want to generate additionalbash completion information.

func (*FlagSet)SetInterspersed

func (f *FlagSet) SetInterspersed(interspersedbool)

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

func (f *FlagSet) SetOutput(outputio.Writer)

SetOutput sets the destination for usage and error messages.If output is nil, os.Stderr is used.

func (*FlagSet)ShorthandLookup

func (f *FlagSet) ShorthandLookup(namestring) *Flag

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

func (f *FlagSet) String(namestring, valuestring, usagestring) *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

func (f *FlagSet) StringArray(namestring, value []string, usagestring) *[]string

StringArray defines a string flag with specified name, default value, and usage string.The return value is the address of a []string variable that stores the value of the flag.The value of each argument will not try to be separated by comma. Use a StringSlice for that.

func (*FlagSet)StringArrayP

func (f *FlagSet) StringArrayP(name, shorthandstring, value []string, usagestring) *[]string

StringArrayP is like StringArray, but accepts a shorthand letter that can be used after a single dash.

func (*FlagSet)StringArrayVar

func (f *FlagSet) StringArrayVar(p *[]string, namestring, value []string, usagestring)

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

func (f *FlagSet) StringArrayVarP(p *[]string, name, shorthandstring, value []string, usagestring)

StringArrayVarP is like StringArrayVar, but accepts a shorthand letter that can be used after a single dash.

func (*FlagSet)StringP

func (f *FlagSet) StringP(name, shorthandstring, valuestring, usagestring) *string

StringP is like String, but accepts a shorthand letter that can be used after a single dash.

func (*FlagSet)StringSlice

func (f *FlagSet) StringSlice(namestring, value []string, usagestring) *[]string

StringSlice defines a string flag with specified name, default value, and usage string.The return value is the address of a []string variable that stores the value of the flag.Compared to StringArray flags, StringSlice flags take comma-separated value as arguments and split them accordingly.For example:

--ss="v1,v2" --ss="v3"

will result in

[]string{"v1", "v2", "v3"}

func (*FlagSet)StringSliceP

func (f *FlagSet) StringSliceP(name, shorthandstring, value []string, usagestring) *[]string

StringSliceP is like StringSlice, but accepts a shorthand letter that can be used after a single dash.

func (*FlagSet)StringSliceVar

func (f *FlagSet) StringSliceVar(p *[]string, namestring, value []string, usagestring)

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

func (f *FlagSet) StringSliceVarP(p *[]string, name, shorthandstring, value []string, usagestring)

StringSliceVarP is like StringSliceVar, but accepts a shorthand letter that can be used after a single dash.

func (*FlagSet)StringToIntadded inv1.0.3

func (f *FlagSet) StringToInt(namestring, value map[string]int, usagestring) *map[string]int

StringToInt defines a string flag with specified name, default value, and usage string.The return value is the address of a map[string]int variable that stores the value of the flag.The value of each argument will not try to be separated by comma

func (*FlagSet)StringToInt64added inv1.0.5

func (f *FlagSet) StringToInt64(namestring, value map[string]int64, usagestring) *map[string]int64

StringToInt64 defines a string flag with specified name, default value, and usage string.The return value is the address of a map[string]int64 variable that stores the value of the flag.The value of each argument will not try to be separated by comma

func (*FlagSet)StringToInt64Padded 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)StringToInt64Varadded 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)StringToInt64VarPadded 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)StringToIntPadded 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)StringToIntVaradded inv1.0.3

func (f *FlagSet) StringToIntVar(p *map[string]int, namestring, value map[string]int, usagestring)

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)StringToIntVarPadded 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)StringToStringadded 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)StringToStringPadded 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)StringToStringVaradded 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)StringToStringVarPadded 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

func (f *FlagSet) StringVar(p *string, namestring, valuestring, usagestring)

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

func (f *FlagSet) StringVarP(p *string, name, shorthandstring, valuestring, usagestring)

StringVarP is like StringVar, but accepts a shorthand letter that can be used after a single dash.

func (*FlagSet)TextVaradded 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)TextVarPadded 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)Timeadded inv1.0.7

func (f *FlagSet) Time(namestring, valuetime.Time, formats []string, usagestring) *time.Time

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)TimePadded 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)TimeVaradded inv1.0.7

func (f *FlagSet) TimeVar(p *time.Time, namestring, valuetime.Time, formats []string, usagestring)

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)TimeVarPadded 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

func (f *FlagSet) Uint(namestring, valueuint, usagestring) *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

func (f *FlagSet) Uint16(namestring, valueuint16, usagestring) *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

func (f *FlagSet) Uint16P(name, shorthandstring, valueuint16, usagestring) *uint16

Uint16P is like Uint16, but accepts a shorthand letter that can be used after a single dash.

func (*FlagSet)Uint16Var

func (f *FlagSet) Uint16Var(p *uint16, namestring, valueuint16, usagestring)

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

func (f *FlagSet) Uint16VarP(p *uint16, name, shorthandstring, valueuint16, usagestring)

Uint16VarP is like Uint16Var, but accepts a shorthand letter that can be used after a single dash.

func (*FlagSet)Uint32

func (f *FlagSet) Uint32(namestring, valueuint32, usagestring) *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

func (f *FlagSet) Uint32P(name, shorthandstring, valueuint32, usagestring) *uint32

Uint32P is like Uint32, but accepts a shorthand letter that can be used after a single dash.

func (*FlagSet)Uint32Var

func (f *FlagSet) Uint32Var(p *uint32, namestring, valueuint32, usagestring)

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

func (f *FlagSet) Uint32VarP(p *uint32, name, shorthandstring, valueuint32, usagestring)

Uint32VarP is like Uint32Var, but accepts a shorthand letter that can be used after a single dash.

func (*FlagSet)Uint64

func (f *FlagSet) Uint64(namestring, valueuint64, usagestring) *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

func (f *FlagSet) Uint64P(name, shorthandstring, valueuint64, usagestring) *uint64

Uint64P is like Uint64, but accepts a shorthand letter that can be used after a single dash.

func (*FlagSet)Uint64Var

func (f *FlagSet) Uint64Var(p *uint64, namestring, valueuint64, usagestring)

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

func (f *FlagSet) Uint64VarP(p *uint64, name, shorthandstring, valueuint64, usagestring)

Uint64VarP is like Uint64Var, but accepts a shorthand letter that can be used after a single dash.

func (*FlagSet)Uint8

func (f *FlagSet) Uint8(namestring, valueuint8, usagestring) *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

func (f *FlagSet) Uint8P(name, shorthandstring, valueuint8, usagestring) *uint8

Uint8P is like Uint8, but accepts a shorthand letter that can be used after a single dash.

func (*FlagSet)Uint8Var

func (f *FlagSet) Uint8Var(p *uint8, namestring, valueuint8, usagestring)

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

func (f *FlagSet) Uint8VarP(p *uint8, name, shorthandstring, valueuint8, usagestring)

Uint8VarP is like Uint8Var, but accepts a shorthand letter that can be used after a single dash.

func (*FlagSet)UintP

func (f *FlagSet) UintP(name, shorthandstring, valueuint, usagestring) *uint

UintP is like Uint, but accepts a shorthand letter that can be used after a single dash.

func (*FlagSet)UintSlice

func (f *FlagSet) UintSlice(namestring, value []uint, usagestring) *[]uint

UintSlice defines a []uint flag with specified name, default value, and usage string.The return value is the address of a []uint variable that stores the value of the flag.

func (*FlagSet)UintSliceP

func (f *FlagSet) UintSliceP(name, shorthandstring, value []uint, usagestring) *[]uint

UintSliceP is like UintSlice, but accepts a shorthand letter that can be used after a single dash.

func (*FlagSet)UintSliceVar

func (f *FlagSet) UintSliceVar(p *[]uint, namestring, value []uint, usagestring)

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

func (f *FlagSet) UintSliceVarP(p *[]uint, name, shorthandstring, value []uint, usagestring)

UintSliceVarP is like UintSliceVar, but accepts a shorthand letter that can be used after a single dash.

func (*FlagSet)UintVar

func (f *FlagSet) UintVar(p *uint, namestring, valueuint, usagestring)

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

func (f *FlagSet) UintVarP(p *uint, name, shorthandstring, valueuint, usagestring)

UintVarP is like UintVar, but accepts a shorthand letter that can be used after a single dash.

func (*FlagSet)Var

func (f *FlagSet) Var(valueValue, namestring, usagestring)

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

func (f *FlagSet) VarP(valueValue, name, shorthand, usagestring)

VarP is like Var, but accepts a shorthand letter that can be used after a single dash.

func (*FlagSet)VarPF

func (f *FlagSet) VarPF(valueValue, name, shorthand, usagestring) *Flag

VarPF is like VarP, but returns the flag created

func (*FlagSet)Visit

func (f *FlagSet) Visit(fn func(*Flag))

Visit visits the flags in lexicographical order orin primordial order if f.SortFlags is false, calling fn for each.It visits only those flags that have been set.

func (*FlagSet)VisitAll

func (f *FlagSet) VisitAll(fn func(*Flag))

VisitAll visits the flags in lexicographical order orin primordial order if f.SortFlags is false, calling fn for each.It visits all flags, even those not set.

typeInvalidSyntaxErroradded 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)Erroradded inv1.0.7

func (e *InvalidSyntaxError) Error()string

Error implements error.

func (*InvalidSyntaxError)GetSpecifiedFlagadded inv1.0.7

func (e *InvalidSyntaxError) GetSpecifiedFlag()string

GetSpecifiedName returns the exact flag (with dashes) as itappeared in the parsed arguments.

typeInvalidValueErroradded 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)Erroradded inv1.0.7

func (e *InvalidValueError) Error()string

Error implements error.

func (*InvalidValueError)GetFlagadded inv1.0.7

func (e *InvalidValueError) GetFlag() *Flag

GetFlag returns the flag for which the error occurred.

func (*InvalidValueError)GetValueadded inv1.0.7

func (e *InvalidValueError) GetValue()string

GetValue returns the invalid value that was provided.

func (*InvalidValueError)Unwrapadded 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).

typeNotExistErroradded 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)Erroradded inv1.0.7

func (e *NotExistError) Error()string

Error implements error.

func (*NotExistError)GetSpecifiedNameadded 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)GetSpecifiedShortnamesadded 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.

typeParseErrorsAllowlistadded 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.

typeSliceValueadded 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

type Value interface {String()stringSet(string)errorType()string}

Value is the interface to the dynamic value stored in a flag.(The default value is represented as a string.)

typeValueRequiredErroradded 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)Erroradded inv1.0.7

func (e *ValueRequiredError) Error()string

Error implements error.

func (*ValueRequiredError)GetFlagadded inv1.0.7

func (e *ValueRequiredError) GetFlag() *Flag

GetFlag returns the flag for which the error occurred.

func (*ValueRequiredError)GetSpecifiedNameadded 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)GetSpecifiedShortnamesadded 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

View all Source files

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f orF : Jump to
y orY : Canonical URL
go.dev uses cookies from Google to deliver and enhance the quality of its services and to analyze traffic.Learn more.

[8]ページ先頭

©2009-2025 Movatter.jp