pflag
39 分钟阅读
pflag
描述
pflag是Go语言的flag
包的一个替代品,实现了POSIX/GNU风格的--flags
。
pflag兼容GNU对命令行选项的POSIX建议的扩展。更详细的描述请参见下面的"命令行标志语法"部分。
pflag采用与Go语言相同的BSD许可证授权,许可证的内容可以在LICENSE文件中找到。
安装
使用标准的go get
命令可以获取pflag。
运行以下命令进行安装:
go get github.com/spf13/pflag
运行以下命令进行测试:
go test github.com/spf13/pflag
用法
pflag是Go原生flag
包的一个替代品。如果您将pflag导入为"flag",则所有的代码都应该继续正常工作,无需进行任何更改。
import flag "github.com/spf13/pflag"
有一个例外情况:如果您直接实例化Flag结构体,还需要设置一个额外的字段"Shorthand"。大多数代码不会直接实例化这个结构体,而是使用诸如String()、BoolVar()和Var()等函数,因此不受影响。
使用flag.String()、Bool()、Int()等函数来定义标志。
以下是一个声明整数标志的示例,标志名为-flagname
,存储在指针ip
中,类型为*int
。
var ip *int = flag.Int("flagname", 1234, "help message for flagname")
如果需要,您可以使用Var()函数将标志绑定到一个变量上。
var flagvar int
func init() {
flag.IntVar(&flagvar, "flagname", 1234, "help message for flagname")
}
或者您可以创建满足Value接口的自定义标志(使用指针接收器),并通过以下方式将它们与标志解析相关联:
flag.Var(&flagVal, "name", "help message for flagname")
对于这样的标志,其默认值就是变量的初始值。
在定义所有标志后,调用
flag.Parse()
来将命令行解析进已定义的标志。
然后可以直接使用标志。如果使用的是标志本身,则它们都是指针;如果绑定到变量,则它们是值。
fmt.Println("ip has value ", *ip)
fmt.Println("flagvar has value ", flagvar)
如果您使用 FlagSet
,并且发现在代码中跟踪所有指针变得困难,那么可以使用一些辅助函数来获取 Flag
(结构体) 中存储的值如果您有一个名为’flagname’、类型为int
的pflag.FlagSet
,您可以使用GetInt()
来获取int值。但请注意,‘flagname’必须存在且为int类型,否则GetString("flagname")
将失败。
i, err := flagset.GetInt("flagname")
在解析后,该标志之后的实参可以作为flag.Args()
的切片或作为flag.Arg(i)
单独使用。实参的索引范围是从0到flag.NArg()-1
。
pflag包还定义了一些在 flag
包中不存在的新函数,它们为标志提供了一字母缩写。您可以通过在定义标志的任何函数名称后附加 ‘P
’ 来使用这些函数。
var ip = flag.IntP("flagname", "f", 1234, "help message")
var flagvar bool
func init() {
flag.BoolVarP(&flagvar, "boolname", "b", true, "help message")
}
flag.VarP(&flagVal, "varname", "v", "help message")
缩写字母可以在命令行上使用单破折号。布尔型缩写标志可以与其他缩写标志结合使用。
默认的命令行标志集由顶层函数控制。FlagSet类型允许定义独立的标志集,例如在命令行接口中实现子命令。FlagSet的方法类似于顶层函数用于命令行标志集的方法。
Setting no option default values for flags 为标志设置无选项默认值
After you create a flag it is possible to set the pflag.NoOptDefVal for the given flag. Doing this changes the meaning of the flag slightly. If a flag has a NoOptDefVal and the flag is set on the command line without an option the flag will be set to the NoOptDefVal. For example given:
在创建标志后,可以为给定的标志设置pflag.NoOptDefVal。这样做会略微改变标志的含义。如果一个标志具有NoOptDefVal,并且在命令行上设置该标志而没有选项,那么该标志将被设置为NoOptDefVal。例如:
var ip = flag.IntP("flagname", "f", 1234, "help message")
flag.Lookup("flagname").NoOptDefVal = "4321"
Would result in something like
会产生类似以下的结果
Parsed Arguments | Resulting Value |
---|---|
–flagname=1357 | ip=1357 |
–flagname | ip=4321 |
[nothing] | ip=1234 |
Command line flag syntax 命令行标志语法
--flag // boolean flags, or flags with no option default values
--flag x // only on flags without a default value
--flag=x
Unlike the flag package, a single dash before an option means something different than a double dash. Single dashes signify a series of shorthand letters for flags. All but the last shorthand letter must be boolean flags or a flag with a default value
与flag包不同,选项之前的单破折号和双破折号有不同的含义。单破折号表示一系列标志的缩写字母。除了最后一个缩写字母可以是布尔型标志或具有默认值的标志外,其他都必须是布尔型标志。
// boolean or flags where the 'no option default value' is set
-f
-f=true
-abc
but
-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 line before this terminator.
在" – “之后,标志解析将停止。与flag包不同,在这个终止符之前,标志可以与参数混合在命令行的任何位置。
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.
整数型标志接受1234、0664、0x1234等,并且可以为负数。布尔型标志(长格式)接受1、0、t、f、true、false、TRUE、FALSE、True、False。持续时间标志接受任何对于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
示例#1:您希望在标志中比较 -、_ 和 . 时得到相同的结果。也就是说 –my-flag == –my_flag == –my.flag
|
|
Example #2: You want to alias two flags. aka –old-flag-name == –new-flag-name
示例#2:您希望给两个标志设置别名。也就是说 –old-flag-name == –new-flag-name
|
|
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.
示例#1:您希望弃用一个名为"badflag"的标志,并告知用户应该使用哪个标志代替它。
// deprecate a flag by specifying its name and a usage message
flags.MarkDeprecated("badflag", "please use --good-flag instead")
This hides “badflag” from help text, and prints Flag --badflag has been deprecated, please use --good-flag instead
when “badflag” is used.
这将在帮助文本中隐藏"badflag",并在使用"badflag"时打印Flag --badflag已被弃用,请使用--good-flag代替
。
Example #2: You want to keep a flag name “noshorthandflag” but deprecate its shortname “n”.
示例#2:您希望保留一个名为"noshorthandflag"的标志,但弃用其缩写"n"。
// deprecate a flag shorthand by specifying its flag name and a usage message
flags.MarkShorthandDeprecated("noshorthandflag", "please use --noshorthandflag only")
This hides the shortname “n” from help text, and prints Flag shorthand -n has been deprecated, please use --noshorthandflag only
when the shorthand “n” is used.
这将在帮助文本中隐藏缩写"n",并在使用缩写"n"时打印Flag shorthand -n已被弃用,请只使用--noshorthandflag
。
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.
示例:您有一个名为"secretFlag"的标志,仅供内部使用,不希望它显示在帮助文本中或可用于使用文本。
// hide a flag by specifying its name
flags.MarkHidden("secretFlag")
Disable sorting of flags 禁用标志的排序
pflag
allows you to disable sorting of flags for help and usage message.
pflag
允许您禁用帮助和使用消息的标志排序。
示例:
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 = false
flags.PrintDefaults()
输出:
-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 在使用pflag时支持Go标志
In order to support flags defined using Go’s flag
package, they must be added to the pflag
flagset. This is usually necessary to support flags defined by third-party dependencies (e.g. golang/glog
).
为了支持使用Go的flag
包定义的标志,它们必须添加到pflag
的标志集中。这通常是为了支持由第三方依赖(例如golang/glog
)定义的标志。
Example: You want to add the Go flags to the CommandLine
flagset
示例:您希望将Go标志添加到CommandLine
的标志集中
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()
}
更多信息
You can see the full reference documentation of the pflag package at godoc.org, or through go’s standard documentation system by running godoc -http=:6060
and browsing to http://localhost:6060/pkg/github.com/spf13/pflag after installation.
您可以在godoc.org上查看pflag包的完整参考文档,或者在安装后通过运行godoc -http=:6060
并浏览http://localhost:6060/pkg/github.com/spf13/pflag来使用Go的标准文档系统。
文档概述
Package pflag is a drop-in replacement for Go’s flag package, implementing POSIX/GNU-style –flags.
pflag包是Go标准库flag包的一个替代品,实现了POSIX/GNU风格的–flags。
pflag is compatible with the GNU extensions to the POSIX recommendations for command-line options. See http://www.gnu.org/software/libc/manual/html_node/Argument-Syntax.html
pflag与GNU对POSIX命令行选项的推荐扩展兼容。请参阅http://www.gnu.org/software/libc/manual/html_node/Argument-Syntax.html
用法:
pflag is a drop-in replacement of Go’s native flag package. If you import pflag under the name “flag” then all code should continue to function with no changes.
pflag是Go原生flag包的一个替代品。如果您使用名称"flag"导入pflag,则所有代码应该继续正常工作,无需更改。
import flag "github.com/spf13/pflag"
There is one exception to this: if you directly instantiate the Flag struct there is one more field “Shorthand” that you will need to set. Most code never instantiates this struct directly, and instead uses functions such as String(), BoolVar(), and Var(), and is therefore unaffected.
但有一个例外:如果直接实例化Flag结构体,则需要设置一个额外的字段"Shorthand"。大多数代码不会直接实例化此结构体,而是使用诸如String()、BoolVar()和Var()等函数,因此不受影响。
Define flags using flag.String(), Bool(), Int(), etc.
使用flag.String()、Bool()、Int()等来定义标志。
This declares an integer flag, -flagname, stored in the pointer ip, with type *int.
这将声明一个整数标志-flagname,存储在指针ip中,类型为*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()函数将标志绑定到变量。
var flagvar int
func init() {
flag.IntVar(&flagvar, "flagname", 1234, "help message for flagname")
}
Or you can create custom flags that satisfy the Value interface (with pointer receivers) and couple them to flag parsing by
或者,您可以创建满足Value接口(具有指针接收者)的自定义标志,并将它们与标志解析耦合
flag.Var(&flagVal, "name", "help message for flagname")
For such flags, the default value is just the initial value of the variable.
对于这些标志,默认值只是变量的初始值。
After all flags are defined, call
在定义所有标志后,调用
flag.Parse()
to parse the command line into the defined flags.
将命令行解析为已定义的标志。
Flags may then be used directly. If you’re using the flags themselves, they are all pointers; if you bind to variables, they’re values.
然后可以直接使用标志。如果使用标志本身,它们都是指针;如果绑定到变量,则是值。
fmt.Println("ip has value ", *ip)
fmt.Println("flagvar has value ", flagvar)
After parsing, the arguments after the flag are available as the slice flag.Args() or individually as flag.Arg(i). The arguments are indexed from 0 through flag.NArg()-1.
解析后,标志后面的参数可以作为切片flag.Args()或单独作为flag.Arg(i)使用。参数从0到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.
pflag包还定义了一些在flag中不存在的新函数,为标志提供了一字母的缩写形式。您可以通过将定义标志的任何函数的名称附加’P’来使用这些函数。
var ip = flag.IntP("flagname", "f", 1234, "help message")
var flagvar bool
func init() {
flag.BoolVarP(&flagvar, "boolname", "b", true, "help message")
}
flag.VarP(&flagval, "varname", "v", "help message")
Shorthand letters can be used with single dashes on the command line. Boolean shorthand flags can be combined with other shorthand flags.
单个短横线加上字母可以在命令行中使用。布尔型短标志可以与其他短标志组合使用。
Command line flag syntax:
命令行标志语法:
--flag // boolean flags only
--flag=x
Unlike the flag package, a single dash before an option means something different than a double dash. Single dashes signify a series of shorthand letters for flags. All but the last shorthand letter must be boolean flags.
与flag包不同,选项之前的单个短横线与双短横线有不同的含义。单个短横线表示一系列用于标志的简写字母。除了最后一个简写字母,其他字母必须是布尔型标志。
// boolean flags
-f
-abc
// non-boolean flags
-n 1234
-Ifile
// mixed
-abcs "hello"
-abcn1234
Flag parsing stops after the terminator “–”. Unlike the flag package, flags can be interspersed with arguments anywhere on the command line before this terminator.
在终止符"–“之后,标志解析停止。与flag包不同,标志可以与参数交错出现在终止符之前的命令行中的任何位置。
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.
整数标志接受1234、0664、0x1234等值,可以为负数。布尔型标志(以其长形式表示)接受1、0、t、f、true、false、TRUE、FALSE、True、False。持续时间标志接受任何time.ParseDuration可接受的输入。
The default set of command-line flags is controlled by top-level functions. The FlagSet type allows one to define independent sets of flags, such as to implement subcommands in a command-line interface. The methods of FlagSet are analogous to the top-level functions for the command-line flag set.
默认的命令行标志集由顶级函数控制。FlagSet类型允许定义独立的标志集,例如在命令行界面中实现子命令。FlagSet的方法与用于命令行标志集的顶级函数类似。
Examples
Constants
This section is empty.
Variables
var CommandLine = NewFlagSet(os.Args[0], ExitOnError)
CommandLine is the default set of command-line flags, parsed from os.Args.
var ErrHelp = errors.New("pflag: help requested")
ErrHelp is the error returned if the flag -help is invoked but no such flag is defined.
var Usage = func() {
fmt.Fprintf(os.Stderr, "Usage of %s:\n", os.Args[0])
PrintDefaults()
}
Usage prints to standard error a usage message documenting all defined command-line flags. The function is a variable that may be changed to point to a custom function. By default it prints a simple header and calls PrintDefaults; for details about the format of the output and how to control it, see the documentation for PrintDefaults.
Functions
func Arg
|
|
Arg returns the i’th command-line argument. Arg(0) is the first remaining argument after flags have been processed.
func Args
|
|
Args returns the non-flag command-line arguments.
func Bool
|
|
Bool defines a bool flag with specified name, default value, and usage string. The return value is the address of a bool variable that stores the value of the flag.
func BoolP
|
|
BoolP is like Bool, but accepts a shorthand letter that can be used after a single dash.
func BoolSlice
|
|
BoolSlice defines a []bool flag with specified name, default value, and usage string. The return value is the address of a []bool variable that stores the value of the flag.
func BoolSliceP
|
|
BoolSliceP is like BoolSlice, but accepts a shorthand letter that can be used after a single dash.
func BoolSliceVar
|
|
BoolSliceVar defines a []bool flag with specified name, default value, and usage string. The argument p points to a []bool variable in which to store the value of the flag.
func BoolSliceVarP
|
|
BoolSliceVarP is like BoolSliceVar, but accepts a shorthand letter that can be used after a single dash.
func BoolVar
|
|
BoolVar defines a bool flag with specified name, default value, and usage string. The argument p points to a bool variable in which to store the value of the flag.
func BoolVarP
|
|
BoolVarP is like BoolVar, but accepts a shorthand letter that can be used after a single dash.
func BytesBase64 <- v1.0.2
|
|
BytesBase64 defines an []byte flag with specified name, default value, and usage string. The return value is the address of an []byte variable that stores the value of the flag.
func BytesBase64P <- v1.0.2
|
|
BytesBase64P is like BytesBase64, but accepts a shorthand letter that can be used after a single dash.
func BytesBase64Var <- v1.0.2
|
|
BytesBase64Var defines an []byte flag with specified name, default value, and usage string. The argument p points to an []byte variable in which to store the value of the flag.
func BytesBase64VarP <- v1.0.2
|
|
BytesBase64VarP is like BytesBase64Var, but accepts a shorthand letter that can be used after a single dash.
func BytesHex <- v1.0.1
|
|
BytesHex defines an []byte flag with specified name, default value, and usage string. The return value is the address of an []byte variable that stores the value of the flag.
func BytesHexP <- v1.0.1
|
|
BytesHexP is like BytesHex, but accepts a shorthand letter that can be used after a single dash.
func BytesHexVar <- v1.0.1
|
|
BytesHexVar defines an []byte flag with specified name, default value, and usage string. The argument p points to an []byte variable in which to store the value of the flag.
func BytesHexVarP <- v1.0.1
|
|
BytesHexVarP is like BytesHexVar, but accepts a shorthand letter that can be used after a single dash.
func Count
|
|
Count defines a count flag with specified name, default value, and usage string. The return value is the address of an int variable that stores the value of the flag. A count flag will add 1 to its value evey time it is found on the command line
func CountP
|
|
CountP is like Count only takes a shorthand for the flag name.
func CountVar
|
|
CountVar like CountVar only the flag is placed on the CommandLine instead of a given flag set
func CountVarP
|
|
CountVarP is like CountVar only take a shorthand for the flag name.
func Duration
|
|
Duration defines a time.Duration flag with specified name, default value, and usage string. The return value is the address of a time.Duration variable that stores the value of the flag.
func DurationP
|
|
DurationP is like Duration, but accepts a shorthand letter that can be used after a single dash.
func DurationSlice <- v1.0.1
|
|
DurationSlice defines a []time.Duration flag with specified name, default value, and usage string. The return value is the address of a []time.Duration variable that stores the value of the flag.
func DurationSliceP <- v1.0.1
|
|
DurationSliceP is like DurationSlice, but accepts a shorthand letter that can be used after a single dash.
func DurationSliceVar <- v1.0.1
|
|
DurationSliceVar defines a duration[] flag with specified name, default value, and usage string. The argument p points to a duration[] variable in which to store the value of the flag.
func DurationSliceVarP <- v1.0.1
|
|
DurationSliceVarP is like DurationSliceVar, but accepts a shorthand letter that can be used after a single dash.
func DurationVar
|
|
DurationVar defines a time.Duration flag with specified name, default value, and usage string. The argument p points to a time.Duration variable in which to store the value of the flag.
func DurationVarP
|
|
DurationVarP is like DurationVar, but accepts a shorthand letter that can be used after a single dash.
func Float32
|
|
Float32 defines a float32 flag with specified name, default value, and usage string. The return value is the address of a float32 variable that stores the value of the flag.
func Float32P
|
|
Float32P is like Float32, but accepts a shorthand letter that can be used after a single dash.
func Float32Slice <- v1.0.5
|
|
Float32Slice defines a []float32 flag with specified name, default value, and usage string. The return value is the address of a []float32 variable that stores the value of the flag.
func Float32SliceP <- v1.0.5
|
|
Float32SliceP is like Float32Slice, but accepts a shorthand letter that can be used after a single dash.
func Float32SliceVar <- v1.0.5
|
|
Float32SliceVar defines a float32[] flag with specified name, default value, and usage string. The argument p points to a float32[] variable in which to store the value of the flag.
func Float32SliceVarP <- v1.0.5
|
|
Float32SliceVarP is like Float32SliceVar, but accepts a shorthand letter that can be used after a single dash.
func Float32Var
|
|
Float32Var defines a float32 flag with specified name, default value, and usage string. The argument p points to a float32 variable in which to store the value of the flag.
func Float32VarP
|
|
Float32VarP is like Float32Var, but accepts a shorthand letter that can be used after a single dash.
func Float64
|
|
Float64 defines a float64 flag with specified name, default value, and usage string. The return value is the address of a float64 variable that stores the value of the flag.
func Float64P
|
|
Float64P is like Float64, but accepts a shorthand letter that can be used after a single dash.
func Float64Slice <- v1.0.5
|
|
Float64Slice defines a []float64 flag with specified name, default value, and usage string. The return value is the address of a []float64 variable that stores the value of the flag.
func Float64SliceP <- v1.0.5
|
|
Float64SliceP is like Float64Slice, but accepts a shorthand letter that can be used after a single dash.
func Float64SliceVar <- v1.0.5
|
|
Float64SliceVar defines a float64[] flag with specified name, default value, and usage string. The argument p points to a float64[] variable in which to store the value of the flag.
func Float64SliceVarP <- v1.0.5
|
|
Float64SliceVarP is like Float64SliceVar, but accepts a shorthand letter that can be used after a single dash.
func Float64Var
|
|
Float64Var defines a float64 flag with specified name, default value, and usage string. The argument p points to a float64 variable in which to store the value of the flag.
func Float64VarP
|
|
Float64VarP is like Float64Var, but accepts a shorthand letter that can be used after a single dash.
func IP
|
|
IP defines an net.IP flag with specified name, default value, and usage string. The return value is the address of an net.IP variable that stores the value of the flag.
func IPMask
|
|
IPMask defines an net.IPMask flag with specified name, default value, and usage string. The return value is the address of an net.IPMask variable that stores the value of the flag.
func IPMaskP
|
|
IPMaskP is like IP, but accepts a shorthand letter that can be used after a single dash.
func IPMaskVar
|
|
IPMaskVar defines an net.IPMask flag with specified name, default value, and usage string. The argument p points to an net.IPMask variable in which to store the value of the flag.
func IPMaskVarP
|
|
IPMaskVarP is like IPMaskVar, but accepts a shorthand letter that can be used after a single dash.
func IPNet
|
|
IPNet defines an net.IPNet flag with specified name, default value, and usage string. The return value is the address of an net.IPNet variable that stores the value of the flag.
func IPNetP
|
|
IPNetP is like IPNet, but accepts a shorthand letter that can be used after a single dash.
func IPNetVar
|
|
IPNetVar defines an net.IPNet flag with specified name, default value, and usage string. The argument p points to an net.IPNet variable in which to store the value of the flag.
func IPNetVarP
|
|
IPNetVarP is like IPNetVar, but accepts a shorthand letter that can be used after a single dash.
func IPP
|
|
IPP is like IP, but accepts a shorthand letter that can be used after a single dash.
func IPSlice
|
|
IPSlice defines a []net.IP flag with specified name, default value, and usage string. The return value is the address of a []net.IP variable that stores the value of the flag.
func IPSliceP
|
|
IPSliceP is like IPSlice, but accepts a shorthand letter that can be used after a single dash.
func IPSliceVar
|
|
IPSliceVar defines a []net.IP flag with specified name, default value, and usage string. The argument p points to a []net.IP variable in which to store the value of the flag.
func IPSliceVarP
|
|
IPSliceVarP is like IPSliceVar, but accepts a shorthand letter that can be used after a single dash.
func IPVar
|
|
IPVar defines an net.IP flag with specified name, default value, and usage string. The argument p points to an net.IP variable in which to store the value of the flag.
func IPVarP
|
|
IPVarP is like IPVar, but accepts a shorthand letter that can be used after a single dash.
func Int
|
|
Int defines an int flag with specified name, default value, and usage string. The return value is the address of an int variable that stores the value of the flag.
func Int16 <- v1.0.1
|
|
Int16 defines an int16 flag with specified name, default value, and usage string. The return value is the address of an int16 variable that stores the value of the flag.
func Int16P <- v1.0.1
|
|
Int16P is like Int16, but accepts a shorthand letter that can be used after a single dash.
func Int16Var <- v1.0.1
|
|
Int16Var defines an int16 flag with specified name, default value, and usage string. The argument p points to an int16 variable in which to store the value of the flag.
func Int16VarP <- v1.0.1
|
|
Int16VarP is like Int16Var, but accepts a shorthand letter that can be used after a single dash.
func Int32
|
|
Int32 defines an int32 flag with specified name, default value, and usage string. The return value is the address of an int32 variable that stores the value of the flag.
func Int32P
|
|
Int32P is like Int32, but accepts a shorthand letter that can be used after a single dash.
func Int32Slice <- v1.0.5
|
|
Int32Slice defines a []int32 flag with specified name, default value, and usage string. The return value is the address of a []int32 variable that stores the value of the flag.
func Int32SliceP <- v1.0.5
|
|
Int32SliceP is like Int32Slice, but accepts a shorthand letter that can be used after a single dash.
func Int32SliceVar <- v1.0.5
|
|
Int32SliceVar defines a int32[] flag with specified name, default value, and usage string. The argument p points to a int32[] variable in which to store the value of the flag.
func Int32SliceVarP <- v1.0.5
|
|
Int32SliceVarP is like Int32SliceVar, but accepts a shorthand letter that can be used after a single dash.
func Int32Var
|
|
Int32Var defines an int32 flag with specified name, default value, and usage string. The argument p points to an int32 variable in which to store the value of the flag.
func Int32VarP
|
|
Int32VarP is like Int32Var, but accepts a shorthand letter that can be used after a single dash.
func Int64
|
|
Int64 defines an int64 flag with specified name, default value, and usage string. The return value is the address of an int64 variable that stores the value of the flag.
func Int64P
|
|
Int64P is like Int64, but accepts a shorthand letter that can be used after a single dash.
func Int64Slice <- v1.0.5
|
|
Int64Slice defines a []int64 flag with specified name, default value, and usage string. The return value is the address of a []int64 variable that stores the value of the flag.
func Int64SliceP <- v1.0.5
|
|
Int64SliceP is like Int64Slice, but accepts a shorthand letter that can be used after a single dash.
func Int64SliceVar <- v1.0.5
|
|
Int64SliceVar defines a int64[] flag with specified name, default value, and usage string. The argument p points to a int64[] variable in which to store the value of the flag.
func Int64SliceVarP <- v1.0.5
|
|
Int64SliceVarP is like Int64SliceVar, but accepts a shorthand letter that can be used after a single dash.
func Int64Var
|
|
Int64Var defines an int64 flag with specified name, default value, and usage string. The argument p points to an int64 variable in which to store the value of the flag.
func Int64VarP
|
|
Int64VarP is like Int64Var, but accepts a shorthand letter that can be used after a single dash.
func Int8
|
|
Int8 defines an int8 flag with specified name, default value, and usage string. The return value is the address of an int8 variable that stores the value of the flag.
func Int8P
|
|
Int8P is like Int8, but accepts a shorthand letter that can be used after a single dash.
func Int8Var
|
|
Int8Var defines an int8 flag with specified name, default value, and usage string. The argument p points to an int8 variable in which to store the value of the flag.
func Int8VarP
|
|
Int8VarP is like Int8Var, but accepts a shorthand letter that can be used after a single dash.
func IntP
|
|
IntP is like Int, but accepts a shorthand letter that can be used after a single dash.
func IntSlice
|
|
IntSlice defines a []int flag with specified name, default value, and usage string. The return value is the address of a []int variable that stores the value of the flag.
func IntSliceP
|
|
IntSliceP is like IntSlice, but accepts a shorthand letter that can be used after a single dash.
func IntSliceVar
|
|
IntSliceVar defines a int[] flag with specified name, default value, and usage string. The argument p points to a int[] variable in which to store the value of the flag.
func IntSliceVarP
|
|
IntSliceVarP is like IntSliceVar, but accepts a shorthand letter that can be used after a single dash.
func IntVar
|
|
IntVar defines an int flag with specified name, default value, and usage string. The argument p points to an int variable in which to store the value of the flag.
func IntVarP
|
|
IntVarP is like IntVar, but accepts a shorthand letter that can be used after a single dash.
func NArg
|
|
NArg is the number of arguments remaining after flags have been processed.
func NFlag
|
|
NFlag returns the number of command-line flags that have been set.
func Parse
|
|
Parse parses the command-line flags from os.Args[1:]. Must be called after all flags are defined and before flags are accessed by the program.
func ParseAll
|
|
ParseAll parses the command-line flags from os.Args[1:] and called fn for each. The arguments for fn are flag and value. Must be called after all flags are defined and before flags are accessed by the program.
func ParseIPv4Mask
|
|
ParseIPv4Mask written in IP form (e.g. 255.255.255.0). This function should really belong to the net package.
func Parsed
|
|
Parsed returns true if the command-line flags have been parsed.
func PrintDefaults
|
|
PrintDefaults prints to standard error the default values of all defined command-line flags.
func Set
|
|
Set sets the value of the named command-line flag.
func SetInterspersed
|
|
SetInterspersed sets whether to support interspersed option/non-option arguments.
func String
|
|
String defines a string flag with specified name, default value, and usage string. The return value is the address of a string variable that stores the value of the flag.
func StringArray
|
|
StringArray defines a string flag with specified name, default value, and usage string. The return value is the address of a []string variable that stores the value of the flag. The value of each argument will not try to be separated by comma. Use a StringSlice for that.
func StringArrayP
|
|
StringArrayP is like StringArray, but accepts a shorthand letter that can be used after a single dash.
func StringArrayVar
|
|
StringArrayVar defines a string flag with specified name, default value, and usage string. The argument p points to a []string variable in which to store the value of the flag. The value of each argument will not try to be separated by comma. Use a StringSlice for that.
func StringArrayVarP
|
|
StringArrayVarP is like StringArrayVar, but accepts a shorthand letter that can be used after a single dash.
func StringP
|
|
StringP is like String, but accepts a shorthand letter that can be used after a single dash.
func StringSlice
|
|
StringSlice defines a string flag with specified name, default value, and usage string. The return value is the address of a []string variable that stores the value of the flag. Compared to StringArray flags, StringSlice flags take comma-separated value as arguments and split them accordingly. For example:
--ss="v1,v2" --ss="v3"
will result in
[]string{"v1", "v2", "v3"}
func StringSliceP
|
|
StringSliceP is like StringSlice, but accepts a shorthand letter that can be used after a single dash.
func StringSliceVar
|
|
StringSliceVar defines a string flag with specified name, default value, and usage string. The argument p points to a []string variable in which to store the value of the flag. Compared to StringArray flags, StringSlice flags take comma-separated value as arguments and split them accordingly. For example:
--ss="v1,v2" --ss="v3"
will result in
[]string{"v1", "v2", "v3"}
func StringSliceVarP
|
|
StringSliceVarP is like StringSliceVar, but accepts a shorthand letter that can be used after a single dash.
func StringToInt <- v1.0.3
|
|
StringToInt defines a string flag with specified name, default value, and usage string. The return value is the address of a map[string]int variable that stores the value of the flag. The value of each argument will not try to be separated by comma
func StringToInt64 <- v1.0.5
|
|
StringToInt64 defines a string flag with specified name, default value, and usage string. The return value is the address of a map[string]int64 variable that stores the value of the flag. The value of each argument will not try to be separated by comma
func StringToInt64P <- v1.0.5
|
|
StringToInt64P is like StringToInt64, but accepts a shorthand letter that can be used after a single dash.
func StringToInt64Var <- v1.0.5
|
|
StringToInt64Var defines a string flag with specified name, default value, and usage string. The argument p point64s to a map[string]int64 variable in which to store the value of the flag. The value of each argument will not try to be separated by comma
func StringToInt64VarP <- v1.0.5
|
|
StringToInt64VarP is like StringToInt64Var, but accepts a shorthand letter that can be used after a single dash.
func StringToIntP <- v1.0.3
|
|
StringToIntP is like StringToInt, but accepts a shorthand letter that can be used after a single dash.
func StringToIntVar <- v1.0.3
|
|
StringToIntVar defines a string flag with specified name, default value, and usage string. The argument p points to a map[string]int variable in which to store the value of the flag. The value of each argument will not try to be separated by comma
func StringToIntVarP <- v1.0.3
|
|
StringToIntVarP is like StringToIntVar, but accepts a shorthand letter that can be used after a single dash.
func StringToString <- v1.0.3
|
|
StringToString defines a string flag with specified name, default value, and usage string. The return value is the address of a map[string]string variable that stores the value of the flag. The value of each argument will not try to be separated by comma
func StringToStringP <- v1.0.3
|
|
StringToStringP is like StringToString, but accepts a shorthand letter that can be used after a single dash.
func StringToStringVar <- v1.0.3
|
|
StringToStringVar defines a string flag with specified name, default value, and usage string. The argument p points to a map[string]string variable in which to store the value of the flag. The value of each argument will not try to be separated by comma
func StringToStringVarP <- v1.0.3
|
|
StringToStringVarP is like StringToStringVar, but accepts a shorthand letter that can be used after a single dash.
func StringVar
|
|
StringVar defines a string flag with specified name, default value, and usage string. The argument p points to a string variable in which to store the value of the flag.
func StringVarP
|
|
StringVarP is like StringVar, but accepts a shorthand letter that can be used after a single dash.
func Uint
|
|
Uint defines a uint flag with specified name, default value, and usage string. The return value is the address of a uint variable that stores the value of the flag.
func Uint16
|
|
Uint16 defines a uint flag with specified name, default value, and usage string. The return value is the address of a uint variable that stores the value of the flag.
func Uint16P
|
|
Uint16P is like Uint16, but accepts a shorthand letter that can be used after a single dash.
func Uint16Var
|
|
Uint16Var defines a uint flag with specified name, default value, and usage string. The argument p points to a uint variable in which to store the value of the flag.
func Uint16VarP
|
|
Uint16VarP is like Uint16Var, but accepts a shorthand letter that can be used after a single dash.
func Uint32
|
|
Uint32 defines a uint32 flag with specified name, default value, and usage string. The return value is the address of a uint32 variable that stores the value of the flag.
func Uint32P
|
|
Uint32P is like Uint32, but accepts a shorthand letter that can be used after a single dash.
func Uint32Var
|
|
Uint32Var defines a uint32 flag with specified name, default value, and usage string. The argument p points to a uint32 variable in which to store the value of the flag.
func Uint32VarP
|
|
Uint32VarP is like Uint32Var, but accepts a shorthand letter that can be used after a single dash.
func Uint64
|
|
Uint64 defines a uint64 flag with specified name, default value, and usage string. The return value is the address of a uint64 variable that stores the value of the flag.
func Uint64P
|
|
Uint64P is like Uint64, but accepts a shorthand letter that can be used after a single dash.
func Uint64Var
|
|
Uint64Var defines a uint64 flag with specified name, default value, and usage string. The argument p points to a uint64 variable in which to store the value of the flag.
func Uint64VarP
|
|
Uint64VarP is like Uint64Var, but accepts a shorthand letter that can be used after a single dash.
func Uint8
|
|
Uint8 defines a uint8 flag with specified name, default value, and usage string. The return value is the address of a uint8 variable that stores the value of the flag.
func Uint8P
|
|
Uint8P is like Uint8, but accepts a shorthand letter that can be used after a single dash.
func Uint8Var
|
|
Uint8Var defines a uint8 flag with specified name, default value, and usage string. The argument p points to a uint8 variable in which to store the value of the flag.
func Uint8VarP
|
|
Uint8VarP is like Uint8Var, but accepts a shorthand letter that can be used after a single dash.
func UintP
|
|
UintP is like Uint, but accepts a shorthand letter that can be used after a single dash.
func UintSlice
|
|
UintSlice defines a []uint flag with specified name, default value, and usage string. The return value is the address of a []uint variable that stores the value of the flag.
func UintSliceP
|
|
UintSliceP is like UintSlice, but accepts a shorthand letter that can be used after a single dash.
func UintSliceVar
|
|
UintSliceVar defines a uint[] flag with specified name, default value, and usage string. The argument p points to a uint[] variable in which to store the value of the flag.
func UintSliceVarP
|
|
UintSliceVarP is like the UintSliceVar, but accepts a shorthand letter that can be used after a single dash.
func UintVar
|
|
UintVar defines a uint flag with specified name, default value, and usage string. The argument p points to a uint variable in which to store the value of the flag.
func UintVarP
|
|
UintVarP is like UintVar, but accepts a shorthand letter that can be used after a single dash.
func UnquoteUsage
|
|
UnquoteUsage extracts a back-quoted name from the usage string for a flag and returns it and the un-quoted usage. Given “a name
to show” it returns (“name”, “a name to show”). If there are no back quotes, the name is an educated guess of the type of the flag’s value, or the empty string if the flag is boolean.
func Var
|
|
Var defines a flag with the specified name and usage string. The type and value of the flag are represented by the first argument, of type Value, which typically holds a user-defined implementation of Value. For instance, the caller could create a flag that turns a comma-separated string into a slice of strings by giving the slice the methods of Value; in particular, Set would decompose the comma-separated string into the slice.
func VarP
|
|
VarP is like Var, but accepts a shorthand letter that can be used after a single dash.
func Visit
|
|
Visit visits the command-line flags in lexicographical order or in primordial order if f.SortFlags is false, calling fn for each. It visits only those flags that have been set.
func VisitAll
|
|
VisitAll visits the command-line flags in lexicographical order or in primordial order if f.SortFlags is false, calling fn for each. It visits all flags, even those not set.
Types
type ErrorHandling
|
|
ErrorHandling defines how to handle flag parsing errors.
|
|
type Flag
|
|
A Flag represents the state of a flag.
func Lookup
|
|
Lookup returns the Flag structure of the named command-line flag, returning nil if none exists.
func PFlagFromGoFlag
|
|
PFlagFromGoFlag will return a *pflag.Flag given a *flag.Flag If the *flag.Flag.Name was a single character (ex: v
) it will be accessiblei with both -v
and --v
in flags. If the golang flag was more than a single character (ex: verbose
) it will only be accessible via --verbose
func ShorthandLookup
|
|
ShorthandLookup returns the Flag structure of the short handed flag, returning nil if none exists.
Example
type FlagSet
|
|
A FlagSet represents a set of defined flags.
func NewFlagSet
|
|
NewFlagSet returns a new, empty flag set with the specified name, error handling property and SortFlags set to true.
(*FlagSet) AddFlag
|
|
AddFlag will add the flag to the FlagSet
(*FlagSet) AddFlagSet
|
|
AddFlagSet adds one FlagSet to another. If a flag is already present in f the flag from newSet will be ignored.
(*FlagSet) AddGoFlag
|
|
AddGoFlag will add the given *flag.Flag to the pflag.FlagSet
(*FlagSet) AddGoFlagSet
|
|
AddGoFlagSet will add the given *flag.FlagSet to the pflag.FlagSet
(*FlagSet) Arg
|
|
Arg returns the i’th argument. Arg(0) is the first remaining argument after flags have been processed.
(*FlagSet) Args
|
|
Args returns the non-flag arguments.
(*FlagSet) ArgsLenAtDash
|
|
ArgsLenAtDash will return the length of f.Args at the moment when a – was found during arg parsing. This allows your program to know which args were before the – and which came after.
(*FlagSet) Bool
|
|
Bool defines a bool flag with specified name, default value, and usage string. The return value is the address of a bool variable that stores the value of the flag.
(*FlagSet) BoolP
|
|
BoolP is like Bool, but accepts a shorthand letter that can be used after a single dash.
(*FlagSet) BoolSlice
|
|
BoolSlice defines a []bool flag with specified name, default value, and usage string. The return value is the address of a []bool variable that stores the value of the flag.
(*FlagSet) BoolSliceP
|
|
BoolSliceP is like BoolSlice, but accepts a shorthand letter that can be used after a single dash.
(*FlagSet) BoolSliceVar
|
|
BoolSliceVar defines a boolSlice flag with specified name, default value, and usage string. The argument p points to a []bool variable in which to store the value of the flag.
(*FlagSet) BoolSliceVarP
|
|
BoolSliceVarP is like BoolSliceVar, but accepts a shorthand letter that can be used after a single dash.
(*FlagSet) BoolVar
|
|
BoolVar defines a bool flag with specified name, default value, and usage string. The argument p points to a bool variable in which to store the value of the flag.
(*FlagSet) BoolVarP
|
|
BoolVarP is like BoolVar, but accepts a shorthand letter that can be used after a single dash.
(*FlagSet) BytesBase64 <- v1.0.2
|
|
BytesBase64 defines an []byte flag with specified name, default value, and usage string. The return value is the address of an []byte variable that stores the value of the flag.
(*FlagSet) BytesBase64P <- v1.0.2
|
|
BytesBase64P is like BytesBase64, but accepts a shorthand letter that can be used after a single dash.
(*FlagSet) BytesBase64Var <- v1.0.2
|
|
BytesBase64Var defines an []byte flag with specified name, default value, and usage string. The argument p points to an []byte variable in which to store the value of the flag.
(*FlagSet) BytesBase64VarP <- v1.0.2
|
|
BytesBase64VarP is like BytesBase64Var, but accepts a shorthand letter that can be used after a single dash.
(*FlagSet) BytesHex <- v1.0.1
|
|
BytesHex defines an []byte flag with specified name, default value, and usage string. The return value is the address of an []byte variable that stores the value of the flag.
(*FlagSet) BytesHexP <- v1.0.1
|
|
BytesHexP is like BytesHex, but accepts a shorthand letter that can be used after a single dash.
(*FlagSet) BytesHexVar <- v1.0.1
|
|
BytesHexVar defines an []byte flag with specified name, default value, and usage string. The argument p points to an []byte variable in which to store the value of the flag.
(*FlagSet) BytesHexVarP <- v1.0.1
|
|
BytesHexVarP is like BytesHexVar, but accepts a shorthand letter that can be used after a single dash.
(*FlagSet) Changed
|
|
Changed returns true if the flag was explicitly set during Parse() and false otherwise
(*FlagSet) Count
|
|
Count defines a count flag with specified name, default value, and usage string. The return value is the address of an int variable that stores the value of the flag. A count flag will add 1 to its value every time it is found on the command line
(*FlagSet) CountP
|
|
CountP is like Count only takes a shorthand for the flag name.
(*FlagSet) CountVar
|
|
CountVar defines a count flag with specified name, default value, and usage string. The argument p points to an int variable in which to store the value of the flag. A count flag will add 1 to its value every time it is found on the command line
(*FlagSet) CountVarP
|
|
CountVarP is like CountVar only take a shorthand for the flag name.
(*FlagSet) Duration
|
|
Duration defines a time.Duration flag with specified name, default value, and usage string. The return value is the address of a time.Duration variable that stores the value of the flag.
(*FlagSet) DurationP
|
|
DurationP is like Duration, but accepts a shorthand letter that can be used after a single dash.
(*FlagSet) DurationSlice <- v1.0.1
|
|
DurationSlice defines a []time.Duration flag with specified name, default value, and usage string. The return value is the address of a []time.Duration variable that stores the value of the flag.
(*FlagSet) DurationSliceP <- v1.0.1
|
|
DurationSliceP is like DurationSlice, but accepts a shorthand letter that can be used after a single dash.
(*FlagSet) DurationSliceVar <- v1.0.1
|
|
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.
(*FlagSet) DurationSliceVarP <- v1.0.1
|
|
DurationSliceVarP is like DurationSliceVar, but accepts a shorthand letter that can be used after a single dash.
(*FlagSet) DurationVar
|
|
DurationVar defines a time.Duration flag with specified name, default value, and usage string. The argument p points to a time.Duration variable in which to store the value of the flag.
(*FlagSet) DurationVarP
|
|
DurationVarP is like DurationVar, but accepts a shorthand letter that can be used after a single dash.
(*FlagSet) FlagUsages
|
|
FlagUsages returns a string containing the usage information for all flags in the FlagSet
(*FlagSet) FlagUsagesWrapped
|
|
FlagUsagesWrapped returns a string containing the usage information for all flags in the FlagSet. Wrapped to cols
columns (0 for no wrapping)
(*FlagSet) Float32
|
|
Float32 defines a float32 flag with specified name, default value, and usage string. The return value is the address of a float32 variable that stores the value of the flag.
(*FlagSet) Float32P
|
|
Float32P is like Float32, but accepts a shorthand letter that can be used after a single dash.
(*FlagSet) Float32Slice <- v1.0.5
|
|
Float32Slice defines a []float32 flag with specified name, default value, and usage string. The return value is the address of a []float32 variable that stores the value of the flag.
(*FlagSet) Float32SliceP <- v1.0.5
|
|
Float32SliceP is like Float32Slice, but accepts a shorthand letter that can be used after a single dash.
(*FlagSet) Float32SliceVar <- v1.0.5
|
|
Float32SliceVar defines a float32Slice flag with specified name, default value, and usage string. The argument p points to a []float32 variable in which to store the value of the flag.
(*FlagSet) Float32SliceVarP <- v1.0.5
|
|
Float32SliceVarP is like Float32SliceVar, but accepts a shorthand letter that can be used after a single dash.
(*FlagSet) Float32Var
|
|
Float32Var defines a float32 flag with specified name, default value, and usage string. The argument p points to a float32 variable in which to store the value of the flag.
(*FlagSet) Float32VarP
|
|
Float32VarP is like Float32Var, but accepts a shorthand letter that can be used after a single dash.
(*FlagSet) Float64
|
|
Float64 defines a float64 flag with specified name, default value, and usage string. The return value is the address of a float64 variable that stores the value of the flag.
(*FlagSet) Float64P
|
|
Float64P is like Float64, but accepts a shorthand letter that can be used after a single dash.
(*FlagSet) Float64Slice <- v1.0.5
|
|
Float64Slice defines a []float64 flag with specified name, default value, and usage string. The return value is the address of a []float64 variable that stores the value of the flag.
(*FlagSet) Float64SliceP <- v1.0.5
|
|
Float64SliceP is like Float64Slice, but accepts a shorthand letter that can be used after a single dash.
(*FlagSet) Float64SliceVar <- v1.0.5
|
|
Float64SliceVar defines a float64Slice flag with specified name, default value, and usage string. The argument p points to a []float64 variable in which to store the value of the flag.
(*FlagSet) Float64SliceVarP <- v1.0.5
|
|
Float64SliceVarP is like Float64SliceVar, but accepts a shorthand letter that can be used after a single dash.
(*FlagSet) Float64Var
|
|
Float64Var defines a float64 flag with specified name, default value, and usage string. The argument p points to a float64 variable in which to store the value of the flag.
(*FlagSet) Float64VarP
|
|
Float64VarP is like Float64Var, but accepts a shorthand letter that can be used after a single dash.
(*FlagSet) GetBool
|
|
GetBool return the bool value of a flag with the given name
(*FlagSet) GetBoolSlice
|
|
GetBoolSlice returns the []bool value of a flag with the given name.
(*FlagSet) GetBytesBase64 <- v1.0.2
|
|
GetBytesBase64 return the []byte value of a flag with the given name
(*FlagSet) GetBytesHex <- v1.0.1
|
|
GetBytesHex return the []byte value of a flag with the given name
(*FlagSet) GetCount
|
|
GetCount return the int value of a flag with the given name
(*FlagSet) GetDuration
|
|
GetDuration return the duration value of a flag with the given name
(*FlagSet) GetDurationSlice <- v1.0.1
|
|
GetDurationSlice returns the []time.Duration value of a flag with the given name
(*FlagSet) GetFloat32
|
|
GetFloat32 return the float32 value of a flag with the given name
(*FlagSet) GetFloat32Slice <- v1.0.5
|
|
GetFloat32Slice return the []float32 value of a flag with the given name
(*FlagSet) GetFloat64
|
|
GetFloat64 return the float64 value of a flag with the given name
(*FlagSet) GetFloat64Slice <- v1.0.5
|
|
GetFloat64Slice return the []float64 value of a flag with the given name
(*FlagSet) GetIP
|
|
GetIP return the net.IP value of a flag with the given name
(*FlagSet) GetIPNet
|
|
GetIPNet return the net.IPNet value of a flag with the given name
(*FlagSet) GetIPSlice
|
|
GetIPSlice returns the []net.IP value of a flag with the given name
(*FlagSet) GetIPv4Mask
|
|
GetIPv4Mask return the net.IPv4Mask value of a flag with the given name
(*FlagSet) GetInt
|
|
GetInt return the int value of a flag with the given name
(*FlagSet) GetInt16 <- v1.0.1
|
|
GetInt16 returns the int16 value of a flag with the given name
(*FlagSet) GetInt32
|
|
GetInt32 return the int32 value of a flag with the given name
(*FlagSet) GetInt32Slice <- v1.0.5
|
|
GetInt32Slice return the []int32 value of a flag with the given name
(*FlagSet) GetInt64
|
|
GetInt64 return the int64 value of a flag with the given name
(*FlagSet) GetInt64Slice <- v1.0.5
|
|
GetInt64Slice return the []int64 value of a flag with the given name
(*FlagSet) GetInt8
|
|
GetInt8 return the int8 value of a flag with the given name
(*FlagSet) GetIntSlice
|
|
GetIntSlice return the []int value of a flag with the given name
(*FlagSet) GetNormalizeFunc
|
|
GetNormalizeFunc returns the previously set NormalizeFunc of a function which does no translation, if not set previously.
(*FlagSet) GetString
|
|
GetString return the string value of a flag with the given name
(*FlagSet) GetStringArray
|
|
GetStringArray return the []string value of a flag with the given name
(*FlagSet) GetStringSlice
|
|
GetStringSlice return the []string value of a flag with the given name
(*FlagSet) GetStringToInt <- v1.0.3
|
|
GetStringToInt return the map[string]int value of a flag with the given name
(*FlagSet) GetStringToInt64 <- v1.0.5
|
|
GetStringToInt64 return the map[string]int64 value of a flag with the given name
(*FlagSet) GetStringToString <- v1.0.3
|
|
GetStringToString return the map[string]string value of a flag with the given name
(*FlagSet) GetUint
|
|
GetUint return the uint value of a flag with the given name
(*FlagSet) GetUint16
|
|
GetUint16 return the uint16 value of a flag with the given name
(*FlagSet) GetUint32
|
|
GetUint32 return the uint32 value of a flag with the given name
(*FlagSet) GetUint64
|
|
GetUint64 return the uint64 value of a flag with the given name
(*FlagSet) GetUint8
|
|
GetUint8 return the uint8 value of a flag with the given name
(*FlagSet) GetUintSlice
|
|
GetUintSlice returns the []uint value of a flag with the given name.
(*FlagSet) HasAvailableFlags
|
|
HasAvailableFlags returns a bool to indicate if the FlagSet has any flags that are not hidden.
(*FlagSet) HasFlags
|
|
HasFlags returns a bool to indicate if the FlagSet has any flags defined.
(*FlagSet) IP
|
|
IP defines an net.IP flag with specified name, default value, and usage string. The return value is the address of an net.IP variable that stores the value of the flag.
(*FlagSet) IPMask
|
|
IPMask defines an net.IPMask flag with specified name, default value, and usage string. The return value is the address of an net.IPMask variable that stores the value of the flag.
(*FlagSet) IPMaskP
|
|
IPMaskP is like IPMask, but accepts a shorthand letter that can be used after a single dash.
(*FlagSet) IPMaskVar
|
|
IPMaskVar defines an net.IPMask flag with specified name, default value, and usage string. The argument p points to an net.IPMask variable in which to store the value of the flag.
(*FlagSet) IPMaskVarP
|
|
IPMaskVarP is like IPMaskVar, but accepts a shorthand letter that can be used after a single dash.
(*FlagSet) IPNet
|
|
IPNet defines an net.IPNet flag with specified name, default value, and usage string. The return value is the address of an net.IPNet variable that stores the value of the flag.
(*FlagSet) IPNetP
|
|
IPNetP is like IPNet, but accepts a shorthand letter that can be used after a single dash.
(*FlagSet) IPNetVar
|
|
IPNetVar defines an net.IPNet flag with specified name, default value, and usage string. The argument p points to an net.IPNet variable in which to store the value of the flag.
(*FlagSet) IPNetVarP
|
|
IPNetVarP is like IPNetVar, but accepts a shorthand letter that can be used after a single dash.
(*FlagSet) IPP
|
|
IPP is like IP, but accepts a shorthand letter that can be used after a single dash.
(*FlagSet) IPSlice
|
|
IPSlice defines a []net.IP flag with specified name, default value, and usage string. The return value is the address of a []net.IP variable that stores the value of that flag.
(*FlagSet) IPSliceP
|
|
IPSliceP is like IPSlice, but accepts a shorthand letter that can be used after a single dash.
(*FlagSet) IPSliceVar
|
|
IPSliceVar defines a ipSlice flag with specified name, default value, and usage string. The argument p points to a []net.IP variable in which to store the value of the flag.
(*FlagSet) IPSliceVarP
|
|
IPSliceVarP is like IPSliceVar, but accepts a shorthand letter that can be used after a single dash.
(*FlagSet) IPVar
|
|
IPVar defines an net.IP flag with specified name, default value, and usage string. The argument p points to an net.IP variable in which to store the value of the flag.
(*FlagSet) IPVarP
|
|
IPVarP is like IPVar, but accepts a shorthand letter that can be used after a single dash.
(*FlagSet) Init
|
|
Init sets the name and error handling property for a flag set. By default, the zero FlagSet uses an empty name and the ContinueOnError error handling policy.
(*FlagSet) Int
|
|
Int defines an int flag with specified name, default value, and usage string. The return value is the address of an int variable that stores the value of the flag.
(*FlagSet) Int16 <- v1.0.1
|
|
Int16 defines an int16 flag with specified name, default value, and usage string. The return value is the address of an int16 variable that stores the value of the flag.
(*FlagSet) Int16P <- v1.0.1
|
|
Int16P is like Int16, but accepts a shorthand letter that can be used after a single dash.
(*FlagSet) Int16Var <- v1.0.1
|
|
Int16Var defines an int16 flag with specified name, default value, and usage string. The argument p points to an int16 variable in which to store the value of the flag.
(*FlagSet) Int16VarP <- v1.0.1
|
|
Int16VarP is like Int16Var, but accepts a shorthand letter that can be used after a single dash.
(*FlagSet) Int32
|
|
Int32 defines an int32 flag with specified name, default value, and usage string. The return value is the address of an int32 variable that stores the value of the flag.
(*FlagSet) Int32P
|
|
Int32P is like Int32, but accepts a shorthand letter that can be used after a single dash.
(*FlagSet) Int32Slice <- v1.0.5
|
|
Int32Slice defines a []int32 flag with specified name, default value, and usage string. The return value is the address of a []int32 variable that stores the value of the flag.
(*FlagSet) Int32SliceP <- v1.0.5
|
|
Int32SliceP is like Int32Slice, but accepts a shorthand letter that can be used after a single dash.
(*FlagSet) Int32SliceVar <- v1.0.5
|
|
Int32SliceVar defines a int32Slice flag with specified name, default value, and usage string. The argument p points to a []int32 variable in which to store the value of the flag.
(*FlagSet) Int32SliceVarP <- v1.0.5
|
|
Int32SliceVarP is like Int32SliceVar, but accepts a shorthand letter that can be used after a single dash.
(*FlagSet) Int32Var
|
|
Int32Var defines an int32 flag with specified name, default value, and usage string. The argument p points to an int32 variable in which to store the value of the flag.
(*FlagSet) Int32VarP
|
|
Int32VarP is like Int32Var, but accepts a shorthand letter that can be used after a single dash.
(*FlagSet) Int64
|
|
Int64 defines an int64 flag with specified name, default value, and usage string. The return value is the address of an int64 variable that stores the value of the flag.
(*FlagSet) Int64P
|
|
Int64P is like Int64, but accepts a shorthand letter that can be used after a single dash.
(*FlagSet) Int64Slice <- v1.0.5
|
|
Int64Slice defines a []int64 flag with specified name, default value, and usage string. The return value is the address of a []int64 variable that stores the value of the flag.
(*FlagSet) Int64SliceP <- v1.0.5
|
|
Int64SliceP is like Int64Slice, but accepts a shorthand letter that can be used after a single dash.
(*FlagSet) Int64SliceVar <- v1.0.5
|
|
Int64SliceVar defines a int64Slice flag with specified name, default value, and usage string. The argument p points to a []int64 variable in which to store the value of the flag.
(*FlagSet) Int64SliceVarP <- v1.0.5
|
|
Int64SliceVarP is like Int64SliceVar, but accepts a shorthand letter that can be used after a single dash.
(*FlagSet) Int64Var
|
|
Int64Var defines an int64 flag with specified name, default value, and usage string. The argument p points to an int64 variable in which to store the value of the flag.
(*FlagSet) Int64VarP
|
|
Int64VarP is like Int64Var, but accepts a shorthand letter that can be used after a single dash.
(*FlagSet) Int8
|
|
Int8 defines an int8 flag with specified name, default value, and usage string. The return value is the address of an int8 variable that stores the value of the flag.
(*FlagSet) Int8P
|
|
Int8P is like Int8, but accepts a shorthand letter that can be used after a single dash.
(*FlagSet) Int8Var
|
|
Int8Var defines an int8 flag with specified name, default value, and usage string. The argument p points to an int8 variable in which to store the value of the flag.
(*FlagSet) Int8VarP
|
|
Int8VarP is like Int8Var, but accepts a shorthand letter that can be used after a single dash.
(*FlagSet) IntP
|
|
IntP is like Int, but accepts a shorthand letter that can be used after a single dash.
(*FlagSet) IntSlice
|
|
IntSlice defines a []int flag with specified name, default value, and usage string. The return value is the address of a []int variable that stores the value of the flag.
(*FlagSet) IntSliceP
|
|
IntSliceP is like IntSlice, but accepts a shorthand letter that can be used after a single dash.
(*FlagSet) IntSliceVar
|
|
IntSliceVar defines a intSlice flag with specified name, default value, and usage string. The argument p points to a []int variable in which to store the value of the flag.
(*FlagSet) IntSliceVarP
|
|
IntSliceVarP is like IntSliceVar, but accepts a shorthand letter that can be used after a single dash.
(*FlagSet) IntVar
|
|
IntVar defines an int flag with specified name, default value, and usage string. The argument p points to an int variable in which to store the value of the flag.
(*FlagSet) IntVarP
|
|
IntVarP is like IntVar, but accepts a shorthand letter that can be used after a single dash.
(*FlagSet) Lookup
|
|
Lookup returns the Flag structure of the named flag, returning nil if none exists.
(*FlagSet) MarkDeprecated
|
|
MarkDeprecated indicated that a flag is deprecated in your program. It will continue to function but will not show up in help or usage messages. Using this flag will also print the given usageMessage.
(*FlagSet) MarkHidden
|
|
MarkHidden sets a flag to ‘hidden’ in your program. It will continue to function but will not show up in help or usage messages.
(*FlagSet) MarkShorthandDeprecated
|
|
MarkShorthandDeprecated will mark the shorthand of a flag deprecated in your program. It will continue to function but will not show up in help or usage messages. Using this flag will also print the given usageMessage.
(*FlagSet) NArg
|
|
NArg is the number of arguments remaining after flags have been processed.
(*FlagSet) NFlag
|
|
NFlag returns the number of flags that have been set.
(*FlagSet) Parse
|
|
Parse parses flag definitions from the argument list, which should not include the command name. Must be called after all flags in the FlagSet are defined and before flags are accessed by the program. The return value will be ErrHelp if -help was set but not defined.
(*FlagSet) ParseAll
|
|
ParseAll parses flag definitions from the argument list, which should not include the command name. The arguments for fn are flag and value. Must be called after all flags in the FlagSet are defined and before flags are accessed by the program. The return value will be ErrHelp if -help was set but not defined.
(*FlagSet) Parsed
|
|
Parsed reports whether f.Parse has been called.
(*FlagSet) PrintDefaults
|
|
PrintDefaults prints, to standard error unless configured otherwise, the default values of all defined flags in the set.
(*FlagSet) Set
|
|
Set sets the value of the named flag.
(*FlagSet) SetAnnotation
|
|
SetAnnotation allows one to set arbitrary annotations on a flag in the FlagSet. This is sometimes used by spf13/cobra programs which want to generate additional bash completion information.
(*FlagSet) SetInterspersed
|
|
SetInterspersed sets whether to support interspersed option/non-option arguments.
(*FlagSet) SetNormalizeFunc
|
|
SetNormalizeFunc allows you to add a function which can translate flag names. Flags added to the FlagSet will be translated and then when anything tries to look up the flag that will also be translated. So it would be possible to create a flag named “getURL” and have it translated to “geturl”. A user could then pass “–getUrl” which may also be translated to “geturl” and everything will work.
(*FlagSet) SetOutput
|
|
SetOutput sets the destination for usage and error messages. If output is nil, os.Stderr is used.
(*FlagSet) ShorthandLookup
|
|
ShorthandLookup returns the Flag structure of the short handed flag, returning nil if none exists. It panics, if len(name) > 1.
Example
(*FlagSet) String
|
|
String defines a string flag with specified name, default value, and usage string. The return value is the address of a string variable that stores the value of the flag.
(*FlagSet) StringArray
|
|
StringArray defines a string flag with specified name, default value, and usage string. The return value is the address of a []string variable that stores the value of the flag. The value of each argument will not try to be separated by comma. Use a StringSlice for that.
(*FlagSet) StringArrayP
|
|
StringArrayP is like StringArray, but accepts a shorthand letter that can be used after a single dash.
(*FlagSet) StringArrayVar
|
|
StringArrayVar defines a string flag with specified name, default value, and usage string. The argument p points to a []string variable in which to store the values of the multiple flags. The value of each argument will not try to be separated by comma. Use a StringSlice for that.
(*FlagSet) StringArrayVarP
|
|
StringArrayVarP is like StringArrayVar, but accepts a shorthand letter that can be used after a single dash.
(*FlagSet) StringP
|
|
StringP is like String, but accepts a shorthand letter that can be used after a single dash.
(*FlagSet) StringSlice
|
|
StringSlice defines a string flag with specified name, default value, and usage string. The return value is the address of a []string variable that stores the value of the flag. Compared to StringArray flags, StringSlice flags take comma-separated value as arguments and split them accordingly. For example:
--ss="v1,v2" --ss="v3"
will result in
[]string{"v1", "v2", "v3"}
(*FlagSet) StringSliceP
|
|
StringSliceP is like StringSlice, but accepts a shorthand letter that can be used after a single dash.
(*FlagSet) StringSliceVar
|
|
StringSliceVar defines a string flag with specified name, default value, and usage string. The argument p points to a []string variable in which to store the value of the flag. Compared to StringArray flags, StringSlice flags take comma-separated value as arguments and split them accordingly. For example:
--ss="v1,v2" --ss="v3"
will result in
[]string{"v1", "v2", "v3"}
(*FlagSet) StringSliceVarP
|
|
StringSliceVarP is like StringSliceVar, but accepts a shorthand letter that can be used after a single dash.
(*FlagSet) StringToInt <- v1.0.3
|
|
StringToInt defines a string flag with specified name, default value, and usage string. The return value is the address of a map[string]int variable that stores the value of the flag. The value of each argument will not try to be separated by comma
(*FlagSet) StringToInt64 <- v1.0.5
|
|
StringToInt64 defines a string flag with specified name, default value, and usage string. The return value is the address of a map[string]int64 variable that stores the value of the flag. The value of each argument will not try to be separated by comma
(*FlagSet) StringToInt64P <- v1.0.5
|
|
StringToInt64P is like StringToInt64, but accepts a shorthand letter that can be used after a single dash.
(*FlagSet) StringToInt64Var <- v1.0.5
|
|
StringToInt64Var defines a string flag with specified name, default value, and usage string. The argument p point64s to a map[string]int64 variable in which to store the values of the multiple flags. The value of each argument will not try to be separated by comma
(*FlagSet) StringToInt64VarP <- v1.0.5
|
|
StringToInt64VarP is like StringToInt64Var, but accepts a shorthand letter that can be used after a single dash.
(*FlagSet) StringToIntP <- v1.0.3
|
|
StringToIntP is like StringToInt, but accepts a shorthand letter that can be used after a single dash.
(*FlagSet) StringToIntVar <- v1.0.3
|
|
StringToIntVar defines a string flag with specified name, default value, and usage string. The argument p points to a map[string]int variable in which to store the values of the multiple flags. The value of each argument will not try to be separated by comma
(*FlagSet) StringToIntVarP <- v1.0.3
|
|
StringToIntVarP is like StringToIntVar, but accepts a shorthand letter that can be used after a single dash.
(*FlagSet) StringToString <- v1.0.3
|
|
StringToString defines a string flag with specified name, default value, and usage string. The return value is the address of a map[string]string variable that stores the value of the flag. The value of each argument will not try to be separated by comma
(*FlagSet) StringToStringP <- v1.0.3
|
|
StringToStringP is like StringToString, but accepts a shorthand letter that can be used after a single dash.
(*FlagSet) StringToStringVar <- v1.0.3
|
|
StringToStringVar defines a string flag with specified name, default value, and usage string. The argument p points to a map[string]string variable in which to store the values of the multiple flags. The value of each argument will not try to be separated by comma
(*FlagSet) StringToStringVarP <- v1.0.3
|
|
StringToStringVarP is like StringToStringVar, but accepts a shorthand letter that can be used after a single dash.
(*FlagSet) StringVar
|
|
StringVar defines a string flag with specified name, default value, and usage string. The argument p points to a string variable in which to store the value of the flag.
(*FlagSet) StringVarP
|
|
StringVarP is like StringVar, but accepts a shorthand letter that can be used after a single dash.
(*FlagSet) Uint
|
|
Uint defines a uint flag with specified name, default value, and usage string. The return value is the address of a uint variable that stores the value of the flag.
(*FlagSet) Uint16
|
|
Uint16 defines a uint flag with specified name, default value, and usage string. The return value is the address of a uint variable that stores the value of the flag.
(*FlagSet) Uint16P
|
|
Uint16P is like Uint16, but accepts a shorthand letter that can be used after a single dash.
(*FlagSet) Uint16Var
|
|
Uint16Var defines a uint flag with specified name, default value, and usage string. The argument p points to a uint variable in which to store the value of the flag.
(*FlagSet) Uint16VarP
|
|
Uint16VarP is like Uint16Var, but accepts a shorthand letter that can be used after a single dash.
(*FlagSet) Uint32
|
|
Uint32 defines a uint32 flag with specified name, default value, and usage string. The return value is the address of a uint32 variable that stores the value of the flag.
(*FlagSet) Uint32P
|
|
Uint32P is like Uint32, but accepts a shorthand letter that can be used after a single dash.
(*FlagSet) Uint32Var
|
|
Uint32Var defines a uint32 flag with specified name, default value, and usage string. The argument p points to a uint32 variable in which to store the value of the flag.
(*FlagSet) Uint32VarP
|
|
Uint32VarP is like Uint32Var, but accepts a shorthand letter that can be used after a single dash.
(*FlagSet) Uint64
|
|
Uint64 defines a uint64 flag with specified name, default value, and usage string. The return value is the address of a uint64 variable that stores the value of the flag.
(*FlagSet) Uint64P
|
|
Uint64P is like Uint64, but accepts a shorthand letter that can be used after a single dash.
(*FlagSet) Uint64Var
|
|
Uint64Var defines a uint64 flag with specified name, default value, and usage string. The argument p points to a uint64 variable in which to store the value of the flag.
(*FlagSet) Uint64VarP
|
|
Uint64VarP is like Uint64Var, but accepts a shorthand letter that can be used after a single dash.
(*FlagSet) Uint8
|
|
Uint8 defines a uint8 flag with specified name, default value, and usage string. The return value is the address of a uint8 variable that stores the value of the flag.
(*FlagSet) Uint8P
|
|
Uint8P is like Uint8, but accepts a shorthand letter that can be used after a single dash.
(*FlagSet) Uint8Var
|
|
Uint8Var defines a uint8 flag with specified name, default value, and usage string. The argument p points to a uint8 variable in which to store the value of the flag.
(*FlagSet) Uint8VarP
|
|
Uint8VarP is like Uint8Var, but accepts a shorthand letter that can be used after a single dash.
(*FlagSet) UintP
|
|
UintP is like Uint, but accepts a shorthand letter that can be used after a single dash.
(*FlagSet) UintSlice
|
|
UintSlice defines a []uint flag with specified name, default value, and usage string. The return value is the address of a []uint variable that stores the value of the flag.
(*FlagSet) UintSliceP
|
|
UintSliceP is like UintSlice, but accepts a shorthand letter that can be used after a single dash.
(*FlagSet) UintSliceVar
|
|
UintSliceVar defines a uintSlice flag with specified name, default value, and usage string. The argument p points to a []uint variable in which to store the value of the flag.
(*FlagSet) UintSliceVarP
|
|
UintSliceVarP is like UintSliceVar, but accepts a shorthand letter that can be used after a single dash.
(*FlagSet) UintVar
|
|
UintVar defines a uint flag with specified name, default value, and usage string. The argument p points to a uint variable in which to store the value of the flag.
(*FlagSet) UintVarP
|
|
UintVarP is like UintVar, but accepts a shorthand letter that can be used after a single dash.
(*FlagSet) Var
|
|
Var defines a flag with the specified name and usage string. The type and value of the flag are represented by the first argument, of type Value, which typically holds a user-defined implementation of Value. For instance, the caller could create a flag that turns a comma-separated string into a slice of strings by giving the slice the methods of Value; in particular, Set would decompose the comma-separated string into the slice.
(*FlagSet) VarP
|
|
VarP is like Var, but accepts a shorthand letter that can be used after a single dash.
(*FlagSet) VarPF
|
|
VarPF is like VarP, but returns the flag created
(*FlagSet) Visit
|
|
Visit visits the flags in lexicographical order or in primordial order if f.SortFlags is false, calling fn for each. It visits only those flags that have been set.
(*FlagSet) VisitAll
|
|
VisitAll visits the flags in lexicographical order or in primordial order if f.SortFlags is false, calling fn for each. It visits all flags, even those not set.
type NormalizedName
|
|
NormalizedName is a flag name that has been normalized according to rules for the FlagSet (e.g. making ‘-’ and ‘_’ equivalent).
type ParseErrorsWhitelist <- v1.0.1
|
|
ParseErrorsWhitelist defines the parsing errors that can be ignored
type SliceValue <- v1.0.5
|
|
SliceValue is a secondary interface to all flags which hold a list of values. This allows full control over the value of list flags, and avoids complicated marshalling and unmarshalling to csv.
type Value
|
|
Value is the interface to the dynamic value stored in a flag. (The default value is represented as a string.)