diff --git a/bool.go b/bool.go index c4c5c0bf..8026fac4 100644 --- a/bool.go +++ b/bool.go @@ -52,8 +52,14 @@ func (f *FlagSet) BoolVar(p *bool, name string, value bool, usage string) { // 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) { + f.BoolVarPF(p, name, shorthand, value, usage) +} + +// BoolVarPF is like BoolVarP, but returns the created flag. +func (f *FlagSet) BoolVarPF(p *bool, name, shorthand string, value bool, usage string) *Flag { flag := f.VarPF(newBoolValue(value, p), name, shorthand, usage) flag.NoOptDefVal = "true" + return flag } // BoolVar defines a bool flag with specified name, default value, and usage string. @@ -68,6 +74,13 @@ func BoolVarP(p *bool, name, shorthand string, value bool, usage string) { flag.NoOptDefVal = "true" } +// BoolVarPF is like BoolVarP, but returns the created flag. +func BoolVarPF(p *bool, name, shorthand string, value bool, usage string) *Flag { + flag := CommandLine.VarPF(newBoolValue(value, p), name, shorthand, usage) + flag.NoOptDefVal = "true" + return flag +} + // 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 (f *FlagSet) Bool(name string, value bool, usage string) *bool { diff --git a/bool_slice.go b/bool_slice.go index 3731370d..f1618109 100644 --- a/bool_slice.go +++ b/bool_slice.go @@ -147,6 +147,11 @@ func (f *FlagSet) BoolSliceVarP(p *[]bool, name, shorthand string, value []bool, f.VarP(newBoolSliceValue(value, p), name, shorthand, usage) } +// BoolSliceVarPF is like BoolSliceVarP, but returns the created flag. +func (f *FlagSet) BoolSliceVarPF(p *[]bool, name, shorthand string, value []bool, usage string) *Flag { + return f.VarPF(newBoolSliceValue(value, p), name, shorthand, usage) +} + // 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 BoolSliceVar(p *[]bool, name string, value []bool, usage string) { @@ -158,6 +163,11 @@ func BoolSliceVarP(p *[]bool, name, shorthand string, value []bool, usage string CommandLine.VarP(newBoolSliceValue(value, p), name, shorthand, usage) } +// BoolSliceVarPF is like BoolSliceVarP, but returns the created flag. +func BoolSliceVarPF(p *[]bool, name, shorthand string, value []bool, usage string) *Flag { + return CommandLine.VarPF(newBoolSliceValue(value, p), name, shorthand, usage) +} + // 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 (f *FlagSet) BoolSlice(name string, value []bool, usage string) *[]bool { diff --git a/bytes.go b/bytes.go index 67d53045..f5a46ad5 100644 --- a/bytes.go +++ b/bytes.go @@ -71,6 +71,11 @@ func (f *FlagSet) BytesHexVarP(p *[]byte, name, shorthand string, value []byte, f.VarP(newBytesHexValue(value, p), name, shorthand, usage) } +// BytesHexVarPF is like BytesHexVarP, but returns the created flag. +func (f *FlagSet) BytesHexVarPF(p *[]byte, name, shorthand string, value []byte, usage string) *Flag { + return f.VarPF(newBytesHexValue(value, p), name, shorthand, usage) +} + // 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 BytesHexVar(p *[]byte, name string, value []byte, usage string) { @@ -82,6 +87,11 @@ func BytesHexVarP(p *[]byte, name, shorthand string, value []byte, usage string) CommandLine.VarP(newBytesHexValue(value, p), name, shorthand, usage) } +// BytesHexVarPF is like BytesHexVarP, but returns the created flag. +func BytesHexVarPF(p *[]byte, name, shorthand string, value []byte, usage string) *Flag { + return CommandLine.VarPF(newBytesHexValue(value, p), name, shorthand, usage) +} + // 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 (f *FlagSet) BytesHex(name string, value []byte, usage string) *[]byte { @@ -171,6 +181,11 @@ func (f *FlagSet) BytesBase64VarP(p *[]byte, name, shorthand string, value []byt f.VarP(newBytesBase64Value(value, p), name, shorthand, usage) } +// BytesBase64VarPF is like BytesBase64VarP, but returns the created flag. +func (f *FlagSet) BytesBase64VarPF(p *[]byte, name, shorthand string, value []byte, usage string) *Flag { + return f.VarPF(newBytesBase64Value(value, p), name, shorthand, usage) +} + // 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 BytesBase64Var(p *[]byte, name string, value []byte, usage string) { @@ -182,6 +197,11 @@ func BytesBase64VarP(p *[]byte, name, shorthand string, value []byte, usage stri CommandLine.VarP(newBytesBase64Value(value, p), name, shorthand, usage) } +// BytesBase64VarPF is like BytesBase64VarP, but returns the created flag. +func BytesBase64VarPF(p *[]byte, name, shorthand string, value []byte, usage string) *Flag { + return CommandLine.VarPF(newBytesBase64Value(value, p), name, shorthand, usage) +} + // 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 (f *FlagSet) BytesBase64(name string, value []byte, usage string) *[]byte { diff --git a/count.go b/count.go index a0b2679f..bba21d68 100644 --- a/count.go +++ b/count.go @@ -53,8 +53,14 @@ func (f *FlagSet) CountVar(p *int, name string, usage string) { // CountVarP is like CountVar only take a shorthand for the flag name. func (f *FlagSet) CountVarP(p *int, name, shorthand string, usage string) { + f.CountVarPF(p, name, shorthand, usage) +} + +// CountVarPF is like CountVarP, but returns the created flag. +func (f *FlagSet) CountVarPF(p *int, name, shorthand string, usage string) *Flag { flag := f.VarPF(newCountValue(0, p), name, shorthand, usage) flag.NoOptDefVal = "+1" + return flag } // CountVar like CountVar only the flag is placed on the CommandLine instead of a given flag set @@ -67,6 +73,11 @@ func CountVarP(p *int, name, shorthand string, usage string) { CommandLine.CountVarP(p, name, shorthand, usage) } +// CountVarPF is like CountVarP, but returns the created flag. +func CountVarPF(p *int, name, shorthand string, usage string) *Flag { + return CommandLine.CountVarPF(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 every time it is found on the command line diff --git a/duration.go b/duration.go index e9debef8..84dafad1 100644 --- a/duration.go +++ b/duration.go @@ -48,6 +48,11 @@ func (f *FlagSet) DurationVarP(p *time.Duration, name, shorthand string, value t f.VarP(newDurationValue(value, p), name, shorthand, usage) } +// DurationVarPF is like DurationVarP, but returns the created flag. +func (f *FlagSet) DurationVarPF(p *time.Duration, name, shorthand string, value time.Duration, usage string) *Flag { + return f.VarPF(newDurationValue(value, p), name, shorthand, usage) +} + // 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 DurationVar(p *time.Duration, name string, value time.Duration, usage string) { @@ -59,6 +64,11 @@ func DurationVarP(p *time.Duration, name, shorthand string, value time.Duration, CommandLine.VarP(newDurationValue(value, p), name, shorthand, usage) } +// DurationVarPF is like DurationVarP, but returns the created flag. +func DurationVarPF(p *time.Duration, name, shorthand string, value time.Duration, usage string) *Flag { + return CommandLine.VarPF(newDurationValue(value, p), name, shorthand, usage) +} + // 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 (f *FlagSet) Duration(name string, value time.Duration, usage string) *time.Duration { diff --git a/duration_slice.go b/duration_slice.go index badadda5..574207d0 100644 --- a/duration_slice.go +++ b/duration_slice.go @@ -128,6 +128,11 @@ func (f *FlagSet) DurationSliceVarP(p *[]time.Duration, name, shorthand string, f.VarP(newDurationSliceValue(value, p), name, shorthand, usage) } +// DurationSliceVarPF is like DurationSliceVarP, but returns the created flag. +func (f *FlagSet) DurationSliceVarPF(p *[]time.Duration, name, shorthand string, value []time.Duration, usage string) *Flag { + return f.VarPF(newDurationSliceValue(value, p), name, shorthand, usage) +} + // 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 DurationSliceVar(p *[]time.Duration, name string, value []time.Duration, usage string) { @@ -139,6 +144,11 @@ func DurationSliceVarP(p *[]time.Duration, name, shorthand string, value []time. CommandLine.VarP(newDurationSliceValue(value, p), name, shorthand, usage) } +// DurationSliceVarPF is like DurationSliceVarP, but returns the created flag. +func DurationSliceVarPF(p *[]time.Duration, name, shorthand string, value []time.Duration, usage string) *Flag { + return CommandLine.VarPF(newDurationSliceValue(value, p), name, shorthand, usage) +} + // 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 (f *FlagSet) DurationSlice(name string, value []time.Duration, usage string) *[]time.Duration { diff --git a/flag.go b/flag.go index 7c058de3..1ef978e1 100644 --- a/flag.go +++ b/flag.go @@ -27,23 +27,32 @@ unaffected. Define flags using flag.String(), Bool(), Int(), etc. This declares an integer flag, -flagname, stored in the pointer ip, with type *int. + var ip = flag.Int("flagname", 1234, "help message for flagname") + If you like, you can bind the flag to a variable using the Var() functions. + var flagvar int func init() { flag.IntVar(&flagvar, "flagname", 1234, "help message for flagname") } + Or you can create custom flags that satisfy the Value interface (with pointer receivers) and couple them to flag parsing by + flag.Var(&flagVal, "name", "help message for flagname") + For such flags, the default value is just the initial value of the variable. After all flags are defined, call + flag.Parse() + to parse the command line into the defined flags. Flags may then be used directly. If you're using the flags themselves, they are all pointers; if you bind to variables, they're values. + fmt.Println("ip has value ", *ip) fmt.Println("flagvar has value ", flagvar) @@ -54,22 +63,26 @@ The arguments are indexed from 0 through flag.NArg()-1. The pflag package also defines some new functions that are not in flag, that give one-letter shorthands for flags. You can use these by appending 'P' to the name of any function that defines a flag. + var ip = flag.IntP("flagname", "f", 1234, "help message") var flagvar bool func init() { flag.BoolVarP(&flagvar, "boolname", "b", true, "help message") } flag.VarP(&flagval, "varname", "v", "help message") + Shorthand letters can be used with single dashes on the command line. Boolean shorthand flags can be combined with other shorthand flags. Command line flag syntax: + --flag // boolean flags only --flag=x Unlike the flag package, a single dash before an option means something different than a double dash. Single dashes signify a series of shorthand letters for flags. All but the last shorthand letter must be boolean flags. + // boolean flags -f -abc @@ -556,6 +569,8 @@ func (f *Flag) defaultIsZeroValue() bool { return true case "": return true + case "[]": + return true case "": return true case "0": @@ -934,9 +949,9 @@ func (f *FlagSet) usage() { } } -//--unknown (args will be empty) -//--unknown --next-flag ... (args will be --next-flag ...) -//--unknown arg ... (args will be arg ...) +// --unknown (args will be empty) +// --unknown --next-flag ... (args will be --next-flag ...) +// --unknown arg ... (args will be arg ...) func stripUnknownFlagValue(args []string) []string { if len(args) == 0 { //--unknown diff --git a/float32.go b/float32.go index a243f81f..bb9789cb 100644 --- a/float32.go +++ b/float32.go @@ -50,6 +50,11 @@ func (f *FlagSet) Float32VarP(p *float32, name, shorthand string, value float32, f.VarP(newFloat32Value(value, p), name, shorthand, usage) } +// Float32VarPF is like Float32VarP, but returns the created flag. +func (f *FlagSet) Float32VarPF(p *float32, name, shorthand string, value float32, usage string) *Flag { + return f.VarPF(newFloat32Value(value, p), name, shorthand, usage) +} + // 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 Float32Var(p *float32, name string, value float32, usage string) { @@ -61,6 +66,11 @@ func Float32VarP(p *float32, name, shorthand string, value float32, usage string CommandLine.VarP(newFloat32Value(value, p), name, shorthand, usage) } +// Float32VarPF is like Float32VarP, but returns the created flag. +func Float32VarPF(p *float32, name, shorthand string, value float32, usage string) *Flag { + return CommandLine.VarPF(newFloat32Value(value, p), name, shorthand, usage) +} + // 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 (f *FlagSet) Float32(name string, value float32, usage string) *float32 { diff --git a/float32_slice.go b/float32_slice.go index caa35274..374fa0e2 100644 --- a/float32_slice.go +++ b/float32_slice.go @@ -136,6 +136,11 @@ func (f *FlagSet) Float32SliceVarP(p *[]float32, name, shorthand string, value [ f.VarP(newFloat32SliceValue(value, p), name, shorthand, usage) } +// Float32SliceVarPF is like Float32SliceVarP, but returns the created flag. +func (f *FlagSet) Float32SliceVarPF(p *[]float32, name, shorthand string, value []float32, usage string) *Flag { + return f.VarPF(newFloat32SliceValue(value, p), name, shorthand, usage) +} + // 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 Float32SliceVar(p *[]float32, name string, value []float32, usage string) { @@ -147,6 +152,11 @@ func Float32SliceVarP(p *[]float32, name, shorthand string, value []float32, usa CommandLine.VarP(newFloat32SliceValue(value, p), name, shorthand, usage) } +// Float32SliceVarPF is like Float32SliceVarP, but returns the created flag. +func Float32SliceVarPF(p *[]float32, name, shorthand string, value []float32, usage string) *Flag { + return CommandLine.VarPF(newFloat32SliceValue(value, p), name, shorthand, usage) +} + // 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 (f *FlagSet) Float32Slice(name string, value []float32, usage string) *[]float32 { diff --git a/float64.go b/float64.go index 04b5492a..1f9126fa 100644 --- a/float64.go +++ b/float64.go @@ -46,6 +46,11 @@ func (f *FlagSet) Float64VarP(p *float64, name, shorthand string, value float64, f.VarP(newFloat64Value(value, p), name, shorthand, usage) } +// Float64VarPF is like Float64VarP, but returns the created flag. +func (f *FlagSet) Float64VarPF(p *float64, name, shorthand string, value float64, usage string) *Flag { + return f.VarPF(newFloat64Value(value, p), name, shorthand, usage) +} + // 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 Float64Var(p *float64, name string, value float64, usage string) { @@ -57,6 +62,11 @@ func Float64VarP(p *float64, name, shorthand string, value float64, usage string CommandLine.VarP(newFloat64Value(value, p), name, shorthand, usage) } +// Float64VarPF is like Float64VarP, bbut returns the created flag. +func Float64VarPF(p *float64, name, shorthand string, value float64, usage string) *Flag { + return CommandLine.VarPF(newFloat64Value(value, p), name, shorthand, usage) +} + // 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 (f *FlagSet) Float64(name string, value float64, usage string) *float64 { diff --git a/float64_slice.go b/float64_slice.go index 85bf3073..7db9896c 100644 --- a/float64_slice.go +++ b/float64_slice.go @@ -128,6 +128,11 @@ func (f *FlagSet) Float64SliceVarP(p *[]float64, name, shorthand string, value [ f.VarP(newFloat64SliceValue(value, p), name, shorthand, usage) } +// Float64SliceVarPF is like Float64SliceVarP, but returns the created flag. +func (f *FlagSet) Float64SliceVarPF(p *[]float64, name, shorthand string, value []float64, usage string) *Flag { + return f.VarPF(newFloat64SliceValue(value, p), name, shorthand, usage) +} + // 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 Float64SliceVar(p *[]float64, name string, value []float64, usage string) { @@ -139,6 +144,11 @@ func Float64SliceVarP(p *[]float64, name, shorthand string, value []float64, usa CommandLine.VarP(newFloat64SliceValue(value, p), name, shorthand, usage) } +// Float64SliceVarPF is like Float64SliceVarP, but returns the created flag. +func Float64SliceVarPF(p *[]float64, name, shorthand string, value []float64, usage string) *Flag { + return CommandLine.VarPF(newFloat64SliceValue(value, p), name, shorthand, usage) +} + // 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 (f *FlagSet) Float64Slice(name string, value []float64, usage string) *[]float64 { diff --git a/int.go b/int.go index 1474b89d..b4b4967d 100644 --- a/int.go +++ b/int.go @@ -46,6 +46,11 @@ func (f *FlagSet) IntVarP(p *int, name, shorthand string, value int, usage strin f.VarP(newIntValue(value, p), name, shorthand, usage) } +// IntVarPF is like IntVarP, but returns the created flag. +func (f *FlagSet) IntVarPF(p *int, name, shorthand string, value int, usage string) *Flag { + return f.VarPF(newIntValue(value, p), name, shorthand, usage) +} + // 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 IntVar(p *int, name string, value int, usage string) { @@ -57,6 +62,11 @@ func IntVarP(p *int, name, shorthand string, value int, usage string) { CommandLine.VarP(newIntValue(value, p), name, shorthand, usage) } +// IntVarPF is like IntVarP, but returns the created flag. +func IntVarPF(p *int, name, shorthand string, value int, usage string) *Flag { + return CommandLine.VarPF(newIntValue(value, p), name, shorthand, usage) +} + // 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 (f *FlagSet) Int(name string, value int, usage string) *int { diff --git a/int16.go b/int16.go index f1a01d05..7aeb602f 100644 --- a/int16.go +++ b/int16.go @@ -50,6 +50,11 @@ func (f *FlagSet) Int16VarP(p *int16, name, shorthand string, value int16, usage f.VarP(newInt16Value(value, p), name, shorthand, usage) } +// Int16VarPF is like Int16VarP, but returns the created flag. +func (f *FlagSet) Int16VarPF(p *int16, name, shorthand string, value int16, usage string) *Flag { + return f.VarPF(newInt16Value(value, p), name, shorthand, usage) +} + // 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 Int16Var(p *int16, name string, value int16, usage string) { @@ -61,6 +66,11 @@ func Int16VarP(p *int16, name, shorthand string, value int16, usage string) { CommandLine.VarP(newInt16Value(value, p), name, shorthand, usage) } +// Int16VarPF is like Int16VarP, but returns the created flag. +func Int16VarPF(p *int16, name, shorthand string, value int16, usage string) *Flag { + return CommandLine.VarPF(newInt16Value(value, p), name, shorthand, usage) +} + // 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 (f *FlagSet) Int16(name string, value int16, usage string) *int16 { diff --git a/int32.go b/int32.go index 9b95944f..f250d626 100644 --- a/int32.go +++ b/int32.go @@ -50,6 +50,11 @@ func (f *FlagSet) Int32VarP(p *int32, name, shorthand string, value int32, usage f.VarP(newInt32Value(value, p), name, shorthand, usage) } +// Int32VarPF is like Int32VarP, but returns the created flag. +func (f *FlagSet) Int32VarPF(p *int32, name, shorthand string, value int32, usage string) *Flag { + return f.VarPF(newInt32Value(value, p), name, shorthand, usage) +} + // 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 Int32Var(p *int32, name string, value int32, usage string) { @@ -61,6 +66,11 @@ func Int32VarP(p *int32, name, shorthand string, value int32, usage string) { CommandLine.VarP(newInt32Value(value, p), name, shorthand, usage) } +// Int32VarPF is like Int32VarP, but returns the created flag. +func Int32VarPF(p *int32, name, shorthand string, value int32, usage string) *Flag { + return CommandLine.VarPF(newInt32Value(value, p), name, shorthand, usage) +} + // 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 (f *FlagSet) Int32(name string, value int32, usage string) *int32 { diff --git a/int32_slice.go b/int32_slice.go index ff128ff0..2a2c6e8f 100644 --- a/int32_slice.go +++ b/int32_slice.go @@ -136,6 +136,11 @@ func (f *FlagSet) Int32SliceVarP(p *[]int32, name, shorthand string, value []int f.VarP(newInt32SliceValue(value, p), name, shorthand, usage) } +// Int32SliceVarPF is like Int32SliceVarP, but returns the created flag. +func (f *FlagSet) Int32SliceVarPF(p *[]int32, name, shorthand string, value []int32, usage string) *Flag { + return f.VarPF(newInt32SliceValue(value, p), name, shorthand, usage) +} + // 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 Int32SliceVar(p *[]int32, name string, value []int32, usage string) { @@ -147,6 +152,11 @@ func Int32SliceVarP(p *[]int32, name, shorthand string, value []int32, usage str CommandLine.VarP(newInt32SliceValue(value, p), name, shorthand, usage) } +// Int32SliceVarPF is like Int32SliceVarP, but returns the created flag. +func Int32SliceVarPF(p *[]int32, name, shorthand string, value []int32, usage string) *Flag { + return CommandLine.VarPF(newInt32SliceValue(value, p), name, shorthand, usage) +} + // 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 (f *FlagSet) Int32Slice(name string, value []int32, usage string) *[]int32 { diff --git a/int64.go b/int64.go index 0026d781..b7c57276 100644 --- a/int64.go +++ b/int64.go @@ -46,6 +46,11 @@ func (f *FlagSet) Int64VarP(p *int64, name, shorthand string, value int64, usage f.VarP(newInt64Value(value, p), name, shorthand, usage) } +// Int64VarPF is like Int64VarP, but returns the created flag. +func (f *FlagSet) Int64VarPF(p *int64, name, shorthand string, value int64, usage string) *Flag { + return f.VarPF(newInt64Value(value, p), name, shorthand, usage) +} + // 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 Int64Var(p *int64, name string, value int64, usage string) { @@ -57,6 +62,11 @@ func Int64VarP(p *int64, name, shorthand string, value int64, usage string) { CommandLine.VarP(newInt64Value(value, p), name, shorthand, usage) } +// Int64VarPF is like Int64VarP, but returns the created flag. +func Int64VarPF(p *int64, name, shorthand string, value int64, usage string) *Flag { + return CommandLine.VarPF(newInt64Value(value, p), name, shorthand, usage) +} + // 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 (f *FlagSet) Int64(name string, value int64, usage string) *int64 { diff --git a/int64_slice.go b/int64_slice.go index 25464638..dca27123 100644 --- a/int64_slice.go +++ b/int64_slice.go @@ -128,6 +128,11 @@ func (f *FlagSet) Int64SliceVarP(p *[]int64, name, shorthand string, value []int f.VarP(newInt64SliceValue(value, p), name, shorthand, usage) } +// Int64SliceVarPF is like Int64SliceVarP, but returns the created flag. +func (f *FlagSet) Int64SliceVarPF(p *[]int64, name, shorthand string, value []int64, usage string) *Flag { + return f.VarPF(newInt64SliceValue(value, p), name, shorthand, usage) +} + // 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 Int64SliceVar(p *[]int64, name string, value []int64, usage string) { @@ -139,6 +144,11 @@ func Int64SliceVarP(p *[]int64, name, shorthand string, value []int64, usage str CommandLine.VarP(newInt64SliceValue(value, p), name, shorthand, usage) } +// Int64SliceVarPF is like Int64SliceVarP, but returns the created flag. +func Int64SliceVarPF(p *[]int64, name, shorthand string, value []int64, usage string) *Flag { + return CommandLine.VarPF(newInt64SliceValue(value, p), name, shorthand, usage) +} + // 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 (f *FlagSet) Int64Slice(name string, value []int64, usage string) *[]int64 { diff --git a/int8.go b/int8.go index 4da92228..93d05b9c 100644 --- a/int8.go +++ b/int8.go @@ -50,6 +50,11 @@ func (f *FlagSet) Int8VarP(p *int8, name, shorthand string, value int8, usage st f.VarP(newInt8Value(value, p), name, shorthand, usage) } +// Int8VarPF is like Int8VarP, but returns the created flag. +func (f *FlagSet) Int8VarPF(p *int8, name, shorthand string, value int8, usage string) *Flag { + return f.VarPF(newInt8Value(value, p), name, shorthand, usage) +} + // 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 Int8Var(p *int8, name string, value int8, usage string) { @@ -61,6 +66,11 @@ func Int8VarP(p *int8, name, shorthand string, value int8, usage string) { CommandLine.VarP(newInt8Value(value, p), name, shorthand, usage) } +// Int8VarPF is like Int8VarP, but returns the created flag. +func Int8VarPF(p *int8, name, shorthand string, value int8, usage string) *Flag { + return CommandLine.VarPF(newInt8Value(value, p), name, shorthand, usage) +} + // 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 (f *FlagSet) Int8(name string, value int8, usage string) *int8 { diff --git a/int_slice.go b/int_slice.go index e71c39d9..979432b3 100644 --- a/int_slice.go +++ b/int_slice.go @@ -120,6 +120,11 @@ func (f *FlagSet) IntSliceVarP(p *[]int, name, shorthand string, value []int, us f.VarP(newIntSliceValue(value, p), name, shorthand, usage) } +// IntSliceVarPF is like IntSliceVarP, but returns the created flag. +func (f *FlagSet) IntSliceVarPF(p *[]int, name, shorthand string, value []int, usage string) *Flag { + return f.VarPF(newIntSliceValue(value, p), name, shorthand, usage) +} + // 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 IntSliceVar(p *[]int, name string, value []int, usage string) { @@ -131,6 +136,11 @@ func IntSliceVarP(p *[]int, name, shorthand string, value []int, usage string) { CommandLine.VarP(newIntSliceValue(value, p), name, shorthand, usage) } +// IntSliceVarPF is like IntSliceVarP, but returns the created flag. +func IntSliceVarPF(p *[]int, name, shorthand string, value []int, usage string) *Flag { + return CommandLine.VarPF(newIntSliceValue(value, p), name, shorthand, usage) +} + // 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 { diff --git a/ip.go b/ip.go index 06b8bcb5..d2dd51af 100644 --- a/ip.go +++ b/ip.go @@ -59,6 +59,11 @@ func (f *FlagSet) IPVarP(p *net.IP, name, shorthand string, value net.IP, usage f.VarP(newIPValue(value, p), name, shorthand, usage) } +// IPVarPF is like IPVarP, but returns the created flag. +func (f *FlagSet) IPVarPF(p *net.IP, name, shorthand string, value net.IP, usage string) *Flag { + return f.VarPF(newIPValue(value, p), name, shorthand, usage) +} + // 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 IPVar(p *net.IP, name string, value net.IP, usage string) { @@ -70,6 +75,11 @@ func IPVarP(p *net.IP, name, shorthand string, value net.IP, usage string) { CommandLine.VarP(newIPValue(value, p), name, shorthand, usage) } +// IPVarPF is like IPVarP, but returns the created flag. +func IPVarPF(p *net.IP, name, shorthand string, value net.IP, usage string) *Flag { + return CommandLine.VarPF(newIPValue(value, p), name, shorthand, usage) +} + // 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 (f *FlagSet) IP(name string, value net.IP, usage string) *net.IP { diff --git a/ip_slice.go b/ip_slice.go index 775faae4..dfe516b6 100644 --- a/ip_slice.go +++ b/ip_slice.go @@ -148,6 +148,11 @@ func (f *FlagSet) IPSliceVarP(p *[]net.IP, name, shorthand string, value []net.I f.VarP(newIPSliceValue(value, p), name, shorthand, usage) } +// IPSliceVarPF is like IPSliceVarP, but returns the created flag. +func (f *FlagSet) IPSliceVarPF(p *[]net.IP, name, shorthand string, value []net.IP, usage string) *Flag { + return f.VarPF(newIPSliceValue(value, p), name, shorthand, usage) +} + // 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 IPSliceVar(p *[]net.IP, name string, value []net.IP, usage string) { @@ -159,6 +164,11 @@ func IPSliceVarP(p *[]net.IP, name, shorthand string, value []net.IP, usage stri CommandLine.VarP(newIPSliceValue(value, p), name, shorthand, usage) } +// IPSliceVarPF is like IPSliceVarP, but returns the created flag. +func IPSliceVarPF(p *[]net.IP, name, shorthand string, value []net.IP, usage string) *Flag { + return CommandLine.VarPF(newIPSliceValue(value, p), name, shorthand, usage) +} + // IPSlice defines a []net.IP flag with specified name, default value, and usage string. // The return value is the address of a []net.IP variable that stores the value of that flag. func (f *FlagSet) IPSlice(name string, value []net.IP, usage string) *[]net.IP { diff --git a/ipmask.go b/ipmask.go index 5bd44bd2..947fe65f 100644 --- a/ipmask.go +++ b/ipmask.go @@ -84,6 +84,11 @@ func (f *FlagSet) IPMaskVarP(p *net.IPMask, name, shorthand string, value net.IP f.VarP(newIPMaskValue(value, p), name, shorthand, usage) } +// IPMaskVarPF is like IPMaskVarP, but returns the created flag. +func (f *FlagSet) IPMaskVarPF(p *net.IPMask, name, shorthand string, value net.IPMask, usage string) *Flag { + return f.VarPF(newIPMaskValue(value, p), name, shorthand, usage) +} + // 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 IPMaskVar(p *net.IPMask, name string, value net.IPMask, usage string) { @@ -95,6 +100,11 @@ func IPMaskVarP(p *net.IPMask, name, shorthand string, value net.IPMask, usage s CommandLine.VarP(newIPMaskValue(value, p), name, shorthand, usage) } +// IPMaskVarPF is like IPMaskVarP, but returns the created flag. +func IPMaskVarPF(p *net.IPMask, name, shorthand string, value net.IPMask, usage string) *Flag { + return CommandLine.VarPF(newIPMaskValue(value, p), name, shorthand, usage) +} + // 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 (f *FlagSet) IPMask(name string, value net.IPMask, usage string) *net.IPMask { diff --git a/ipnet.go b/ipnet.go index e2c1b8bc..39b3a146 100644 --- a/ipnet.go +++ b/ipnet.go @@ -60,6 +60,11 @@ func (f *FlagSet) IPNetVarP(p *net.IPNet, name, shorthand string, value net.IPNe f.VarP(newIPNetValue(value, p), name, shorthand, usage) } +// IPNetVarPF is like IPNetVarP, but returns the created flag. +func (f *FlagSet) IPNetVarPF(p *net.IPNet, name, shorthand string, value net.IPNet, usage string) *Flag { + return f.VarPF(newIPNetValue(value, p), name, shorthand, usage) +} + // 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 IPNetVar(p *net.IPNet, name string, value net.IPNet, usage string) { @@ -71,6 +76,11 @@ func IPNetVarP(p *net.IPNet, name, shorthand string, value net.IPNet, usage stri CommandLine.VarP(newIPNetValue(value, p), name, shorthand, usage) } +// IPNetVarPF is like IPNetVarP, but returns the created flag. +func IPNetVarPF(p *net.IPNet, name, shorthand string, value net.IPNet, usage string) *Flag { + return CommandLine.VarPF(newIPNetValue(value, p), name, shorthand, usage) +} + // 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 (f *FlagSet) IPNet(name string, value net.IPNet, usage string) *net.IPNet { diff --git a/ipnet_slice.go b/ipnet_slice.go index 6b541aa8..07e8a091 100644 --- a/ipnet_slice.go +++ b/ipnet_slice.go @@ -109,6 +109,11 @@ func (f *FlagSet) IPNetSliceVarP(p *[]net.IPNet, name, shorthand string, value [ f.VarP(newIPNetSliceValue(value, p), name, shorthand, usage) } +// IPNetSliceVarPF is like IPNetSliceVarP, but returns the created flag. +func (f *FlagSet) IPNetSliceVarPF(p *[]net.IPNet, name, shorthand string, value []net.IPNet, usage string) *Flag { + return f.VarPF(newIPNetSliceValue(value, p), name, shorthand, usage) +} + // IPNetSliceVar defines a []net.IPNet flag with specified name, default value, and usage string. // The argument p points to a []net.IPNet variable in which to store the value of the flag. func IPNetSliceVar(p *[]net.IPNet, name string, value []net.IPNet, usage string) { @@ -120,6 +125,11 @@ func IPNetSliceVarP(p *[]net.IPNet, name, shorthand string, value []net.IPNet, u CommandLine.VarP(newIPNetSliceValue(value, p), name, shorthand, usage) } +// IPNetSliceVarPF is like IPNetSliceVarP, but returns the created flag. +func IPNetSliceVarPF(p *[]net.IPNet, name, shorthand string, value []net.IPNet, usage string) *Flag { + return CommandLine.VarPF(newIPNetSliceValue(value, p), name, shorthand, usage) +} + // IPNetSlice defines a []net.IPNet flag with specified name, default value, and usage string. // The return value is the address of a []net.IPNet variable that stores the value of that flag. func (f *FlagSet) IPNetSlice(name string, value []net.IPNet, usage string) *[]net.IPNet { diff --git a/string.go b/string.go index 04e0a26f..9a7e0bbf 100644 --- a/string.go +++ b/string.go @@ -42,6 +42,11 @@ func (f *FlagSet) StringVarP(p *string, name, shorthand string, value string, us f.VarP(newStringValue(value, p), name, shorthand, usage) } +// StringVarPF is like StringVarP, but returns the created flag. +func (f *FlagSet) StringVarPF(p *string, name, shorthand string, value string, usage string) *Flag { + return f.VarPF(newStringValue(value, p), name, shorthand, usage) +} + // 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 StringVar(p *string, name string, value string, usage string) { @@ -53,6 +58,11 @@ func StringVarP(p *string, name, shorthand string, value string, usage string) { CommandLine.VarP(newStringValue(value, p), name, shorthand, usage) } +// StringVarPF is like StringVarP, but returns the created flag. +func StringVarPF(p *string, name, shorthand string, value string, usage string) *Flag { + return CommandLine.VarPF(newStringValue(value, p), name, shorthand, usage) +} + // 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 (f *FlagSet) String(name string, value string, usage string) *string { diff --git a/string_array.go b/string_array.go index d1ff0a96..dfbbeeb7 100644 --- a/string_array.go +++ b/string_array.go @@ -84,6 +84,11 @@ func (f *FlagSet) StringArrayVarP(p *[]string, name, shorthand string, value []s f.VarP(newStringArrayValue(value, p), name, shorthand, usage) } +// StringArrayVarPF is like StringArrayVarP, but returns the created flag. +func (f *FlagSet) StringArrayVarPF(p *[]string, name, shorthand string, value []string, usage string) *Flag { + return f.VarPF(newStringArrayValue(value, p), name, shorthand, usage) +} + // 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. @@ -96,6 +101,11 @@ func StringArrayVarP(p *[]string, name, shorthand string, value []string, usage CommandLine.VarP(newStringArrayValue(value, p), name, shorthand, usage) } +// StringArrayVarPF is like StringArrayVarP, but returns the created flag. +func StringArrayVarPF(p *[]string, name, shorthand string, value []string, usage string) *Flag { + return CommandLine.VarPF(newStringArrayValue(value, p), name, shorthand, usage) +} + // 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. diff --git a/string_slice.go b/string_slice.go index 3cb2e69d..14bd26ae 100644 --- a/string_slice.go +++ b/string_slice.go @@ -98,9 +98,12 @@ func (f *FlagSet) GetStringSlice(name string) ([]string, error) { // 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" +// +// --ss="v1,v2" --ss="v3" +// // will result in -// []string{"v1", "v2", "v3"} +// +// []string{"v1", "v2", "v3"} func (f *FlagSet) StringSliceVar(p *[]string, name string, value []string, usage string) { f.VarP(newStringSliceValue(value, p), name, "", usage) } @@ -110,13 +113,21 @@ func (f *FlagSet) StringSliceVarP(p *[]string, name, shorthand string, value []s f.VarP(newStringSliceValue(value, p), name, shorthand, usage) } +// StringSliceVarPF is like StringSliceVarP, but returns the created flag. +func (f *FlagSet) StringSliceVarPF(p *[]string, name, shorthand string, value []string, usage string) *Flag { + return f.VarPF(newStringSliceValue(value, p), name, shorthand, usage) +} + // 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" +// +// --ss="v1,v2" --ss="v3" +// // will result in -// []string{"v1", "v2", "v3"} +// +// []string{"v1", "v2", "v3"} func StringSliceVar(p *[]string, name string, value []string, usage string) { CommandLine.VarP(newStringSliceValue(value, p), name, "", usage) } @@ -126,13 +137,21 @@ func StringSliceVarP(p *[]string, name, shorthand string, value []string, usage CommandLine.VarP(newStringSliceValue(value, p), name, shorthand, usage) } +// StringSliceVarPF is like StringSliceVarP, but returns the created flag. +func StringSliceVarPF(p *[]string, name, shorthand string, value []string, usage string) *Flag { + return CommandLine.VarPF(newStringSliceValue(value, p), name, shorthand, 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. // Compared to StringArray flags, StringSlice flags take comma-separated value as arguments and split them accordingly. // For example: -// --ss="v1,v2" --ss="v3" +// +// --ss="v1,v2" --ss="v3" +// // will result in -// []string{"v1", "v2", "v3"} +// +// []string{"v1", "v2", "v3"} func (f *FlagSet) StringSlice(name string, value []string, usage string) *[]string { p := []string{} f.StringSliceVarP(&p, name, "", value, usage) @@ -150,9 +169,12 @@ func (f *FlagSet) StringSliceP(name, shorthand string, value []string, usage str // 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" +// +// --ss="v1,v2" --ss="v3" +// // will result in -// []string{"v1", "v2", "v3"} +// +// []string{"v1", "v2", "v3"} func StringSlice(name string, value []string, usage string) *[]string { return CommandLine.StringSliceP(name, "", value, usage) } diff --git a/string_to_int.go b/string_to_int.go index 5ceda396..2335f8e4 100644 --- a/string_to_int.go +++ b/string_to_int.go @@ -108,6 +108,11 @@ func (f *FlagSet) StringToIntVarP(p *map[string]int, name, shorthand string, val f.VarP(newStringToIntValue(value, p), name, shorthand, usage) } +// StringToIntVarPF is like StringToIntVarP, but returns the created flag. +func (f *FlagSet) StringToIntVarPF(p *map[string]int, name, shorthand string, value map[string]int, usage string) *Flag { + return f.VarPF(newStringToIntValue(value, p), name, shorthand, usage) +} + // 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 @@ -120,6 +125,11 @@ func StringToIntVarP(p *map[string]int, name, shorthand string, value map[string CommandLine.VarP(newStringToIntValue(value, p), name, shorthand, usage) } +// StringToIntVarPF is like StringToIntVarP, but returns the created flag. +func StringToIntVarPF(p *map[string]int, name, shorthand string, value map[string]int, usage string) *Flag { + return CommandLine.VarPF(newStringToIntValue(value, p), name, shorthand, usage) +} + // 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 diff --git a/string_to_int64.go b/string_to_int64.go index a807a04a..ec835c80 100644 --- a/string_to_int64.go +++ b/string_to_int64.go @@ -108,6 +108,11 @@ func (f *FlagSet) StringToInt64VarP(p *map[string]int64, name, shorthand string, f.VarP(newStringToInt64Value(value, p), name, shorthand, usage) } +// StringToInt64VarPF is like StringToInt64VarP, but returns the created flag. +func (f *FlagSet) StringToInt64VarPF(p *map[string]int64, name, shorthand string, value map[string]int64, usage string) *Flag { + return f.VarPF(newStringToInt64Value(value, p), name, shorthand, usage) +} + // 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 @@ -120,6 +125,11 @@ func StringToInt64VarP(p *map[string]int64, name, shorthand string, value map[st CommandLine.VarP(newStringToInt64Value(value, p), name, shorthand, usage) } +// StringToInt64VarPF is like StringToInt64VarP, but returns the created flag. +func StringToInt64VarPF(p *map[string]int64, name, shorthand string, value map[string]int64, usage string) *Flag { + return CommandLine.VarPF(newStringToInt64Value(value, p), name, shorthand, usage) +} + // 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 diff --git a/string_to_string.go b/string_to_string.go index 890a01af..63be45bd 100644 --- a/string_to_string.go +++ b/string_to_string.go @@ -119,6 +119,11 @@ func (f *FlagSet) StringToStringVarP(p *map[string]string, name, shorthand strin f.VarP(newStringToStringValue(value, p), name, shorthand, usage) } +// StringToStringVarPF is like StringToStringVarP, but returns the created flag. +func (f *FlagSet) StringToStringVarPF(p *map[string]string, name, shorthand string, value map[string]string, usage string) *Flag { + return f.VarPF(newStringToStringValue(value, p), name, shorthand, usage) +} + // 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 @@ -131,6 +136,11 @@ func StringToStringVarP(p *map[string]string, name, shorthand string, value map[ CommandLine.VarP(newStringToStringValue(value, p), name, shorthand, usage) } +// StringToStringVarPF is like StringToStringVarP, but returns the created flag. +func StringToStringVarPF(p *map[string]string, name, shorthand string, value map[string]string, usage string) *Flag { + return CommandLine.VarPF(newStringToStringValue(value, p), name, shorthand, usage) +} + // 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 diff --git a/uint.go b/uint.go index dcbc2b75..7af76f4d 100644 --- a/uint.go +++ b/uint.go @@ -50,6 +50,11 @@ func (f *FlagSet) UintVarP(p *uint, name, shorthand string, value uint, usage st f.VarP(newUintValue(value, p), name, shorthand, usage) } +// UintVarPF is like UintVarP, but returns the created flag. +func (f *FlagSet) UintVarPF(p *uint, name, shorthand string, value uint, usage string) *Flag { + return f.VarPF(newUintValue(value, p), name, shorthand, usage) +} + // 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 UintVar(p *uint, name string, value uint, usage string) { @@ -61,6 +66,11 @@ func UintVarP(p *uint, name, shorthand string, value uint, usage string) { CommandLine.VarP(newUintValue(value, p), name, shorthand, usage) } +// UintVarPF is like UintVarP, but returns the created flag. +func UintVarPF(p *uint, name, shorthand string, value uint, usage string) *Flag { + return CommandLine.VarPF(newUintValue(value, p), name, shorthand, usage) +} + // 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 (f *FlagSet) Uint(name string, value uint, usage string) *uint { diff --git a/uint16.go b/uint16.go index 7e9914ed..fe04e202 100644 --- a/uint16.go +++ b/uint16.go @@ -50,6 +50,11 @@ func (f *FlagSet) Uint16VarP(p *uint16, name, shorthand string, value uint16, us f.VarP(newUint16Value(value, p), name, shorthand, usage) } +// Uint16VarPF is like Uint16VarP, but returns the created flag. +func (f *FlagSet) Uint16VarPF(p *uint16, name, shorthand string, value uint16, usage string) *Flag { + return f.VarPF(newUint16Value(value, p), name, shorthand, usage) +} + // 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 Uint16Var(p *uint16, name string, value uint16, usage string) { @@ -61,6 +66,11 @@ func Uint16VarP(p *uint16, name, shorthand string, value uint16, usage string) { CommandLine.VarP(newUint16Value(value, p), name, shorthand, usage) } +// Uint16VarPF is like Uint16VarP, but returns the created flag. +func Uint16VarPF(p *uint16, name, shorthand string, value uint16, usage string) *Flag { + return CommandLine.VarPF(newUint16Value(value, p), name, shorthand, usage) +} + // 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 (f *FlagSet) Uint16(name string, value uint16, usage string) *uint16 { diff --git a/uint32.go b/uint32.go index d8024539..58b91db4 100644 --- a/uint32.go +++ b/uint32.go @@ -50,6 +50,11 @@ func (f *FlagSet) Uint32VarP(p *uint32, name, shorthand string, value uint32, us f.VarP(newUint32Value(value, p), name, shorthand, usage) } +// Uint32VarPF is like Uint32Var, but returns the created flag. +func (f *FlagSet) Uint32VarPF(p *uint32, name, shorthand string, value uint32, usage string) *Flag { + return f.VarPF(newUint32Value(value, p), name, shorthand, usage) +} + // 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 Uint32Var(p *uint32, name string, value uint32, usage string) { @@ -61,6 +66,11 @@ func Uint32VarP(p *uint32, name, shorthand string, value uint32, usage string) { CommandLine.VarP(newUint32Value(value, p), name, shorthand, usage) } +// Uint32VarPF is like Uint32VarP, but returns the created flag. +func Uint32VarPF(p *uint32, name, shorthand string, value uint32, usage string) *Flag { + return CommandLine.VarPF(newUint32Value(value, p), name, shorthand, usage) +} + // 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 (f *FlagSet) Uint32(name string, value uint32, usage string) *uint32 { diff --git a/uint64.go b/uint64.go index f62240f2..96dd5a63 100644 --- a/uint64.go +++ b/uint64.go @@ -50,6 +50,11 @@ func (f *FlagSet) Uint64VarP(p *uint64, name, shorthand string, value uint64, us f.VarP(newUint64Value(value, p), name, shorthand, usage) } +// Uint64VarPF is like Uint64VarP, but returns the created flag. +func (f *FlagSet) Uint64VarPF(p *uint64, name, shorthand string, value uint64, usage string) *Flag { + return f.VarPF(newUint64Value(value, p), name, shorthand, usage) +} + // 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 Uint64Var(p *uint64, name string, value uint64, usage string) { @@ -61,6 +66,11 @@ func Uint64VarP(p *uint64, name, shorthand string, value uint64, usage string) { CommandLine.VarP(newUint64Value(value, p), name, shorthand, usage) } +// Uint64VarPF is like Uint64VarP, but returns the created flag. +func Uint64VarPF(p *uint64, name, shorthand string, value uint64, usage string) *Flag { + return CommandLine.VarPF(newUint64Value(value, p), name, shorthand, usage) +} + // 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 (f *FlagSet) Uint64(name string, value uint64, usage string) *uint64 { diff --git a/uint8.go b/uint8.go index bb0e83c1..7960d654 100644 --- a/uint8.go +++ b/uint8.go @@ -50,6 +50,11 @@ func (f *FlagSet) Uint8VarP(p *uint8, name, shorthand string, value uint8, usage f.VarP(newUint8Value(value, p), name, shorthand, usage) } +// Uint8VarPF is like Uint8VarP, but returns the created flag. +func (f *FlagSet) Uint8VarPF(p *uint8, name, shorthand string, value uint8, usage string) *Flag { + return f.VarPF(newUint8Value(value, p), name, shorthand, usage) +} + // 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 Uint8Var(p *uint8, name string, value uint8, usage string) { @@ -61,6 +66,11 @@ func Uint8VarP(p *uint8, name, shorthand string, value uint8, usage string) { CommandLine.VarP(newUint8Value(value, p), name, shorthand, usage) } +// Uint8VarPF is like Uint8VarP, but returns the created flag. +func Uint8VarPF(p *uint8, name, shorthand string, value uint8, usage string) *Flag { + return CommandLine.VarPF(newUint8Value(value, p), name, shorthand, usage) +} + // 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 (f *FlagSet) Uint8(name string, value uint8, usage string) *uint8 { diff --git a/uint_slice.go b/uint_slice.go index 5fa92483..240c7d10 100644 --- a/uint_slice.go +++ b/uint_slice.go @@ -130,6 +130,11 @@ func (f *FlagSet) UintSliceVarP(p *[]uint, name, shorthand string, value []uint, f.VarP(newUintSliceValue(value, p), name, shorthand, usage) } +// UintSliceVarPF is like UintSliceVarP, but returns the created flag. +func (f *FlagSet) UintSliceVarPF(p *[]uint, name, shorthand string, value []uint, usage string) *Flag { + return f.VarPF(newUintSliceValue(value, p), name, shorthand, usage) +} + // 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 UintSliceVar(p *[]uint, name string, value []uint, usage string) { @@ -141,6 +146,11 @@ func UintSliceVarP(p *[]uint, name, shorthand string, value []uint, usage string CommandLine.VarP(newUintSliceValue(value, p), name, shorthand, usage) } +// UintSliceVarPF is like the UintSliceVarP, but returns the created flag. +func UintSliceVarPF(p *[]uint, name, shorthand string, value []uint, usage string) *Flag { + return CommandLine.VarPF(newUintSliceValue(value, p), name, shorthand, usage) +} + // 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 (f *FlagSet) UintSlice(name string, value []uint, usage string) *[]uint {