mirror of https://github.com/k3s-io/k3s
Update spf13/cobra and spf13/pflag
parent
2f1edf7db5
commit
681ee126ff
|
@ -476,12 +476,11 @@
|
|||
},
|
||||
{
|
||||
"ImportPath": "github.com/spf13/cobra",
|
||||
"Rev": "385fc87e4343efec233811d3d933509e8975d11a"
|
||||
"Rev": "db0518444643a7b170abb78164bbeaf5a2bb816f"
|
||||
},
|
||||
{
|
||||
"ImportPath": "github.com/spf13/pflag",
|
||||
"Comment": "v0.0.1-81-g4869ec2",
|
||||
"Rev": "4869ec2ae0628354eaac5bf88fccf9a7265ae475"
|
||||
"Rev": "112aaa578dfdd0e913663b05153be974bd72497a"
|
||||
},
|
||||
{
|
||||
"ImportPath": "github.com/stretchr/objx",
|
||||
|
|
|
@ -13,6 +13,7 @@ import (
|
|||
const (
|
||||
BashCompFilenameExt = "cobra_annotation_bash_completion_filename_extentions"
|
||||
BashCompOneRequiredFlag = "cobra_annotation_bash_completion_one_required_flag"
|
||||
BashCompSubdirsInDir = "cobra_annotation_bash_completion_subdirs_in_dir"
|
||||
)
|
||||
|
||||
func preamble(out *bytes.Buffer) {
|
||||
|
@ -100,6 +101,12 @@ __handle_filename_extension_flag()
|
|||
_filedir "@(${ext})"
|
||||
}
|
||||
|
||||
__handle_subdirs_in_dir_flag()
|
||||
{
|
||||
local dir="$1"
|
||||
pushd "${dir}" >/dev/null 2>&1 && _filedir -d && popd >/dev/null 2>&1
|
||||
}
|
||||
|
||||
__handle_flag()
|
||||
{
|
||||
__debug "${FUNCNAME}: c is $c words[c] is ${words[c]}"
|
||||
|
@ -226,6 +233,16 @@ func writeFlagHandler(name string, annotations map[string][]string, out *bytes.B
|
|||
ext := "_filedir"
|
||||
fmt.Fprintf(out, " flags_completion+=(%q)\n", ext)
|
||||
}
|
||||
case BashCompSubdirsInDir:
|
||||
fmt.Fprintf(out, " flags_with_completion+=(%q)\n", name)
|
||||
|
||||
if len(value) == 1 {
|
||||
ext := "__handle_subdirs_in_dir_flag " + value[0]
|
||||
fmt.Fprintf(out, " flags_completion+=(%q)\n", ext)
|
||||
} else {
|
||||
ext := "_filedir -d"
|
||||
fmt.Fprintf(out, " flags_completion+=(%q)\n", ext)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -56,6 +56,11 @@ func TestBashCompletions(t *testing.T) {
|
|||
c.Flags().StringVar(&flagvalExt, "filename-ext", "", "Enter a filename (extension limited)")
|
||||
c.MarkFlagFilename("filename-ext")
|
||||
|
||||
// subdirectories in a given directory
|
||||
var flagvalTheme string
|
||||
c.Flags().StringVar(&flagvalTheme, "theme", "", "theme to use (located in /themes/THEMENAME/)")
|
||||
c.Flags().SetAnnotation("theme", BashCompSubdirsInDir, []string{"themes"})
|
||||
|
||||
out := new(bytes.Buffer)
|
||||
c.GenBashCompletion(out)
|
||||
str := out.String()
|
||||
|
@ -75,6 +80,8 @@ func TestBashCompletions(t *testing.T) {
|
|||
check(t, str, `flags_completion+=("_filedir")`)
|
||||
// check for filename extension flags
|
||||
check(t, str, `flags_completion+=("__handle_filename_extension_flag json|yaml|yml")`)
|
||||
// check for subdirs_in_dir flags
|
||||
check(t, str, `flags_completion+=("__handle_subdirs_in_dir_flag themes")`)
|
||||
|
||||
checkOmit(t, str, cmdDeprecated.Name())
|
||||
}
|
||||
|
|
|
@ -963,3 +963,11 @@ func TestGlobalNormFuncPropagation(t *testing.T) {
|
|||
t.Error("cmdPrint and cmdEchoSub should had the normalization function of rootCmd")
|
||||
}
|
||||
}
|
||||
|
||||
func TestFlagOnPflagCommandLine(t *testing.T) {
|
||||
flagName := "flagOnCommandLine"
|
||||
pflag.CommandLine.String(flagName, "", "about my flag")
|
||||
r := fullSetupTest("--help")
|
||||
|
||||
checkResultContains(t, r, flagName)
|
||||
}
|
||||
|
|
|
@ -158,7 +158,6 @@ func (c *Command) SetHelpTemplate(s string) {
|
|||
func (c *Command) SetGlobalNormalizationFunc(n func(f *flag.FlagSet, name string) flag.NormalizedName) {
|
||||
c.Flags().SetNormalizeFunc(n)
|
||||
c.PersistentFlags().SetNormalizeFunc(n)
|
||||
c.LocalFlags().SetNormalizeFunc(n)
|
||||
c.globNormFunc = n
|
||||
|
||||
for _, command := range c.commands {
|
||||
|
@ -873,6 +872,13 @@ func (c *Command) LocalFlags() *flag.FlagSet {
|
|||
c.lflags.VisitAll(func(f *flag.Flag) {
|
||||
local.AddFlag(f)
|
||||
})
|
||||
if !c.HasParent() {
|
||||
flag.CommandLine.VisitAll(func(f *flag.Flag) {
|
||||
if local.Lookup(f.Name) == nil {
|
||||
local.AddFlag(f)
|
||||
}
|
||||
})
|
||||
}
|
||||
return local
|
||||
}
|
||||
|
||||
|
|
|
@ -53,7 +53,7 @@ func (f *FlagSet) BoolVar(p *bool, name string, value bool, usage string) {
|
|||
f.BoolVarP(p, name, "", value, usage)
|
||||
}
|
||||
|
||||
// Like BoolVar, but accepts a shorthand letter that can be used after a single dash.
|
||||
// BoolVarP is like BoolVar, but accepts a shorthand letter that can be used after a single dash.
|
||||
func (f *FlagSet) BoolVarP(p *bool, name, shorthand string, value bool, usage string) {
|
||||
flag := f.VarPF(newBoolValue(value, p), name, shorthand, usage)
|
||||
flag.NoOptDefVal = "true"
|
||||
|
@ -65,7 +65,7 @@ func BoolVar(p *bool, name string, value bool, usage string) {
|
|||
BoolVarP(p, name, "", value, usage)
|
||||
}
|
||||
|
||||
// Like BoolVar, but accepts a shorthand letter that can be used after a single dash.
|
||||
// BoolVarP is like BoolVar, but accepts a shorthand letter that can be used after a single dash.
|
||||
func BoolVarP(p *bool, name, shorthand string, value bool, usage string) {
|
||||
flag := CommandLine.VarPF(newBoolValue(value, p), name, shorthand, usage)
|
||||
flag.NoOptDefVal = "true"
|
||||
|
@ -77,7 +77,7 @@ func (f *FlagSet) Bool(name string, value bool, usage string) *bool {
|
|||
return f.BoolP(name, "", value, usage)
|
||||
}
|
||||
|
||||
// Like Bool, but accepts a shorthand letter that can be used after a single dash.
|
||||
// BoolP is like Bool, but accepts a shorthand letter that can be used after a single dash.
|
||||
func (f *FlagSet) BoolP(name, shorthand string, value bool, usage string) *bool {
|
||||
p := new(bool)
|
||||
f.BoolVarP(p, name, shorthand, value, usage)
|
||||
|
@ -90,7 +90,7 @@ func Bool(name string, value bool, usage string) *bool {
|
|||
return BoolP(name, "", value, usage)
|
||||
}
|
||||
|
||||
// Like Bool, but accepts a shorthand letter that can be used after a single dash.
|
||||
// BoolP is like Bool, but accepts a shorthand letter that can be used after a single dash.
|
||||
func BoolP(name, shorthand string, value bool, usage string) *bool {
|
||||
b := CommandLine.BoolP(name, shorthand, value, usage)
|
||||
return b
|
||||
|
|
|
@ -38,6 +38,7 @@ func countConv(sval string) (interface{}, error) {
|
|||
return i, nil
|
||||
}
|
||||
|
||||
// GetCount return the int value of a flag with the given name
|
||||
func (f *FlagSet) GetCount(name string) (int, error) {
|
||||
val, err := f.getFlagType(name, "count", countConv)
|
||||
if err != nil {
|
||||
|
@ -46,39 +47,51 @@ func (f *FlagSet) GetCount(name string) (int, error) {
|
|||
return val.(int), nil
|
||||
}
|
||||
|
||||
// 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 evey time it is found on the command line
|
||||
func (f *FlagSet) CountVar(p *int, name string, usage string) {
|
||||
f.CountVarP(p, name, "", usage)
|
||||
}
|
||||
|
||||
// CountVarP is like CountVar only take a shorthand for the flag name.
|
||||
func (f *FlagSet) CountVarP(p *int, name, shorthand string, usage string) {
|
||||
flag := f.VarPF(newCountValue(0, p), name, shorthand, usage)
|
||||
flag.NoOptDefVal = "-1"
|
||||
}
|
||||
|
||||
// CountVar like CountVar only the flag is placed on the CommandLine instead of a given flag set
|
||||
func CountVar(p *int, name string, usage string) {
|
||||
CommandLine.CountVar(p, name, usage)
|
||||
}
|
||||
|
||||
// CountVarP is like CountVar only take a shorthand for the flag name.
|
||||
func CountVarP(p *int, name, shorthand string, usage string) {
|
||||
CommandLine.CountVarP(p, name, shorthand, usage)
|
||||
}
|
||||
|
||||
// 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 (f *FlagSet) Count(name string, usage string) *int {
|
||||
p := new(int)
|
||||
f.CountVarP(p, name, "", usage)
|
||||
return p
|
||||
}
|
||||
|
||||
// CountP is like Count only takes a shorthand for the flag name.
|
||||
func (f *FlagSet) CountP(name, shorthand string, usage string) *int {
|
||||
p := new(int)
|
||||
f.CountVarP(p, name, shorthand, usage)
|
||||
return p
|
||||
}
|
||||
|
||||
// Count like Count only the flag is placed on the CommandLine isntead of a given flag set
|
||||
func Count(name string, usage string) *int {
|
||||
return CommandLine.CountP(name, "", usage)
|
||||
}
|
||||
|
||||
// CountP is like Count only takes a shorthand for the flag name.
|
||||
func CountP(name, shorthand string, usage string) *int {
|
||||
return CommandLine.CountP(name, shorthand, usage)
|
||||
}
|
||||
|
|
|
@ -43,7 +43,7 @@ func (f *FlagSet) DurationVar(p *time.Duration, name string, value time.Duration
|
|||
f.VarP(newDurationValue(value, p), name, "", usage)
|
||||
}
|
||||
|
||||
// Like DurationVar, but accepts a shorthand letter that can be used after a single dash.
|
||||
// DurationVarP is like DurationVar, but accepts a shorthand letter that can be used after a single dash.
|
||||
func (f *FlagSet) DurationVarP(p *time.Duration, name, shorthand string, value time.Duration, usage string) {
|
||||
f.VarP(newDurationValue(value, p), name, shorthand, usage)
|
||||
}
|
||||
|
@ -54,7 +54,7 @@ func DurationVar(p *time.Duration, name string, value time.Duration, usage strin
|
|||
CommandLine.VarP(newDurationValue(value, p), name, "", usage)
|
||||
}
|
||||
|
||||
// Like DurationVar, but accepts a shorthand letter that can be used after a single dash.
|
||||
// DurationVarP is like DurationVar, but accepts a shorthand letter that can be used after a single dash.
|
||||
func DurationVarP(p *time.Duration, name, shorthand string, value time.Duration, usage string) {
|
||||
CommandLine.VarP(newDurationValue(value, p), name, shorthand, usage)
|
||||
}
|
||||
|
@ -67,7 +67,7 @@ func (f *FlagSet) Duration(name string, value time.Duration, usage string) *time
|
|||
return p
|
||||
}
|
||||
|
||||
// Like Duration, but accepts a shorthand letter that can be used after a single dash.
|
||||
// DurationP is like Duration, but accepts a shorthand letter that can be used after a single dash.
|
||||
func (f *FlagSet) DurationP(name, shorthand string, value time.Duration, usage string) *time.Duration {
|
||||
p := new(time.Duration)
|
||||
f.DurationVarP(p, name, shorthand, value, usage)
|
||||
|
@ -80,7 +80,7 @@ func Duration(name string, value time.Duration, usage string) *time.Duration {
|
|||
return CommandLine.DurationP(name, "", value, usage)
|
||||
}
|
||||
|
||||
// Like Duration, but accepts a shorthand letter that can be used after a single dash.
|
||||
// DurationP is like Duration, but accepts a shorthand letter that can be used after a single dash.
|
||||
func DurationP(name, shorthand string, value time.Duration, usage string) *time.Duration {
|
||||
return CommandLine.DurationP(name, shorthand, value, usage)
|
||||
}
|
||||
|
|
|
@ -3,98 +3,98 @@
|
|||
// license that can be found in the LICENSE file.
|
||||
|
||||
/*
|
||||
pflag is a drop-in replacement for Go's flag package, implementing
|
||||
POSIX/GNU-style --flags.
|
||||
Package pflag is a drop-in replacement for Go's flag package, implementing
|
||||
POSIX/GNU-style --flags.
|
||||
|
||||
pflag is compatible with the GNU extensions to the POSIX recommendations
|
||||
for command-line options. See
|
||||
http://www.gnu.org/software/libc/manual/html_node/Argument-Syntax.html
|
||||
pflag is compatible with the GNU extensions to the POSIX recommendations
|
||||
for command-line options. See
|
||||
http://www.gnu.org/software/libc/manual/html_node/Argument-Syntax.html
|
||||
|
||||
Usage:
|
||||
Usage:
|
||||
|
||||
pflag is a drop-in replacement of Go's native flag package. If you import
|
||||
pflag under the name "flag" then all code should continue to function
|
||||
with no changes.
|
||||
pflag is a drop-in replacement of Go's native flag package. If you import
|
||||
pflag under the name "flag" then all code should continue to function
|
||||
with no changes.
|
||||
|
||||
import flag "github.com/ogier/pflag"
|
||||
import flag "github.com/ogier/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.
|
||||
there is one more field "Shorthand" that you will need to set.
|
||||
Most code never instantiates this struct directly, and instead uses
|
||||
functions such as String(), BoolVar(), and Var(), and is therefore
|
||||
unaffected.
|
||||
|
||||
Define flags using flag.String(), Bool(), Int(), etc.
|
||||
Define flags using flag.String(), Bool(), Int(), etc.
|
||||
|
||||
This declares an integer flag, -flagname, stored in the pointer ip, with type *int.
|
||||
var ip = flag.Int("flagname", 1234, "help message for flagname")
|
||||
If you like, you can bind the flag to a variable using the Var() functions.
|
||||
var flagvar int
|
||||
func init() {
|
||||
flag.IntVar(&flagvar, "flagname", 1234, "help message for flagname")
|
||||
}
|
||||
Or you can create custom flags that satisfy the Value interface (with
|
||||
pointer receivers) and couple them to flag parsing by
|
||||
flag.Var(&flagVal, "name", "help message for flagname")
|
||||
For such flags, the default value is just the initial value of the variable.
|
||||
This declares an integer flag, -flagname, stored in the pointer ip, with type *int.
|
||||
var ip = flag.Int("flagname", 1234, "help message for flagname")
|
||||
If you like, you can bind the flag to a variable using the Var() functions.
|
||||
var flagvar int
|
||||
func init() {
|
||||
flag.IntVar(&flagvar, "flagname", 1234, "help message for flagname")
|
||||
}
|
||||
Or you can create custom flags that satisfy the Value interface (with
|
||||
pointer receivers) and couple them to flag parsing by
|
||||
flag.Var(&flagVal, "name", "help message for flagname")
|
||||
For such flags, the default value is just the initial value of the variable.
|
||||
|
||||
After all flags are defined, call
|
||||
flag.Parse()
|
||||
to parse the command line into the defined flags.
|
||||
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)
|
||||
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.
|
||||
After parsing, the arguments after the flag are available as the
|
||||
slice flag.Args() or individually as flag.Arg(i).
|
||||
The arguments are indexed from 0 through flag.NArg()-1.
|
||||
|
||||
The pflag package also defines some new functions that are not in flag,
|
||||
that give one-letter shorthands for flags. You can use these by appending
|
||||
'P' to the name of any function that defines a flag.
|
||||
var ip = flag.IntP("flagname", "f", 1234, "help message")
|
||||
var flagvar bool
|
||||
func init() {
|
||||
flag.BoolVarP("boolname", "b", true, "help message")
|
||||
}
|
||||
flag.VarP(&flagVar, "varname", "v", 1234, "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 pflag package also defines some new functions that are not in flag,
|
||||
that give one-letter shorthands for flags. You can use these by appending
|
||||
'P' to the name of any function that defines a flag.
|
||||
var ip = flag.IntP("flagname", "f", 1234, "help message")
|
||||
var flagvar bool
|
||||
func init() {
|
||||
flag.BoolVarP("boolname", "b", true, "help message")
|
||||
}
|
||||
flag.VarP(&flagVar, "varname", "v", 1234, "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
|
||||
Command line flag syntax:
|
||||
--flag // boolean flags only
|
||||
--flag=x
|
||||
|
||||
Unlike the flag package, a single dash before an option means something
|
||||
different than a double dash. Single dashes signify a series of shorthand
|
||||
letters for flags. All but the last shorthand letter must be boolean flags.
|
||||
// boolean flags
|
||||
-f
|
||||
-abc
|
||||
// non-boolean flags
|
||||
-n 1234
|
||||
-Ifile
|
||||
// mixed
|
||||
-abcs "hello"
|
||||
-abcn1234
|
||||
Unlike the flag package, a single dash before an option means something
|
||||
different than a double dash. Single dashes signify a series of shorthand
|
||||
letters for flags. All but the last shorthand letter must be boolean flags.
|
||||
// boolean flags
|
||||
-f
|
||||
-abc
|
||||
// non-boolean flags
|
||||
-n 1234
|
||||
-Ifile
|
||||
// mixed
|
||||
-abcs "hello"
|
||||
-abcn1234
|
||||
|
||||
Flag parsing stops after the terminator "--". Unlike the flag package,
|
||||
flags can be interspersed with arguments anywhere on the command line
|
||||
before this terminator.
|
||||
Flag parsing stops after the terminator "--". Unlike the flag package,
|
||||
flags can be interspersed with arguments anywhere on the command line
|
||||
before this terminator.
|
||||
|
||||
Integer flags accept 1234, 0664, 0x1234 and may be negative.
|
||||
Boolean flags (in their long form) accept 1, 0, t, f, true, false,
|
||||
TRUE, FALSE, True, False.
|
||||
Duration flags accept any input valid for time.ParseDuration.
|
||||
Integer flags accept 1234, 0664, 0x1234 and may be negative.
|
||||
Boolean flags (in their long form) accept 1, 0, t, f, true, false,
|
||||
TRUE, FALSE, True, False.
|
||||
Duration flags accept any input valid for time.ParseDuration.
|
||||
|
||||
The default set of command-line flags is controlled by
|
||||
top-level functions. The FlagSet type allows one to define
|
||||
independent sets of flags, such as to implement subcommands
|
||||
in a command-line interface. The methods of FlagSet are
|
||||
analogous to the top-level functions for the command-line
|
||||
flag set.
|
||||
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.
|
||||
*/
|
||||
package pflag
|
||||
|
||||
|
@ -115,8 +115,11 @@ var ErrHelp = errors.New("pflag: help requested")
|
|||
type ErrorHandling int
|
||||
|
||||
const (
|
||||
// ContinueOnError will return an err from Parse() if an error is found
|
||||
ContinueOnError ErrorHandling = iota
|
||||
// ExitOnError will call os.Exit(2) if an error is found when parsing
|
||||
ExitOnError
|
||||
// PanicOnError will panic() if an error is found when parsing flags
|
||||
PanicOnError
|
||||
)
|
||||
|
||||
|
@ -181,6 +184,11 @@ func sortFlags(flags map[NormalizedName]*Flag) []*Flag {
|
|||
return result
|
||||
}
|
||||
|
||||
// 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.
|
||||
func (f *FlagSet) SetNormalizeFunc(n func(f *FlagSet, name string) NormalizedName) {
|
||||
f.normalizeNameFunc = n
|
||||
for k, v := range f.formal {
|
||||
|
@ -191,6 +199,8 @@ func (f *FlagSet) SetNormalizeFunc(n func(f *FlagSet, name string) NormalizedNam
|
|||
}
|
||||
}
|
||||
|
||||
// GetNormalizeFunc returns the previously set NormalizeFunc of a function which
|
||||
// does no translation, if not set previously.
|
||||
func (f *FlagSet) GetNormalizeFunc() func(f *FlagSet, name string) NormalizedName {
|
||||
if f.normalizeNameFunc != nil {
|
||||
return f.normalizeNameFunc
|
||||
|
@ -224,6 +234,7 @@ func (f *FlagSet) VisitAll(fn func(*Flag)) {
|
|||
}
|
||||
}
|
||||
|
||||
// HasFlags returns a bool to indicate if the FlagSet has any flags definied.
|
||||
func (f *FlagSet) HasFlags() bool {
|
||||
return len(f.formal) > 0
|
||||
}
|
||||
|
@ -279,7 +290,9 @@ func (f *FlagSet) getFlagType(name string, ftype string, convFunc func(sval stri
|
|||
return result, nil
|
||||
}
|
||||
|
||||
// Mark a flag deprecated in your program
|
||||
// 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.
|
||||
func (f *FlagSet) MarkDeprecated(name string, usageMessage string) error {
|
||||
flag := f.Lookup(name)
|
||||
if flag == nil {
|
||||
|
@ -317,6 +330,9 @@ func (f *FlagSet) Set(name, value string) error {
|
|||
return nil
|
||||
}
|
||||
|
||||
// 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.
|
||||
func (f *FlagSet) SetAnnotation(name, key string, values []string) error {
|
||||
normalName := f.normalizeFlagName(name)
|
||||
flag, ok := f.formal[normalName]
|
||||
|
@ -330,6 +346,8 @@ func (f *FlagSet) SetAnnotation(name, key string, values []string) error {
|
|||
return nil
|
||||
}
|
||||
|
||||
// Changed returns true if the flag was explicitly set during Parse() and false
|
||||
// otherwise
|
||||
func (f *FlagSet) Changed(name string) bool {
|
||||
flag := f.Lookup(name)
|
||||
// If a flag doesn't exist, it wasn't changed....
|
||||
|
@ -347,12 +365,20 @@ func Set(name, value string) error {
|
|||
// PrintDefaults prints, to standard error unless configured
|
||||
// otherwise, the default values of all defined flags in the set.
|
||||
func (f *FlagSet) PrintDefaults() {
|
||||
usages := f.FlagUsages()
|
||||
fmt.Fprintf(f.out(), "%s", usages)
|
||||
}
|
||||
|
||||
// FlagUsages Returns a string containing the usage information for all flags in
|
||||
// the FlagSet
|
||||
func (f *FlagSet) FlagUsages() string {
|
||||
x := new(bytes.Buffer)
|
||||
|
||||
f.VisitAll(func(flag *Flag) {
|
||||
if len(flag.Deprecated) > 0 {
|
||||
return
|
||||
}
|
||||
format := ""
|
||||
// ex: w/ option string argument '-%s, --%s[=%q]: %s\n'
|
||||
if len(flag.Shorthand) > 0 {
|
||||
format = " -%s, --%s"
|
||||
} else {
|
||||
|
@ -361,7 +387,8 @@ func (f *FlagSet) PrintDefaults() {
|
|||
if len(flag.NoOptDefVal) > 0 {
|
||||
format = format + "["
|
||||
}
|
||||
if _, ok := flag.Value.(*stringValue); ok {
|
||||
if flag.Value.Type() == "string" {
|
||||
// put quotes on the value
|
||||
format = format + "=%q"
|
||||
} else {
|
||||
format = format + "=%s"
|
||||
|
@ -370,27 +397,6 @@ func (f *FlagSet) PrintDefaults() {
|
|||
format = format + "]"
|
||||
}
|
||||
format = format + ": %s\n"
|
||||
fmt.Fprintf(f.out(), format, flag.Shorthand, flag.Name, flag.DefValue, flag.Usage)
|
||||
})
|
||||
}
|
||||
|
||||
func (f *FlagSet) FlagUsages() string {
|
||||
x := new(bytes.Buffer)
|
||||
|
||||
f.VisitAll(func(flag *Flag) {
|
||||
if len(flag.Deprecated) > 0 {
|
||||
return
|
||||
}
|
||||
format := "--%s=%s: %s\n"
|
||||
if _, ok := flag.Value.(*stringValue); ok {
|
||||
// put quotes on the value
|
||||
format = "--%s=%q: %s\n"
|
||||
}
|
||||
if len(flag.Shorthand) > 0 {
|
||||
format = " -%s, " + format
|
||||
} else {
|
||||
format = " %s " + format
|
||||
}
|
||||
fmt.Fprintf(x, format, flag.Shorthand, flag.Name, flag.DefValue, flag.Usage)
|
||||
})
|
||||
|
||||
|
@ -462,7 +468,7 @@ func (f *FlagSet) Var(value Value, name string, usage string) {
|
|||
f.VarP(value, name, "", usage)
|
||||
}
|
||||
|
||||
// Like VarP, but returns the flag created
|
||||
// VarPF is like VarP, but returns the flag created
|
||||
func (f *FlagSet) VarPF(value Value, name, shorthand, usage string) *Flag {
|
||||
// Remember the default value as a string; it won't change.
|
||||
flag := &Flag{
|
||||
|
@ -476,14 +482,15 @@ func (f *FlagSet) VarPF(value Value, name, shorthand, usage string) *Flag {
|
|||
return flag
|
||||
}
|
||||
|
||||
// Like Var, but accepts a shorthand letter that can be used after a single dash.
|
||||
// VarP is like Var, but accepts a shorthand letter that can be used after a single dash.
|
||||
func (f *FlagSet) VarP(value Value, name, shorthand, usage string) {
|
||||
_ = f.VarPF(value, name, shorthand, usage)
|
||||
}
|
||||
|
||||
// AddFlag will add the flag to the FlagSet
|
||||
func (f *FlagSet) AddFlag(flag *Flag) {
|
||||
// Call normalizeFlagName function only once
|
||||
var normalizedFlagName NormalizedName = f.normalizeFlagName(flag.Name)
|
||||
normalizedFlagName := f.normalizeFlagName(flag.Name)
|
||||
|
||||
_, alreadythere := f.formal[normalizedFlagName]
|
||||
if alreadythere {
|
||||
|
@ -517,6 +524,19 @@ func (f *FlagSet) AddFlag(flag *Flag) {
|
|||
f.shorthands[c] = flag
|
||||
}
|
||||
|
||||
// AddFlagSet adds one FlagSet to another. If a flag is already present in f
|
||||
// the flag from newSet will be ignored
|
||||
func (f *FlagSet) AddFlagSet(newSet *FlagSet) {
|
||||
if newSet == nil {
|
||||
return
|
||||
}
|
||||
newSet.VisitAll(func(flag *Flag) {
|
||||
if f.Lookup(flag.Name) == nil {
|
||||
f.AddFlag(flag)
|
||||
}
|
||||
})
|
||||
}
|
||||
|
||||
// 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
|
||||
|
@ -527,7 +547,7 @@ func Var(value Value, name string, usage string) {
|
|||
CommandLine.VarP(value, name, "", usage)
|
||||
}
|
||||
|
||||
// Like Var, but accepts a shorthand letter that can be used after a single dash.
|
||||
// VarP is like Var, but accepts a shorthand letter that can be used after a single dash.
|
||||
func VarP(value Value, name, shorthand, usage string) {
|
||||
CommandLine.VarP(value, name, shorthand, usage)
|
||||
}
|
||||
|
@ -720,7 +740,7 @@ func Parse() {
|
|||
CommandLine.Parse(os.Args[1:])
|
||||
}
|
||||
|
||||
// Whether to support interspersed option/non-option arguments.
|
||||
// SetInterspersed sets whether to support interspersed option/non-option arguments.
|
||||
func SetInterspersed(interspersed bool) {
|
||||
CommandLine.SetInterspersed(interspersed)
|
||||
}
|
||||
|
@ -744,7 +764,7 @@ func NewFlagSet(name string, errorHandling ErrorHandling) *FlagSet {
|
|||
return f
|
||||
}
|
||||
|
||||
// Whether to support interspersed option/non-option arguments.
|
||||
// SetIntersperesed sets whether to support interspersed option/non-option arguments.
|
||||
func (f *FlagSet) SetInterspersed(interspersed bool) {
|
||||
f.interspersed = interspersed
|
||||
}
|
||||
|
|
|
@ -19,15 +19,15 @@ import (
|
|||
)
|
||||
|
||||
var (
|
||||
test_bool = Bool("test_bool", false, "bool value")
|
||||
test_int = Int("test_int", 0, "int value")
|
||||
test_int64 = Int64("test_int64", 0, "int64 value")
|
||||
test_uint = Uint("test_uint", 0, "uint value")
|
||||
test_uint64 = Uint64("test_uint64", 0, "uint64 value")
|
||||
test_string = String("test_string", "0", "string value")
|
||||
test_float64 = Float64("test_float64", 0, "float64 value")
|
||||
test_duration = Duration("test_duration", 0, "time.Duration value")
|
||||
test_optional_int = Int("test_optional_int", 0, "optional int value")
|
||||
testBool = Bool("test_bool", false, "bool value")
|
||||
testInt = Int("test_int", 0, "int value")
|
||||
testInt64 = Int64("test_int64", 0, "int64 value")
|
||||
testUint = Uint("test_uint", 0, "uint value")
|
||||
testUint64 = Uint64("test_uint64", 0, "uint64 value")
|
||||
testString = String("test_string", "0", "string value")
|
||||
testFloat = Float64("test_float64", 0, "float64 value")
|
||||
testDuration = Duration("test_duration", 0, "time.Duration value")
|
||||
testOptionalInt = Int("test_optional_int", 0, "optional int value")
|
||||
normalizeFlagNameInvocations = 0
|
||||
)
|
||||
|
||||
|
@ -110,6 +110,23 @@ func TestUsage(t *testing.T) {
|
|||
}
|
||||
}
|
||||
|
||||
func TestAddFlagSet(t *testing.T) {
|
||||
oldSet := NewFlagSet("old", ContinueOnError)
|
||||
newSet := NewFlagSet("new", ContinueOnError)
|
||||
|
||||
oldSet.String("flag1", "flag1", "flag1")
|
||||
oldSet.String("flag2", "flag2", "flag2")
|
||||
|
||||
newSet.String("flag2", "flag2", "flag2")
|
||||
newSet.String("flag3", "flag3", "flag3")
|
||||
|
||||
oldSet.AddFlagSet(newSet)
|
||||
|
||||
if len(oldSet.formal) != 3 {
|
||||
t.Errorf("Unexpected result adding a FlagSet to a FlagSet %v", oldSet)
|
||||
}
|
||||
}
|
||||
|
||||
func TestAnnotation(t *testing.T) {
|
||||
f := NewFlagSet("shorthand", ContinueOnError)
|
||||
|
||||
|
@ -291,7 +308,7 @@ func testParse(f *FlagSet, t *testing.T) {
|
|||
t.Error("mask flag should be 255.255.255.0, is ", (*maskFlag).String())
|
||||
}
|
||||
if v, err := f.GetIPv4Mask("mask"); err != nil || v.String() != (*maskFlag).String() {
|
||||
t.Errorf("GetIP returned %v but maskFlag was %v", v, *maskFlag, err)
|
||||
t.Errorf("GetIP returned %v maskFlag was %v error was %v", v, *maskFlag, err)
|
||||
}
|
||||
if *durationFlag != 2*time.Minute {
|
||||
t.Error("duration flag should be 2m, is ", *durationFlag)
|
||||
|
|
|
@ -48,7 +48,7 @@ func (f *FlagSet) Float32Var(p *float32, name string, value float32, usage strin
|
|||
f.VarP(newFloat32Value(value, p), name, "", usage)
|
||||
}
|
||||
|
||||
// Like Float32Var, but accepts a shorthand letter that can be used after a single dash.
|
||||
// Float32VarP is like Float32Var, but accepts a shorthand letter that can be used after a single dash.
|
||||
func (f *FlagSet) Float32VarP(p *float32, name, shorthand string, value float32, usage string) {
|
||||
f.VarP(newFloat32Value(value, p), name, shorthand, usage)
|
||||
}
|
||||
|
@ -59,7 +59,7 @@ func Float32Var(p *float32, name string, value float32, usage string) {
|
|||
CommandLine.VarP(newFloat32Value(value, p), name, "", usage)
|
||||
}
|
||||
|
||||
// Like Float32Var, but accepts a shorthand letter that can be used after a single dash.
|
||||
// Float32VarP is like Float32Var, but accepts a shorthand letter that can be used after a single dash.
|
||||
func Float32VarP(p *float32, name, shorthand string, value float32, usage string) {
|
||||
CommandLine.VarP(newFloat32Value(value, p), name, shorthand, usage)
|
||||
}
|
||||
|
@ -72,7 +72,7 @@ func (f *FlagSet) Float32(name string, value float32, usage string) *float32 {
|
|||
return p
|
||||
}
|
||||
|
||||
// Like Float32, but accepts a shorthand letter that can be used after a single dash.
|
||||
// Float32P is like Float32, but accepts a shorthand letter that can be used after a single dash.
|
||||
func (f *FlagSet) Float32P(name, shorthand string, value float32, usage string) *float32 {
|
||||
p := new(float32)
|
||||
f.Float32VarP(p, name, shorthand, value, usage)
|
||||
|
@ -85,7 +85,7 @@ func Float32(name string, value float32, usage string) *float32 {
|
|||
return CommandLine.Float32P(name, "", value, usage)
|
||||
}
|
||||
|
||||
// Like Float32, but accepts a shorthand letter that can be used after a single dash.
|
||||
// Float32P is like Float32, but accepts a shorthand letter that can be used after a single dash.
|
||||
func Float32P(name, shorthand string, value float32, usage string) *float32 {
|
||||
return CommandLine.Float32P(name, shorthand, value, usage)
|
||||
}
|
||||
|
|
|
@ -44,7 +44,7 @@ func (f *FlagSet) Float64Var(p *float64, name string, value float64, usage strin
|
|||
f.VarP(newFloat64Value(value, p), name, "", usage)
|
||||
}
|
||||
|
||||
// Like Float64Var, but accepts a shorthand letter that can be used after a single dash.
|
||||
// Float64VarP is like Float64Var, but accepts a shorthand letter that can be used after a single dash.
|
||||
func (f *FlagSet) Float64VarP(p *float64, name, shorthand string, value float64, usage string) {
|
||||
f.VarP(newFloat64Value(value, p), name, shorthand, usage)
|
||||
}
|
||||
|
@ -55,7 +55,7 @@ func Float64Var(p *float64, name string, value float64, usage string) {
|
|||
CommandLine.VarP(newFloat64Value(value, p), name, "", usage)
|
||||
}
|
||||
|
||||
// Like Float64Var, but accepts a shorthand letter that can be used after a single dash.
|
||||
// Float64VarP is like Float64Var, but accepts a shorthand letter that can be used after a single dash.
|
||||
func Float64VarP(p *float64, name, shorthand string, value float64, usage string) {
|
||||
CommandLine.VarP(newFloat64Value(value, p), name, shorthand, usage)
|
||||
}
|
||||
|
@ -68,7 +68,7 @@ func (f *FlagSet) Float64(name string, value float64, usage string) *float64 {
|
|||
return p
|
||||
}
|
||||
|
||||
// Like Float64, but accepts a shorthand letter that can be used after a single dash.
|
||||
// Float64P is like Float64, but accepts a shorthand letter that can be used after a single dash.
|
||||
func (f *FlagSet) Float64P(name, shorthand string, value float64, usage string) *float64 {
|
||||
p := new(float64)
|
||||
f.Float64VarP(p, name, shorthand, value, usage)
|
||||
|
@ -81,7 +81,7 @@ func Float64(name string, value float64, usage string) *float64 {
|
|||
return CommandLine.Float64P(name, "", value, usage)
|
||||
}
|
||||
|
||||
// Like Float64, but accepts a shorthand letter that can be used after a single dash.
|
||||
// Float64P is like Float64, but accepts a shorthand letter that can be used after a single dash.
|
||||
func Float64P(name, shorthand string, value float64, usage string) *float64 {
|
||||
return CommandLine.Float64P(name, shorthand, value, usage)
|
||||
}
|
||||
|
|
|
@ -0,0 +1,94 @@
|
|||
// Copyright 2009 The Go Authors. All rights reserved.
|
||||
// Use of this source code is governed by a BSD-style
|
||||
// license that can be found in the LICENSE file.
|
||||
|
||||
package pflag
|
||||
|
||||
import (
|
||||
goflag "flag"
|
||||
"fmt"
|
||||
"reflect"
|
||||
"strings"
|
||||
)
|
||||
|
||||
var _ = fmt.Print
|
||||
|
||||
// flagValueWrapper implements pflag.Value around a flag.Value. The main
|
||||
// difference here is the addition of the Type method that returns a string
|
||||
// name of the type. As this is generally unknown, we approximate that with
|
||||
// reflection.
|
||||
type flagValueWrapper struct {
|
||||
inner goflag.Value
|
||||
flagType string
|
||||
}
|
||||
|
||||
// We are just copying the boolFlag interface out of goflag as that is what
|
||||
// they use to decide if a flag should get "true" when no arg is given.
|
||||
type goBoolFlag interface {
|
||||
goflag.Value
|
||||
IsBoolFlag() bool
|
||||
}
|
||||
|
||||
func wrapFlagValue(v goflag.Value) Value {
|
||||
// If the flag.Value happens to also be a pflag.Value, just use it directly.
|
||||
if pv, ok := v.(Value); ok {
|
||||
return pv
|
||||
}
|
||||
|
||||
pv := &flagValueWrapper{
|
||||
inner: v,
|
||||
}
|
||||
|
||||
t := reflect.TypeOf(v)
|
||||
if t.Kind() == reflect.Interface || t.Kind() == reflect.Ptr {
|
||||
t = t.Elem()
|
||||
}
|
||||
|
||||
pv.flagType = strings.TrimSuffix(t.Name(), "Value")
|
||||
return pv
|
||||
}
|
||||
|
||||
func (v *flagValueWrapper) String() string {
|
||||
return v.inner.String()
|
||||
}
|
||||
|
||||
func (v *flagValueWrapper) Set(s string) error {
|
||||
return v.inner.Set(s)
|
||||
}
|
||||
|
||||
func (v *flagValueWrapper) Type() string {
|
||||
return v.flagType
|
||||
}
|
||||
|
||||
func PFlagFromGoFlag(goflag *goflag.Flag) *Flag {
|
||||
// Remember the default value as a string; it won't change.
|
||||
flag := &Flag{
|
||||
Name: goflag.Name,
|
||||
Usage: goflag.Usage,
|
||||
Value: wrapFlagValue(goflag.Value),
|
||||
// Looks like golang flags don't set DefValue correctly :-(
|
||||
//DefValue: goflag.DefValue,
|
||||
DefValue: goflag.Value.String(),
|
||||
}
|
||||
if fv, ok := goflag.Value.(goBoolFlag); ok && fv.IsBoolFlag() {
|
||||
flag.NoOptDefVal = "true"
|
||||
}
|
||||
return flag
|
||||
}
|
||||
|
||||
func (f *FlagSet) AddGoFlag(goflag *goflag.Flag) {
|
||||
if f.Lookup(goflag.Name) != nil {
|
||||
return
|
||||
}
|
||||
newflag := PFlagFromGoFlag(goflag)
|
||||
f.AddFlag(newflag)
|
||||
}
|
||||
|
||||
func (f *FlagSet) AddGoFlagSet(newSet *goflag.FlagSet) {
|
||||
if newSet == nil {
|
||||
return
|
||||
}
|
||||
newSet.VisitAll(func(goflag *goflag.Flag) {
|
||||
f.AddGoFlag(goflag)
|
||||
})
|
||||
}
|
|
@ -0,0 +1,39 @@
|
|||
// Copyright 2009 The Go Authors. All rights reserved.
|
||||
// Use of this source code is governed by a BSD-style
|
||||
// license that can be found in the LICENSE file.
|
||||
|
||||
package pflag
|
||||
|
||||
import (
|
||||
goflag "flag"
|
||||
"testing"
|
||||
)
|
||||
|
||||
func TestGoflags(t *testing.T) {
|
||||
goflag.String("stringFlag", "stringFlag", "stringFlag")
|
||||
goflag.Bool("boolFlag", false, "boolFlag")
|
||||
|
||||
f := NewFlagSet("test", ContinueOnError)
|
||||
|
||||
f.AddGoFlagSet(goflag.CommandLine)
|
||||
err := f.Parse([]string{"--stringFlag=bob", "--boolFlag"})
|
||||
if err != nil {
|
||||
t.Fatal("expected no error; get", err)
|
||||
}
|
||||
|
||||
getString, err := f.GetString("stringFlag")
|
||||
if err != nil {
|
||||
t.Fatal("expected no error; get", err)
|
||||
}
|
||||
if getString != "bob" {
|
||||
t.Fatalf("expected getString=bob but got getString=%s", getString)
|
||||
}
|
||||
|
||||
getBool, err := f.GetBool("boolFlag")
|
||||
if err != nil {
|
||||
t.Fatal("expected no error; get", err)
|
||||
}
|
||||
if getBool != true {
|
||||
t.Fatalf("expected getBool=true but got getBool=%v", getBool)
|
||||
}
|
||||
}
|
|
@ -44,7 +44,7 @@ func (f *FlagSet) IntVar(p *int, name string, value int, usage string) {
|
|||
f.VarP(newIntValue(value, p), name, "", usage)
|
||||
}
|
||||
|
||||
// Like IntVar, but accepts a shorthand letter that can be used after a single dash.
|
||||
// IntVarP is like IntVar, but accepts a shorthand letter that can be used after a single dash.
|
||||
func (f *FlagSet) IntVarP(p *int, name, shorthand string, value int, usage string) {
|
||||
f.VarP(newIntValue(value, p), name, shorthand, usage)
|
||||
}
|
||||
|
@ -55,7 +55,7 @@ func IntVar(p *int, name string, value int, usage string) {
|
|||
CommandLine.VarP(newIntValue(value, p), name, "", usage)
|
||||
}
|
||||
|
||||
// Like IntVar, but accepts a shorthand letter that can be used after a single dash.
|
||||
// IntVarP is like IntVar, but accepts a shorthand letter that can be used after a single dash.
|
||||
func IntVarP(p *int, name, shorthand string, value int, usage string) {
|
||||
CommandLine.VarP(newIntValue(value, p), name, shorthand, usage)
|
||||
}
|
||||
|
@ -68,7 +68,7 @@ func (f *FlagSet) Int(name string, value int, usage string) *int {
|
|||
return p
|
||||
}
|
||||
|
||||
// Like Int, but accepts a shorthand letter that can be used after a single dash.
|
||||
// IntP is like Int, but accepts a shorthand letter that can be used after a single dash.
|
||||
func (f *FlagSet) IntP(name, shorthand string, value int, usage string) *int {
|
||||
p := new(int)
|
||||
f.IntVarP(p, name, shorthand, value, usage)
|
||||
|
@ -81,7 +81,7 @@ func Int(name string, value int, usage string) *int {
|
|||
return CommandLine.IntP(name, "", value, usage)
|
||||
}
|
||||
|
||||
// Like Int, but accepts a shorthand letter that can be used after a single dash.
|
||||
// IntP is like Int, but accepts a shorthand letter that can be used after a single dash.
|
||||
func IntP(name, shorthand string, value int, usage string) *int {
|
||||
return CommandLine.IntP(name, shorthand, value, usage)
|
||||
}
|
||||
|
|
|
@ -48,7 +48,7 @@ func (f *FlagSet) Int32Var(p *int32, name string, value int32, usage string) {
|
|||
f.VarP(newInt32Value(value, p), name, "", usage)
|
||||
}
|
||||
|
||||
// Like Int32Var, but accepts a shorthand letter that can be used after a single dash.
|
||||
// Int32VarP is like Int32Var, but accepts a shorthand letter that can be used after a single dash.
|
||||
func (f *FlagSet) Int32VarP(p *int32, name, shorthand string, value int32, usage string) {
|
||||
f.VarP(newInt32Value(value, p), name, shorthand, usage)
|
||||
}
|
||||
|
@ -59,7 +59,7 @@ func Int32Var(p *int32, name string, value int32, usage string) {
|
|||
CommandLine.VarP(newInt32Value(value, p), name, "", usage)
|
||||
}
|
||||
|
||||
// Like Int32Var, but accepts a shorthand letter that can be used after a single dash.
|
||||
// Int32VarP is like Int32Var, but accepts a shorthand letter that can be used after a single dash.
|
||||
func Int32VarP(p *int32, name, shorthand string, value int32, usage string) {
|
||||
CommandLine.VarP(newInt32Value(value, p), name, shorthand, usage)
|
||||
}
|
||||
|
@ -72,7 +72,7 @@ func (f *FlagSet) Int32(name string, value int32, usage string) *int32 {
|
|||
return p
|
||||
}
|
||||
|
||||
// Like Int32, but accepts a shorthand letter that can be used after a single dash.
|
||||
// Int32P is like Int32, but accepts a shorthand letter that can be used after a single dash.
|
||||
func (f *FlagSet) Int32P(name, shorthand string, value int32, usage string) *int32 {
|
||||
p := new(int32)
|
||||
f.Int32VarP(p, name, shorthand, value, usage)
|
||||
|
@ -85,7 +85,7 @@ func Int32(name string, value int32, usage string) *int32 {
|
|||
return CommandLine.Int32P(name, "", value, usage)
|
||||
}
|
||||
|
||||
// Like Int32, but accepts a shorthand letter that can be used after a single dash.
|
||||
// Int32P is like Int32, but accepts a shorthand letter that can be used after a single dash.
|
||||
func Int32P(name, shorthand string, value int32, usage string) *int32 {
|
||||
return CommandLine.Int32P(name, shorthand, value, usage)
|
||||
}
|
||||
|
|
|
@ -44,7 +44,7 @@ func (f *FlagSet) Int64Var(p *int64, name string, value int64, usage string) {
|
|||
f.VarP(newInt64Value(value, p), name, "", usage)
|
||||
}
|
||||
|
||||
// Like Int64Var, but accepts a shorthand letter that can be used after a single dash.
|
||||
// Int64VarP is like Int64Var, but accepts a shorthand letter that can be used after a single dash.
|
||||
func (f *FlagSet) Int64VarP(p *int64, name, shorthand string, value int64, usage string) {
|
||||
f.VarP(newInt64Value(value, p), name, shorthand, usage)
|
||||
}
|
||||
|
@ -55,7 +55,7 @@ func Int64Var(p *int64, name string, value int64, usage string) {
|
|||
CommandLine.VarP(newInt64Value(value, p), name, "", usage)
|
||||
}
|
||||
|
||||
// Like Int64Var, but accepts a shorthand letter that can be used after a single dash.
|
||||
// Int64VarP is like Int64Var, but accepts a shorthand letter that can be used after a single dash.
|
||||
func Int64VarP(p *int64, name, shorthand string, value int64, usage string) {
|
||||
CommandLine.VarP(newInt64Value(value, p), name, shorthand, usage)
|
||||
}
|
||||
|
@ -68,7 +68,7 @@ func (f *FlagSet) Int64(name string, value int64, usage string) *int64 {
|
|||
return p
|
||||
}
|
||||
|
||||
// Like Int64, but accepts a shorthand letter that can be used after a single dash.
|
||||
// Int64P is like Int64, but accepts a shorthand letter that can be used after a single dash.
|
||||
func (f *FlagSet) Int64P(name, shorthand string, value int64, usage string) *int64 {
|
||||
p := new(int64)
|
||||
f.Int64VarP(p, name, shorthand, value, usage)
|
||||
|
@ -81,7 +81,7 @@ func Int64(name string, value int64, usage string) *int64 {
|
|||
return CommandLine.Int64P(name, "", value, usage)
|
||||
}
|
||||
|
||||
// Like Int64, but accepts a shorthand letter that can be used after a single dash.
|
||||
// Int64P is like Int64, but accepts a shorthand letter that can be used after a single dash.
|
||||
func Int64P(name, shorthand string, value int64, usage string) *int64 {
|
||||
return CommandLine.Int64P(name, shorthand, value, usage)
|
||||
}
|
||||
|
|
|
@ -48,7 +48,7 @@ func (f *FlagSet) Int8Var(p *int8, name string, value int8, usage string) {
|
|||
f.VarP(newInt8Value(value, p), name, "", usage)
|
||||
}
|
||||
|
||||
// Like Int8Var, but accepts a shorthand letter that can be used after a single dash.
|
||||
// Int8VarP is like Int8Var, but accepts a shorthand letter that can be used after a single dash.
|
||||
func (f *FlagSet) Int8VarP(p *int8, name, shorthand string, value int8, usage string) {
|
||||
f.VarP(newInt8Value(value, p), name, shorthand, usage)
|
||||
}
|
||||
|
@ -59,7 +59,7 @@ func Int8Var(p *int8, name string, value int8, usage string) {
|
|||
CommandLine.VarP(newInt8Value(value, p), name, "", usage)
|
||||
}
|
||||
|
||||
// Like Int8Var, but accepts a shorthand letter that can be used after a single dash.
|
||||
// Int8VarP is like Int8Var, but accepts a shorthand letter that can be used after a single dash.
|
||||
func Int8VarP(p *int8, name, shorthand string, value int8, usage string) {
|
||||
CommandLine.VarP(newInt8Value(value, p), name, shorthand, usage)
|
||||
}
|
||||
|
@ -72,7 +72,7 @@ func (f *FlagSet) Int8(name string, value int8, usage string) *int8 {
|
|||
return p
|
||||
}
|
||||
|
||||
// Like Int8, but accepts a shorthand letter that can be used after a single dash.
|
||||
// Int8P is like Int8, but accepts a shorthand letter that can be used after a single dash.
|
||||
func (f *FlagSet) Int8P(name, shorthand string, value int8, usage string) *int8 {
|
||||
p := new(int8)
|
||||
f.Int8VarP(p, name, shorthand, value, usage)
|
||||
|
@ -85,7 +85,7 @@ func Int8(name string, value int8, usage string) *int8 {
|
|||
return CommandLine.Int8P(name, "", value, usage)
|
||||
}
|
||||
|
||||
// Like Int8, but accepts a shorthand letter that can be used after a single dash.
|
||||
// Int8P is like Int8, but accepts a shorthand letter that can be used after a single dash.
|
||||
func Int8P(name, shorthand string, value int8, usage string) *int8 {
|
||||
return CommandLine.Int8P(name, shorthand, value, usage)
|
||||
}
|
||||
|
|
|
@ -85,7 +85,7 @@ func (f *FlagSet) IntSliceVar(p *[]int, name string, value []int, usage string)
|
|||
f.VarP(newIntSliceValue(value, p), name, "", usage)
|
||||
}
|
||||
|
||||
// Like IntSliceVar, but accepts a shorthand letter that can be used after a single dash.
|
||||
// IntSliceVarP is like IntSliceVar, but accepts a shorthand letter that can be used after a single dash.
|
||||
func (f *FlagSet) IntSliceVarP(p *[]int, name, shorthand string, value []int, usage string) {
|
||||
f.VarP(newIntSliceValue(value, p), name, shorthand, usage)
|
||||
}
|
||||
|
@ -96,7 +96,7 @@ func IntSliceVar(p *[]int, name string, value []int, usage string) {
|
|||
CommandLine.VarP(newIntSliceValue(value, p), name, "", usage)
|
||||
}
|
||||
|
||||
// Like IntSliceVar, but accepts a shorthand letter that can be used after a single dash.
|
||||
// IntSliceVarP is like IntSliceVar, but accepts a shorthand letter that can be used after a single dash.
|
||||
func IntSliceVarP(p *[]int, name, shorthand string, value []int, usage string) {
|
||||
CommandLine.VarP(newIntSliceValue(value, p), name, shorthand, usage)
|
||||
}
|
||||
|
@ -104,14 +104,14 @@ func IntSliceVarP(p *[]int, name, shorthand string, value []int, usage string) {
|
|||
// 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 (f *FlagSet) IntSlice(name string, value []int, usage string) *[]int {
|
||||
p := make([]int, 0)
|
||||
p := []int{}
|
||||
f.IntSliceVarP(&p, name, "", value, usage)
|
||||
return &p
|
||||
}
|
||||
|
||||
// Like IntSlice, but accepts a shorthand letter that can be used after a single dash.
|
||||
// IntSliceP is like IntSlice, but accepts a shorthand letter that can be used after a single dash.
|
||||
func (f *FlagSet) IntSliceP(name, shorthand string, value []int, usage string) *[]int {
|
||||
p := make([]int, 0)
|
||||
p := []int{}
|
||||
f.IntSliceVarP(&p, name, shorthand, value, usage)
|
||||
return &p
|
||||
}
|
||||
|
@ -122,7 +122,7 @@ func IntSlice(name string, value []int, usage string) *[]int {
|
|||
return CommandLine.IntSliceP(name, "", value, usage)
|
||||
}
|
||||
|
||||
// Like IntSlice, but accepts a shorthand letter that can be used after a single dash.
|
||||
// IntSliceP is like IntSlice, but accepts a shorthand letter that can be used after a single dash.
|
||||
func IntSliceP(name, shorthand string, value []int, usage string) *[]int {
|
||||
return CommandLine.IntSliceP(name, shorthand, value, usage)
|
||||
}
|
||||
|
|
|
@ -13,13 +13,13 @@ import (
|
|||
|
||||
func setUpISFlagSet(isp *[]int) *FlagSet {
|
||||
f := NewFlagSet("test", ContinueOnError)
|
||||
f.IntSliceVar(isp, "is", []int{}, "Command seperated list!")
|
||||
f.IntSliceVar(isp, "is", []int{}, "Command separated list!")
|
||||
return f
|
||||
}
|
||||
|
||||
func setUpISFlagSetWithDefault(isp *[]int) *FlagSet {
|
||||
f := NewFlagSet("test", ContinueOnError)
|
||||
f.IntSliceVar(isp, "is", []int{0, 1}, "Command seperated list!")
|
||||
f.IntSliceVar(isp, "is", []int{0, 1}, "Command separated list!")
|
||||
return f
|
||||
}
|
||||
|
||||
|
@ -87,7 +87,7 @@ func TestISDefault(t *testing.T) {
|
|||
t.Fatalf("got error: %v", err)
|
||||
}
|
||||
if d != v {
|
||||
t.Fatalf("expected is[%d] to be %s but got: %s", i, d, v)
|
||||
t.Fatalf("expected is[%d] to be %d but got: %d", i, d, v)
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -101,7 +101,7 @@ func TestISDefault(t *testing.T) {
|
|||
t.Fatal("got an error from GetIntSlice():", err)
|
||||
}
|
||||
if d != v {
|
||||
t.Fatalf("expected is[%d] to be %s from GetIntSlice but got: %s", i, d, v)
|
||||
t.Fatalf("expected is[%d] to be %d from GetIntSlice but got: %d", i, d, v)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -122,7 +122,7 @@ func TestISWithDefault(t *testing.T) {
|
|||
t.Fatalf("got error: %v", err)
|
||||
}
|
||||
if d != v {
|
||||
t.Fatalf("expected is[%d] to be %s but got: %s", i, d, v)
|
||||
t.Fatalf("expected is[%d] to be %d but got: %d", i, d, v)
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -136,7 +136,7 @@ func TestISWithDefault(t *testing.T) {
|
|||
t.Fatalf("got error: %v", err)
|
||||
}
|
||||
if d != v {
|
||||
t.Fatalf("expected is[%d] to be %s from GetIntSlice but got: %s", i, d, v)
|
||||
t.Fatalf("expected is[%d] to be %d from GetIntSlice but got: %d", i, d, v)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -156,7 +156,7 @@ func TestISCalledTwice(t *testing.T) {
|
|||
}
|
||||
for i, v := range is {
|
||||
if expected[i] != v {
|
||||
t.Fatalf("expected is[%d] to be %s but got: %s", i, expected[i], v)
|
||||
t.Fatalf("expected is[%d] to be %d but got: %d", i, expected[i], v)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -53,7 +53,7 @@ func (f *FlagSet) IPVar(p *net.IP, name string, value net.IP, usage string) {
|
|||
f.VarP(newIPValue(value, p), name, "", usage)
|
||||
}
|
||||
|
||||
// Like IPVar, but accepts a shorthand letter that can be used after a single dash.
|
||||
// IPVarP is like IPVar, but accepts a shorthand letter that can be used after a single dash.
|
||||
func (f *FlagSet) IPVarP(p *net.IP, name, shorthand string, value net.IP, usage string) {
|
||||
f.VarP(newIPValue(value, p), name, shorthand, usage)
|
||||
}
|
||||
|
@ -64,7 +64,7 @@ func IPVar(p *net.IP, name string, value net.IP, usage string) {
|
|||
CommandLine.VarP(newIPValue(value, p), name, "", usage)
|
||||
}
|
||||
|
||||
// Like IPVar, but accepts a shorthand letter that can be used after a single dash.
|
||||
// IPVarP is like IPVar, but accepts a shorthand letter that can be used after a single dash.
|
||||
func IPVarP(p *net.IP, name, shorthand string, value net.IP, usage string) {
|
||||
CommandLine.VarP(newIPValue(value, p), name, shorthand, usage)
|
||||
}
|
||||
|
@ -77,7 +77,7 @@ func (f *FlagSet) IP(name string, value net.IP, usage string) *net.IP {
|
|||
return p
|
||||
}
|
||||
|
||||
// Like IP, but accepts a shorthand letter that can be used after a single dash.
|
||||
// IPP is like IP, but accepts a shorthand letter that can be used after a single dash.
|
||||
func (f *FlagSet) IPP(name, shorthand string, value net.IP, usage string) *net.IP {
|
||||
p := new(net.IP)
|
||||
f.IPVarP(p, name, shorthand, value, usage)
|
||||
|
@ -90,7 +90,7 @@ func IP(name string, value net.IP, usage string) *net.IP {
|
|||
return CommandLine.IPP(name, "", value, usage)
|
||||
}
|
||||
|
||||
// Like IP, but accepts a shorthand letter that can be used after a single dash.
|
||||
// IPP is like IP, but accepts a shorthand letter that can be used after a single dash.
|
||||
func IPP(name, shorthand string, value net.IP, usage string) *net.IP {
|
||||
return CommandLine.IPP(name, shorthand, value, usage)
|
||||
}
|
||||
|
|
|
@ -28,7 +28,7 @@ func (i *ipMaskValue) Type() string {
|
|||
return "ipMask"
|
||||
}
|
||||
|
||||
// Parse IPv4 netmask written in IP form (e.g. 255.255.255.0).
|
||||
// ParseIPv4Mask written in IP form (e.g. 255.255.255.0).
|
||||
// This function should really belong to the net package.
|
||||
func ParseIPv4Mask(s string) net.IPMask {
|
||||
mask := net.ParseIP(s)
|
||||
|
@ -79,7 +79,7 @@ func (f *FlagSet) IPMaskVar(p *net.IPMask, name string, value net.IPMask, usage
|
|||
f.VarP(newIPMaskValue(value, p), name, "", usage)
|
||||
}
|
||||
|
||||
// Like IPMaskVar, but accepts a shorthand letter that can be used after a single dash.
|
||||
// IPMaskVarP is like IPMaskVar, but accepts a shorthand letter that can be used after a single dash.
|
||||
func (f *FlagSet) IPMaskVarP(p *net.IPMask, name, shorthand string, value net.IPMask, usage string) {
|
||||
f.VarP(newIPMaskValue(value, p), name, shorthand, usage)
|
||||
}
|
||||
|
@ -90,7 +90,7 @@ func IPMaskVar(p *net.IPMask, name string, value net.IPMask, usage string) {
|
|||
CommandLine.VarP(newIPMaskValue(value, p), name, "", usage)
|
||||
}
|
||||
|
||||
// Like IPMaskVar, but accepts a shorthand letter that can be used after a single dash.
|
||||
// IPMaskVarP is like IPMaskVar, but accepts a shorthand letter that can be used after a single dash.
|
||||
func IPMaskVarP(p *net.IPMask, name, shorthand string, value net.IPMask, usage string) {
|
||||
CommandLine.VarP(newIPMaskValue(value, p), name, shorthand, usage)
|
||||
}
|
||||
|
@ -103,7 +103,7 @@ func (f *FlagSet) IPMask(name string, value net.IPMask, usage string) *net.IPMas
|
|||
return p
|
||||
}
|
||||
|
||||
// Like IPMask, but accepts a shorthand letter that can be used after a single dash.
|
||||
// IPMaskP is like IPMask, but accepts a shorthand letter that can be used after a single dash.
|
||||
func (f *FlagSet) IPMaskP(name, shorthand string, value net.IPMask, usage string) *net.IPMask {
|
||||
p := new(net.IPMask)
|
||||
f.IPMaskVarP(p, name, shorthand, value, usage)
|
||||
|
@ -116,7 +116,7 @@ func IPMask(name string, value net.IPMask, usage string) *net.IPMask {
|
|||
return CommandLine.IPMaskP(name, "", value, usage)
|
||||
}
|
||||
|
||||
// Like IP, but accepts a shorthand letter that can be used after a single dash.
|
||||
// IPMaskP is like IP, but accepts a shorthand letter that can be used after a single dash.
|
||||
func IPMaskP(name, shorthand string, value net.IPMask, usage string) *net.IPMask {
|
||||
return CommandLine.IPMaskP(name, shorthand, value, usage)
|
||||
}
|
||||
|
|
|
@ -7,31 +7,31 @@ import (
|
|||
)
|
||||
|
||||
// IPNet adapts net.IPNet for use as a flag.
|
||||
type IPNetValue net.IPNet
|
||||
type ipNetValue net.IPNet
|
||||
|
||||
func (ipnet IPNetValue) String() string {
|
||||
func (ipnet ipNetValue) String() string {
|
||||
n := net.IPNet(ipnet)
|
||||
return n.String()
|
||||
}
|
||||
|
||||
func (ipnet *IPNetValue) Set(value string) error {
|
||||
func (ipnet *ipNetValue) Set(value string) error {
|
||||
_, n, err := net.ParseCIDR(strings.TrimSpace(value))
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
*ipnet = IPNetValue(*n)
|
||||
*ipnet = ipNetValue(*n)
|
||||
return nil
|
||||
}
|
||||
|
||||
func (*IPNetValue) Type() string {
|
||||
func (*ipNetValue) Type() string {
|
||||
return "ipNet"
|
||||
}
|
||||
|
||||
var _ = strings.TrimSpace
|
||||
|
||||
func newIPNetValue(val net.IPNet, p *net.IPNet) *IPNetValue {
|
||||
func newIPNetValue(val net.IPNet, p *net.IPNet) *ipNetValue {
|
||||
*p = val
|
||||
return (*IPNetValue)(p)
|
||||
return (*ipNetValue)(p)
|
||||
}
|
||||
|
||||
func ipNetConv(sval string) (interface{}, error) {
|
||||
|
@ -57,7 +57,7 @@ func (f *FlagSet) IPNetVar(p *net.IPNet, name string, value net.IPNet, usage str
|
|||
f.VarP(newIPNetValue(value, p), name, "", usage)
|
||||
}
|
||||
|
||||
// Like IPNetVar, but accepts a shorthand letter that can be used after a single dash.
|
||||
// IPNetVarP is like IPNetVar, but accepts a shorthand letter that can be used after a single dash.
|
||||
func (f *FlagSet) IPNetVarP(p *net.IPNet, name, shorthand string, value net.IPNet, usage string) {
|
||||
f.VarP(newIPNetValue(value, p), name, shorthand, usage)
|
||||
}
|
||||
|
@ -68,7 +68,7 @@ func IPNetVar(p *net.IPNet, name string, value net.IPNet, usage string) {
|
|||
CommandLine.VarP(newIPNetValue(value, p), name, "", usage)
|
||||
}
|
||||
|
||||
// Like IPNetVar, but accepts a shorthand letter that can be used after a single dash.
|
||||
// IPNetVarP is like IPNetVar, but accepts a shorthand letter that can be used after a single dash.
|
||||
func IPNetVarP(p *net.IPNet, name, shorthand string, value net.IPNet, usage string) {
|
||||
CommandLine.VarP(newIPNetValue(value, p), name, shorthand, usage)
|
||||
}
|
||||
|
@ -81,7 +81,7 @@ func (f *FlagSet) IPNet(name string, value net.IPNet, usage string) *net.IPNet {
|
|||
return p
|
||||
}
|
||||
|
||||
// Like IPNet, but accepts a shorthand letter that can be used after a single dash.
|
||||
// IPNetP is like IPNet, but accepts a shorthand letter that can be used after a single dash.
|
||||
func (f *FlagSet) IPNetP(name, shorthand string, value net.IPNet, usage string) *net.IPNet {
|
||||
p := new(net.IPNet)
|
||||
f.IPNetVarP(p, name, shorthand, value, usage)
|
||||
|
@ -94,7 +94,7 @@ func IPNet(name string, value net.IPNet, usage string) *net.IPNet {
|
|||
return CommandLine.IPNetP(name, "", value, usage)
|
||||
}
|
||||
|
||||
// Like IPNet, but accepts a shorthand letter that can be used after a single dash.
|
||||
// IPNetP is like IPNet, but accepts a shorthand letter that can be used after a single dash.
|
||||
func IPNetP(name, shorthand string, value net.IPNet, usage string) *net.IPNet {
|
||||
return CommandLine.IPNetP(name, shorthand, value, usage)
|
||||
}
|
||||
|
|
|
@ -39,7 +39,7 @@ func (f *FlagSet) StringVar(p *string, name string, value string, usage string)
|
|||
f.VarP(newStringValue(value, p), name, "", usage)
|
||||
}
|
||||
|
||||
// Like StringVar, but accepts a shorthand letter that can be used after a single dash.
|
||||
// StringVarP is like StringVar, but accepts a shorthand letter that can be used after a single dash.
|
||||
func (f *FlagSet) StringVarP(p *string, name, shorthand string, value string, usage string) {
|
||||
f.VarP(newStringValue(value, p), name, shorthand, usage)
|
||||
}
|
||||
|
@ -50,7 +50,7 @@ func StringVar(p *string, name string, value string, usage string) {
|
|||
CommandLine.VarP(newStringValue(value, p), name, "", usage)
|
||||
}
|
||||
|
||||
// Like StringVar, but accepts a shorthand letter that can be used after a single dash.
|
||||
// StringVarP is like StringVar, but accepts a shorthand letter that can be used after a single dash.
|
||||
func StringVarP(p *string, name, shorthand string, value string, usage string) {
|
||||
CommandLine.VarP(newStringValue(value, p), name, shorthand, usage)
|
||||
}
|
||||
|
@ -63,7 +63,7 @@ func (f *FlagSet) String(name string, value string, usage string) *string {
|
|||
return p
|
||||
}
|
||||
|
||||
// Like String, but accepts a shorthand letter that can be used after a single dash.
|
||||
// StringP is like String, but accepts a shorthand letter that can be used after a single dash.
|
||||
func (f *FlagSet) StringP(name, shorthand string, value string, usage string) *string {
|
||||
p := new(string)
|
||||
f.StringVarP(p, name, shorthand, value, usage)
|
||||
|
@ -76,7 +76,7 @@ func String(name string, value string, usage string) *string {
|
|||
return CommandLine.StringP(name, "", value, usage)
|
||||
}
|
||||
|
||||
// Like String, but accepts a shorthand letter that can be used after a single dash.
|
||||
// StringP is like String, but accepts a shorthand letter that can be used after a single dash.
|
||||
func StringP(name, shorthand string, value string, usage string) *string {
|
||||
return CommandLine.StringP(name, shorthand, value, usage)
|
||||
}
|
||||
|
|
|
@ -62,7 +62,7 @@ func (f *FlagSet) StringSliceVar(p *[]string, name string, value []string, usage
|
|||
f.VarP(newStringSliceValue(value, p), name, "", usage)
|
||||
}
|
||||
|
||||
// Like StringSliceVar, but accepts a shorthand letter that can be used after a single dash.
|
||||
// StringSliceVarP is like StringSliceVar, but accepts a shorthand letter that can be used after a single dash.
|
||||
func (f *FlagSet) StringSliceVarP(p *[]string, name, shorthand string, value []string, usage string) {
|
||||
f.VarP(newStringSliceValue(value, p), name, shorthand, usage)
|
||||
}
|
||||
|
@ -73,7 +73,7 @@ func StringSliceVar(p *[]string, name string, value []string, usage string) {
|
|||
CommandLine.VarP(newStringSliceValue(value, p), name, "", usage)
|
||||
}
|
||||
|
||||
// Like StringSliceVar, but accepts a shorthand letter that can be used after a single dash.
|
||||
// StringSliceVarP is like StringSliceVar, but accepts a shorthand letter that can be used after a single dash.
|
||||
func StringSliceVarP(p *[]string, name, shorthand string, value []string, usage string) {
|
||||
CommandLine.VarP(newStringSliceValue(value, p), name, shorthand, usage)
|
||||
}
|
||||
|
@ -81,14 +81,14 @@ func StringSliceVarP(p *[]string, name, shorthand string, value []string, usage
|
|||
// 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.
|
||||
func (f *FlagSet) StringSlice(name string, value []string, usage string) *[]string {
|
||||
p := make([]string, 0)
|
||||
p := []string{}
|
||||
f.StringSliceVarP(&p, name, "", value, usage)
|
||||
return &p
|
||||
}
|
||||
|
||||
// Like StringSlice, but accepts a shorthand letter that can be used after a single dash.
|
||||
// StringSliceP is like StringSlice, but accepts a shorthand letter that can be used after a single dash.
|
||||
func (f *FlagSet) StringSliceP(name, shorthand string, value []string, usage string) *[]string {
|
||||
p := make([]string, 0)
|
||||
p := []string{}
|
||||
f.StringSliceVarP(&p, name, shorthand, value, usage)
|
||||
return &p
|
||||
}
|
||||
|
@ -99,7 +99,7 @@ func StringSlice(name string, value []string, usage string) *[]string {
|
|||
return CommandLine.StringSliceP(name, "", value, usage)
|
||||
}
|
||||
|
||||
// Like StringSlice, but accepts a shorthand letter that can be used after a single dash.
|
||||
// StringSliceP is like StringSlice, but accepts a shorthand letter that can be used after a single dash.
|
||||
func StringSliceP(name, shorthand string, value []string, usage string) *[]string {
|
||||
return CommandLine.StringSliceP(name, shorthand, value, usage)
|
||||
}
|
||||
|
|
|
@ -12,13 +12,13 @@ import (
|
|||
|
||||
func setUpSSFlagSet(ssp *[]string) *FlagSet {
|
||||
f := NewFlagSet("test", ContinueOnError)
|
||||
f.StringSliceVar(ssp, "ss", []string{}, "Command seperated list!")
|
||||
f.StringSliceVar(ssp, "ss", []string{}, "Command separated list!")
|
||||
return f
|
||||
}
|
||||
|
||||
func setUpSSFlagSetWithDefault(ssp *[]string) *FlagSet {
|
||||
f := NewFlagSet("test", ContinueOnError)
|
||||
f.StringSliceVar(ssp, "ss", []string{"default", "values"}, "Command seperated list!")
|
||||
f.StringSliceVar(ssp, "ss", []string{"default", "values"}, "Command separated list!")
|
||||
return f
|
||||
}
|
||||
|
||||
|
|
|
@ -48,7 +48,7 @@ func (f *FlagSet) UintVar(p *uint, name string, value uint, usage string) {
|
|||
f.VarP(newUintValue(value, p), name, "", usage)
|
||||
}
|
||||
|
||||
// Like UintVar, but accepts a shorthand letter that can be used after a single dash.
|
||||
// UintVarP is like UintVar, but accepts a shorthand letter that can be used after a single dash.
|
||||
func (f *FlagSet) UintVarP(p *uint, name, shorthand string, value uint, usage string) {
|
||||
f.VarP(newUintValue(value, p), name, shorthand, usage)
|
||||
}
|
||||
|
@ -59,7 +59,7 @@ func UintVar(p *uint, name string, value uint, usage string) {
|
|||
CommandLine.VarP(newUintValue(value, p), name, "", usage)
|
||||
}
|
||||
|
||||
// Like UintVar, but accepts a shorthand letter that can be used after a single dash.
|
||||
// UintVarP is like UintVar, but accepts a shorthand letter that can be used after a single dash.
|
||||
func UintVarP(p *uint, name, shorthand string, value uint, usage string) {
|
||||
CommandLine.VarP(newUintValue(value, p), name, shorthand, usage)
|
||||
}
|
||||
|
@ -72,7 +72,7 @@ func (f *FlagSet) Uint(name string, value uint, usage string) *uint {
|
|||
return p
|
||||
}
|
||||
|
||||
// Like Uint, but accepts a shorthand letter that can be used after a single dash.
|
||||
// UintP is like Uint, but accepts a shorthand letter that can be used after a single dash.
|
||||
func (f *FlagSet) UintP(name, shorthand string, value uint, usage string) *uint {
|
||||
p := new(uint)
|
||||
f.UintVarP(p, name, shorthand, value, usage)
|
||||
|
@ -85,7 +85,7 @@ func Uint(name string, value uint, usage string) *uint {
|
|||
return CommandLine.UintP(name, "", value, usage)
|
||||
}
|
||||
|
||||
// Like Uint, but accepts a shorthand letter that can be used after a single dash.
|
||||
// UintP is like Uint, but accepts a shorthand letter that can be used after a single dash.
|
||||
func UintP(name, shorthand string, value uint, usage string) *uint {
|
||||
return CommandLine.UintP(name, shorthand, value, usage)
|
||||
}
|
||||
|
|
|
@ -46,7 +46,7 @@ func (f *FlagSet) Uint16Var(p *uint16, name string, value uint16, usage string)
|
|||
f.VarP(newUint16Value(value, p), name, "", usage)
|
||||
}
|
||||
|
||||
// Like Uint16Var, but accepts a shorthand letter that can be used after a single dash.
|
||||
// Uint16VarP is like Uint16Var, but accepts a shorthand letter that can be used after a single dash.
|
||||
func (f *FlagSet) Uint16VarP(p *uint16, name, shorthand string, value uint16, usage string) {
|
||||
f.VarP(newUint16Value(value, p), name, shorthand, usage)
|
||||
}
|
||||
|
@ -57,7 +57,7 @@ func Uint16Var(p *uint16, name string, value uint16, usage string) {
|
|||
CommandLine.VarP(newUint16Value(value, p), name, "", usage)
|
||||
}
|
||||
|
||||
// Like Uint16Var, but accepts a shorthand letter that can be used after a single dash.
|
||||
// Uint16VarP is like Uint16Var, but accepts a shorthand letter that can be used after a single dash.
|
||||
func Uint16VarP(p *uint16, name, shorthand string, value uint16, usage string) {
|
||||
CommandLine.VarP(newUint16Value(value, p), name, shorthand, usage)
|
||||
}
|
||||
|
@ -70,7 +70,7 @@ func (f *FlagSet) Uint16(name string, value uint16, usage string) *uint16 {
|
|||
return p
|
||||
}
|
||||
|
||||
// Like Uint16, but accepts a shorthand letter that can be used after a single dash.
|
||||
// Uint16P is like Uint16, but accepts a shorthand letter that can be used after a single dash.
|
||||
func (f *FlagSet) Uint16P(name, shorthand string, value uint16, usage string) *uint16 {
|
||||
p := new(uint16)
|
||||
f.Uint16VarP(p, name, shorthand, value, usage)
|
||||
|
@ -83,7 +83,7 @@ func Uint16(name string, value uint16, usage string) *uint16 {
|
|||
return CommandLine.Uint16P(name, "", value, usage)
|
||||
}
|
||||
|
||||
// Like Uint16, but accepts a shorthand letter that can be used after a single dash.
|
||||
// Uint16P is like Uint16, but accepts a shorthand letter that can be used after a single dash.
|
||||
func Uint16P(name, shorthand string, value uint16, usage string) *uint16 {
|
||||
return CommandLine.Uint16P(name, shorthand, value, usage)
|
||||
}
|
||||
|
|
|
@ -46,7 +46,7 @@ func (f *FlagSet) Uint32Var(p *uint32, name string, value uint32, usage string)
|
|||
f.VarP(newUint32Value(value, p), name, "", usage)
|
||||
}
|
||||
|
||||
// Like Uint32Var, but accepts a shorthand letter that can be used after a single dash.
|
||||
// Uint32VarP is like Uint32Var, but accepts a shorthand letter that can be used after a single dash.
|
||||
func (f *FlagSet) Uint32VarP(p *uint32, name, shorthand string, value uint32, usage string) {
|
||||
f.VarP(newUint32Value(value, p), name, shorthand, usage)
|
||||
}
|
||||
|
@ -57,7 +57,7 @@ func Uint32Var(p *uint32, name string, value uint32, usage string) {
|
|||
CommandLine.VarP(newUint32Value(value, p), name, "", usage)
|
||||
}
|
||||
|
||||
// Like Uint32Var, but accepts a shorthand letter that can be used after a single dash.
|
||||
// Uint32VarP is like Uint32Var, but accepts a shorthand letter that can be used after a single dash.
|
||||
func Uint32VarP(p *uint32, name, shorthand string, value uint32, usage string) {
|
||||
CommandLine.VarP(newUint32Value(value, p), name, shorthand, usage)
|
||||
}
|
||||
|
@ -70,7 +70,7 @@ func (f *FlagSet) Uint32(name string, value uint32, usage string) *uint32 {
|
|||
return p
|
||||
}
|
||||
|
||||
// Like Uint32, but accepts a shorthand letter that can be used after a single dash.
|
||||
// Uint32P is like Uint32, but accepts a shorthand letter that can be used after a single dash.
|
||||
func (f *FlagSet) Uint32P(name, shorthand string, value uint32, usage string) *uint32 {
|
||||
p := new(uint32)
|
||||
f.Uint32VarP(p, name, shorthand, value, usage)
|
||||
|
@ -83,7 +83,7 @@ func Uint32(name string, value uint32, usage string) *uint32 {
|
|||
return CommandLine.Uint32P(name, "", value, usage)
|
||||
}
|
||||
|
||||
// Like Uint32, but accepts a shorthand letter that can be used after a single dash.
|
||||
// Uint32P is like Uint32, but accepts a shorthand letter that can be used after a single dash.
|
||||
func Uint32P(name, shorthand string, value uint32, usage string) *uint32 {
|
||||
return CommandLine.Uint32P(name, shorthand, value, usage)
|
||||
}
|
||||
|
|
|
@ -48,7 +48,7 @@ func (f *FlagSet) Uint64Var(p *uint64, name string, value uint64, usage string)
|
|||
f.VarP(newUint64Value(value, p), name, "", usage)
|
||||
}
|
||||
|
||||
// Like Uint64Var, but accepts a shorthand letter that can be used after a single dash.
|
||||
// Uint64VarP is like Uint64Var, but accepts a shorthand letter that can be used after a single dash.
|
||||
func (f *FlagSet) Uint64VarP(p *uint64, name, shorthand string, value uint64, usage string) {
|
||||
f.VarP(newUint64Value(value, p), name, shorthand, usage)
|
||||
}
|
||||
|
@ -59,7 +59,7 @@ func Uint64Var(p *uint64, name string, value uint64, usage string) {
|
|||
CommandLine.VarP(newUint64Value(value, p), name, "", usage)
|
||||
}
|
||||
|
||||
// Like Uint64Var, but accepts a shorthand letter that can be used after a single dash.
|
||||
// Uint64VarP is like Uint64Var, but accepts a shorthand letter that can be used after a single dash.
|
||||
func Uint64VarP(p *uint64, name, shorthand string, value uint64, usage string) {
|
||||
CommandLine.VarP(newUint64Value(value, p), name, shorthand, usage)
|
||||
}
|
||||
|
@ -72,7 +72,7 @@ func (f *FlagSet) Uint64(name string, value uint64, usage string) *uint64 {
|
|||
return p
|
||||
}
|
||||
|
||||
// Like Uint64, but accepts a shorthand letter that can be used after a single dash.
|
||||
// Uint64P is like Uint64, but accepts a shorthand letter that can be used after a single dash.
|
||||
func (f *FlagSet) Uint64P(name, shorthand string, value uint64, usage string) *uint64 {
|
||||
p := new(uint64)
|
||||
f.Uint64VarP(p, name, shorthand, value, usage)
|
||||
|
@ -85,7 +85,7 @@ func Uint64(name string, value uint64, usage string) *uint64 {
|
|||
return CommandLine.Uint64P(name, "", value, usage)
|
||||
}
|
||||
|
||||
// Like Uint64, but accepts a shorthand letter that can be used after a single dash.
|
||||
// Uint64P is like Uint64, but accepts a shorthand letter that can be used after a single dash.
|
||||
func Uint64P(name, shorthand string, value uint64, usage string) *uint64 {
|
||||
return CommandLine.Uint64P(name, shorthand, value, usage)
|
||||
}
|
||||
|
|
|
@ -48,7 +48,7 @@ func (f *FlagSet) Uint8Var(p *uint8, name string, value uint8, usage string) {
|
|||
f.VarP(newUint8Value(value, p), name, "", usage)
|
||||
}
|
||||
|
||||
// Like Uint8Var, but accepts a shorthand letter that can be used after a single dash.
|
||||
// Uint8VarP is like Uint8Var, but accepts a shorthand letter that can be used after a single dash.
|
||||
func (f *FlagSet) Uint8VarP(p *uint8, name, shorthand string, value uint8, usage string) {
|
||||
f.VarP(newUint8Value(value, p), name, shorthand, usage)
|
||||
}
|
||||
|
@ -59,7 +59,7 @@ func Uint8Var(p *uint8, name string, value uint8, usage string) {
|
|||
CommandLine.VarP(newUint8Value(value, p), name, "", usage)
|
||||
}
|
||||
|
||||
// Like Uint8Var, but accepts a shorthand letter that can be used after a single dash.
|
||||
// Uint8VarP is like Uint8Var, but accepts a shorthand letter that can be used after a single dash.
|
||||
func Uint8VarP(p *uint8, name, shorthand string, value uint8, usage string) {
|
||||
CommandLine.VarP(newUint8Value(value, p), name, shorthand, usage)
|
||||
}
|
||||
|
@ -72,7 +72,7 @@ func (f *FlagSet) Uint8(name string, value uint8, usage string) *uint8 {
|
|||
return p
|
||||
}
|
||||
|
||||
// Like Uint8, but accepts a shorthand letter that can be used after a single dash.
|
||||
// Uint8P is like Uint8, but accepts a shorthand letter that can be used after a single dash.
|
||||
func (f *FlagSet) Uint8P(name, shorthand string, value uint8, usage string) *uint8 {
|
||||
p := new(uint8)
|
||||
f.Uint8VarP(p, name, shorthand, value, usage)
|
||||
|
@ -85,7 +85,7 @@ func Uint8(name string, value uint8, usage string) *uint8 {
|
|||
return CommandLine.Uint8P(name, "", value, usage)
|
||||
}
|
||||
|
||||
// Like Uint8, but accepts a shorthand letter that can be used after a single dash.
|
||||
// Uint8P is like Uint8, but accepts a shorthand letter that can be used after a single dash.
|
||||
func Uint8P(name, shorthand string, value uint8, usage string) *uint8 {
|
||||
return CommandLine.Uint8P(name, shorthand, value, usage)
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue