diff --git a/flag-spec.yaml b/flag-spec.yaml index 3fa2d10367..39f6006d88 100644 --- a/flag-spec.yaml +++ b/flag-spec.yaml @@ -5,12 +5,7 @@ flag_types: bool: no_default_text: true - float64: {} - int64: {} - int: {} time.Duration: {} - uint64: {} - uint: {} string: no_default_text: true diff --git a/flag_float64.go b/flag_float64.go deleted file mode 100644 index b7b8044a53..0000000000 --- a/flag_float64.go +++ /dev/null @@ -1,64 +0,0 @@ -package cli - -import ( - "flag" - "fmt" - "strconv" -) - -// GetValue returns the flags value as string representation and an empty -// string if the flag takes no value at all. -func (f *Float64Flag) GetValue() string { - return fmt.Sprintf("%v", f.Value) -} - -// Apply populates the flag given the flag set and environment -func (f *Float64Flag) Apply(set *flag.FlagSet) error { - if val, source, found := flagFromEnvOrFile(f.EnvVars, f.FilePath); found { - if val != "" { - valFloat, err := strconv.ParseFloat(val, 64) - if err != nil { - return fmt.Errorf("could not parse %q as float64 value from %s for flag %s: %s", val, source, f.Name, err) - } - - f.Value = valFloat - f.HasBeenSet = true - } - } - - for _, name := range f.Names() { - if f.Destination != nil { - set.Float64Var(f.Destination, name, f.Value, f.Usage) - continue - } - set.Float64(name, f.Value, f.Usage) - } - - return nil -} - -// Get returns the flag’s value in the given Context. -func (f *Float64Flag) Get(ctx *Context) float64 { - return ctx.Float64(f.Name) -} - -// Float64 looks up the value of a local Float64Flag, returns -// 0 if not found -func (cCtx *Context) Float64(name string) float64 { - if fs := cCtx.lookupFlagSet(name); fs != nil { - return lookupFloat64(name, fs) - } - return 0 -} - -func lookupFloat64(name string, set *flag.FlagSet) float64 { - f := set.Lookup(name) - if f != nil { - parsed, err := strconv.ParseFloat(f.Value.String(), 64) - if err != nil { - return 0 - } - return parsed - } - return 0 -} diff --git a/flag_int.go b/flag_int.go deleted file mode 100644 index 908e076162..0000000000 --- a/flag_int.go +++ /dev/null @@ -1,65 +0,0 @@ -package cli - -import ( - "flag" - "fmt" - "strconv" -) - -// GetValue returns the flags value as string representation and an empty -// string if the flag takes no value at all. -func (f *IntFlag) GetValue() string { - return fmt.Sprintf("%d", f.Value) -} - -// Apply populates the flag given the flag set and environment -func (f *IntFlag) Apply(set *flag.FlagSet) error { - if val, source, found := flagFromEnvOrFile(f.EnvVars, f.FilePath); found { - if val != "" { - valInt, err := strconv.ParseInt(val, 0, 64) - - if err != nil { - return fmt.Errorf("could not parse %q as int value from %s for flag %s: %s", val, source, f.Name, err) - } - - f.Value = int(valInt) - f.HasBeenSet = true - } - } - - for _, name := range f.Names() { - if f.Destination != nil { - set.IntVar(f.Destination, name, f.Value, f.Usage) - continue - } - set.Int(name, f.Value, f.Usage) - } - - return nil -} - -// Get returns the flag’s value in the given Context. -func (f *IntFlag) Get(ctx *Context) int { - return ctx.Int(f.Name) -} - -// Int looks up the value of a local IntFlag, returns -// 0 if not found -func (cCtx *Context) Int(name string) int { - if fs := cCtx.lookupFlagSet(name); fs != nil { - return lookupInt(name, fs) - } - return 0 -} - -func lookupInt(name string, set *flag.FlagSet) int { - f := set.Lookup(name) - if f != nil { - parsed, err := strconv.ParseInt(f.Value.String(), 0, 64) - if err != nil { - return 0 - } - return int(parsed) - } - return 0 -} diff --git a/flag_int64.go b/flag_int64.go deleted file mode 100644 index 9f07d79a8c..0000000000 --- a/flag_int64.go +++ /dev/null @@ -1,64 +0,0 @@ -package cli - -import ( - "flag" - "fmt" - "strconv" -) - -// GetValue returns the flags value as string representation and an empty -// string if the flag takes no value at all. -func (f *Int64Flag) GetValue() string { - return fmt.Sprintf("%d", f.Value) -} - -// Apply populates the flag given the flag set and environment -func (f *Int64Flag) Apply(set *flag.FlagSet) error { - if val, source, found := flagFromEnvOrFile(f.EnvVars, f.FilePath); found { - if val != "" { - valInt, err := strconv.ParseInt(val, 0, 64) - - if err != nil { - return fmt.Errorf("could not parse %q as int value from %s for flag %s: %s", val, source, f.Name, err) - } - - f.Value = valInt - f.HasBeenSet = true - } - } - - for _, name := range f.Names() { - if f.Destination != nil { - set.Int64Var(f.Destination, name, f.Value, f.Usage) - continue - } - set.Int64(name, f.Value, f.Usage) - } - return nil -} - -// Get returns the flag’s value in the given Context. -func (f *Int64Flag) Get(ctx *Context) int64 { - return ctx.Int64(f.Name) -} - -// Int64 looks up the value of a local Int64Flag, returns -// 0 if not found -func (cCtx *Context) Int64(name string) int64 { - if fs := cCtx.lookupFlagSet(name); fs != nil { - return lookupInt64(name, fs) - } - return 0 -} - -func lookupInt64(name string, set *flag.FlagSet) int64 { - f := set.Lookup(name) - if f != nil { - parsed, err := strconv.ParseInt(f.Value.String(), 0, 64) - if err != nil { - return 0 - } - return parsed - } - return 0 -} diff --git a/flag_test.go b/flag_test.go index deac525b49..06530454ad 100644 --- a/flag_test.go +++ b/flag_test.go @@ -106,8 +106,8 @@ func TestFlagsFromEnv(t *testing.T) { {"foobar", 0, &Float64Flag{Name: "seconds", EnvVars: []string{"SECONDS"}}, `could not parse "foobar" as float64 value from environment variable "SECONDS" for flag seconds: .*`}, {"1", int64(1), &Int64Flag{Name: "seconds", EnvVars: []string{"SECONDS"}}, ""}, - {"1.2", 0, &Int64Flag{Name: "seconds", EnvVars: []string{"SECONDS"}}, `could not parse "1.2" as int value from environment variable "SECONDS" for flag seconds: .*`}, - {"foobar", 0, &Int64Flag{Name: "seconds", EnvVars: []string{"SECONDS"}}, `could not parse "foobar" as int value from environment variable "SECONDS" for flag seconds: .*`}, + {"1.2", 0, &Int64Flag{Name: "seconds", EnvVars: []string{"SECONDS"}}, `could not parse "1.2" as int64 value from environment variable "SECONDS" for flag seconds: .*`}, + {"foobar", 0, &Int64Flag{Name: "seconds", EnvVars: []string{"SECONDS"}}, `could not parse "foobar" as int64 value from environment variable "SECONDS" for flag seconds: .*`}, {"1", 1, &IntFlag{Name: "seconds", EnvVars: []string{"SECONDS"}}, ""}, {"1.2", 0, &IntFlag{Name: "seconds", EnvVars: []string{"SECONDS"}}, `could not parse "1.2" as int value from environment variable "SECONDS" for flag seconds: .*`}, @@ -2384,43 +2384,43 @@ func TestFlagDefaultValue(t *testing.T) { name: "stringSclice", flag: &StringSliceFlag{Name: "flag", Value: NewStringSlice("default1", "default2")}, toParse: []string{"--flag", "parsed"}, - expect: `--flag value (default: "default1", "default2") (accepts multiple inputs)`, + expect: `--flag value (default: "default1", "default2") (accepts multiple inputs)`, }, { name: "float64Sclice", flag: &Float64SliceFlag{Name: "flag", Value: NewFloat64Slice(1.1, 2.2)}, toParse: []string{"--flag", "13.3"}, - expect: `--flag value (default: 1.1, 2.2) (accepts multiple inputs)`, + expect: `--flag value (default: 1.1, 2.2) (accepts multiple inputs)`, }, { name: "int64Sclice", flag: &Int64SliceFlag{Name: "flag", Value: NewInt64Slice(1, 2)}, toParse: []string{"--flag", "13"}, - expect: `--flag value (default: 1, 2) (accepts multiple inputs)`, + expect: `--flag value (default: 1, 2) (accepts multiple inputs)`, }, { name: "intSclice", flag: &IntSliceFlag{Name: "flag", Value: NewIntSlice(1, 2)}, toParse: []string{"--flag", "13"}, - expect: `--flag value (default: 1, 2) (accepts multiple inputs)`, + expect: `--flag value (default: 1, 2) (accepts multiple inputs)`, }, { name: "string", flag: &StringFlag{Name: "flag", Value: "default"}, toParse: []string{"--flag", "parsed"}, - expect: `--flag value (default: "default")`, + expect: `--flag value (default: "default")`, }, { name: "bool", flag: &BoolFlag{Name: "flag", Value: true}, toParse: []string{"--flag", "false"}, - expect: `--flag (default: true)`, + expect: `--flag (default: true)`, }, { name: "uint64", flag: &Uint64Flag{Name: "flag", Value: 1}, toParse: []string{"--flag", "13"}, - expect: `--flag value (default: 1)`, + expect: `--flag value (default: 1)`, }, } for i, v := range cases { diff --git a/flag_uint.go b/flag_uint.go deleted file mode 100644 index d03fa7cd5a..0000000000 --- a/flag_uint.go +++ /dev/null @@ -1,64 +0,0 @@ -package cli - -import ( - "flag" - "fmt" - "strconv" -) - -// Apply populates the flag given the flag set and environment -func (f *UintFlag) Apply(set *flag.FlagSet) error { - if val, source, found := flagFromEnvOrFile(f.EnvVars, f.FilePath); found { - if val != "" { - valInt, err := strconv.ParseUint(val, 0, 64) - if err != nil { - return fmt.Errorf("could not parse %q as uint value from %s for flag %s: %s", val, source, f.Name, err) - } - - f.Value = uint(valInt) - f.HasBeenSet = true - } - } - - for _, name := range f.Names() { - if f.Destination != nil { - set.UintVar(f.Destination, name, f.Value, f.Usage) - continue - } - set.Uint(name, f.Value, f.Usage) - } - - return nil -} - -// GetValue returns the flags value as string representation and an empty -// string if the flag takes no value at all. -func (f *UintFlag) GetValue() string { - return fmt.Sprintf("%d", f.Value) -} - -// Get returns the flag’s value in the given Context. -func (f *UintFlag) Get(ctx *Context) uint { - return ctx.Uint(f.Name) -} - -// Uint looks up the value of a local UintFlag, returns -// 0 if not found -func (cCtx *Context) Uint(name string) uint { - if fs := cCtx.lookupFlagSet(name); fs != nil { - return lookupUint(name, fs) - } - return 0 -} - -func lookupUint(name string, set *flag.FlagSet) uint { - f := set.Lookup(name) - if f != nil { - parsed, err := strconv.ParseUint(f.Value.String(), 0, 64) - if err != nil { - return 0 - } - return uint(parsed) - } - return 0 -} diff --git a/flag_uint64.go b/flag_uint64.go deleted file mode 100644 index 5c06ab4f59..0000000000 --- a/flag_uint64.go +++ /dev/null @@ -1,64 +0,0 @@ -package cli - -import ( - "flag" - "fmt" - "strconv" -) - -// Apply populates the flag given the flag set and environment -func (f *Uint64Flag) Apply(set *flag.FlagSet) error { - if val, source, found := flagFromEnvOrFile(f.EnvVars, f.FilePath); found { - if val != "" { - valInt, err := strconv.ParseUint(val, 0, 64) - if err != nil { - return fmt.Errorf("could not parse %q as uint64 value from %s for flag %s: %s", val, source, f.Name, err) - } - - f.Value = valInt - f.HasBeenSet = true - } - } - - for _, name := range f.Names() { - if f.Destination != nil { - set.Uint64Var(f.Destination, name, f.Value, f.Usage) - continue - } - set.Uint64(name, f.Value, f.Usage) - } - - return nil -} - -// GetValue returns the flags value as string representation and an empty -// string if the flag takes no value at all. -func (f *Uint64Flag) GetValue() string { - return fmt.Sprintf("%d", f.Value) -} - -// Get returns the flag’s value in the given Context. -func (f *Uint64Flag) Get(ctx *Context) uint64 { - return ctx.Uint64(f.Name) -} - -// Uint64 looks up the value of a local Uint64Flag, returns -// 0 if not found -func (cCtx *Context) Uint64(name string) uint64 { - if fs := cCtx.lookupFlagSet(name); fs != nil { - return lookupUint64(name, fs) - } - return 0 -} - -func lookupUint64(name string, set *flag.FlagSet) uint64 { - f := set.Lookup(name) - if f != nil { - parsed, err := strconv.ParseUint(f.Value.String(), 0, 64) - if err != nil { - return 0 - } - return parsed - } - return 0 -} diff --git a/go.mod b/go.mod index 4e39308336..d22a3a72af 100644 --- a/go.mod +++ b/go.mod @@ -10,4 +10,7 @@ require ( gopkg.in/yaml.v3 v3.0.1 ) -require github.com/russross/blackfriday/v2 v2.1.0 // indirect +require ( + github.com/russross/blackfriday/v2 v2.1.0 // indirect + golang.org/x/exp v0.0.0-20221002003631-540bb7301a08 // indirect +) diff --git a/go.sum b/go.sum index 6beae99a6d..b59cd64705 100644 --- a/go.sum +++ b/go.sum @@ -8,6 +8,8 @@ github.com/russross/blackfriday/v2 v2.1.0 h1:JIOH55/0cWyOuilr9/qlrm0BSXldqnqwMsf github.com/russross/blackfriday/v2 v2.1.0/go.mod h1:+Rmxgy9KzJVeS9/2gXHxylqXiyQDYRxCVz55jmeOWTM= github.com/xrash/smetrics v0.0.0-20201216005158-039620a65673 h1:bAn7/zixMGCfxrRTfdpNzjtPYqr8smhKouy9mxVdGPU= github.com/xrash/smetrics v0.0.0-20201216005158-039620a65673/go.mod h1:N3UwUGtsrSj3ccvlPHLoLsHnpR27oXr4ZE984MbSER8= +golang.org/x/exp v0.0.0-20221002003631-540bb7301a08 h1:LtBIgSqNhkuC9gA3BFjGy5obHQT1lnmNsMDFSqWzQ5w= +golang.org/x/exp v0.0.0-20221002003631-540bb7301a08/go.mod h1:cyybsKvd6eL0RnXn6p/Grxp8F5bW7iYuBgsNCOHpMYE= golang.org/x/text v0.3.7 h1:olpwvP2KacW1ZWvsR7uQhoyTYvKAupfQrRGBFM352Gk= golang.org/x/text v0.3.7/go.mod h1:u+2+/6zg+i71rQMx5EYifcz6MCKuco9NR6JIITiCfzQ= golang.org/x/tools v0.0.0-20180917221912-90fa682c2a6e h1:FDhOuMEY4JVRztM/gsbk+IKUQ8kj74bxZrgw87eMMVc= diff --git a/godoc-current.txt b/godoc-current.txt index c35428ebc1..0058092fa6 100644 --- a/godoc-current.txt +++ b/godoc-current.txt @@ -629,7 +629,7 @@ func (cCtx *Context) FlagNames() []string its parent contexts. func (cCtx *Context) Float64(name string) float64 - Float64 looks up the value of a local Float64Flag, returns 0 if not found + Int looks up the value of a local IntFlag, returns 0 if not found func (cCtx *Context) Float64Slice(name string) []float64 Float64Slice looks up the value of a local Float64SliceFlag, returns nil if @@ -685,10 +685,10 @@ func (cCtx *Context) Timestamp(name string) *time.Time Timestamp gets the timestamp from a flag name func (cCtx *Context) Uint(name string) uint - Uint looks up the value of a local UintFlag, returns 0 if not found + Int looks up the value of a local IntFlag, returns 0 if not found func (cCtx *Context) Uint64(name string) uint64 - Uint64 looks up the value of a local Uint64Flag, returns 0 if not found + Int64 looks up the value of a local Int64Flag, returns 0 if not found func (cCtx *Context) Value(name string) interface{} Value returns the value of the flag corresponding to `name` @@ -896,65 +896,7 @@ func (f FlagsByName) Less(i, j int) bool func (f FlagsByName) Swap(i, j int) -type Float64Flag struct { - Name string - - Category string - DefaultText string - FilePath string - Usage string - - Required bool - Hidden bool - HasBeenSet bool - - Value float64 - Destination *float64 - - Aliases []string - EnvVars []string -} - Float64Flag is a flag with type float64 - -func (f *Float64Flag) Apply(set *flag.FlagSet) error - Apply populates the flag given the flag set and environment - -func (f *Float64Flag) Get(ctx *Context) float64 - Get returns the flag’s value in the given Context. - -func (f *Float64Flag) GetCategory() string - GetCategory returns the category of the flag - -func (f *Float64Flag) GetDefaultText() string - GetDefaultText returns the default text for this flag - -func (f *Float64Flag) GetEnvVars() []string - GetEnvVars returns the env vars for this flag - -func (f *Float64Flag) GetUsage() string - GetUsage returns the usage string for the flag - -func (f *Float64Flag) GetValue() string - GetValue returns the flags value as string representation and an empty - string if the flag takes no value at all. - -func (f *Float64Flag) IsRequired() bool - IsRequired returns whether or not the flag is required - -func (f *Float64Flag) IsSet() bool - IsSet returns whether or not the flag has been set through env or file - -func (f *Float64Flag) IsVisible() bool - IsVisible returns true if the flag is not hidden, otherwise false - -func (f *Float64Flag) Names() []string - Names returns the names of the flag - -func (f *Float64Flag) String() string - String returns a readable representation of this value (for usage defaults) - -func (f *Float64Flag) TakesValue() bool - TakesValue returns true if the flag takes a value, otherwise false +type Float64Flag = flagImpl[float64] type Float64Slice struct { // Has unexported fields. @@ -1114,65 +1056,7 @@ func (f *GenericFlag) String() string func (f *GenericFlag) TakesValue() bool TakesValue returns true if the flag takes a value, otherwise false -type Int64Flag struct { - Name string - - Category string - DefaultText string - FilePath string - Usage string - - Required bool - Hidden bool - HasBeenSet bool - - Value int64 - Destination *int64 - - Aliases []string - EnvVars []string -} - Int64Flag is a flag with type int64 - -func (f *Int64Flag) Apply(set *flag.FlagSet) error - Apply populates the flag given the flag set and environment - -func (f *Int64Flag) Get(ctx *Context) int64 - Get returns the flag’s value in the given Context. - -func (f *Int64Flag) GetCategory() string - GetCategory returns the category of the flag - -func (f *Int64Flag) GetDefaultText() string - GetDefaultText returns the default text for this flag - -func (f *Int64Flag) GetEnvVars() []string - GetEnvVars returns the env vars for this flag - -func (f *Int64Flag) GetUsage() string - GetUsage returns the usage string for the flag - -func (f *Int64Flag) GetValue() string - GetValue returns the flags value as string representation and an empty - string if the flag takes no value at all. - -func (f *Int64Flag) IsRequired() bool - IsRequired returns whether or not the flag is required - -func (f *Int64Flag) IsSet() bool - IsSet returns whether or not the flag has been set through env or file - -func (f *Int64Flag) IsVisible() bool - IsVisible returns true if the flag is not hidden, otherwise false - -func (f *Int64Flag) Names() []string - Names returns the names of the flag - -func (f *Int64Flag) String() string - String returns a readable representation of this value (for usage defaults) - -func (f *Int64Flag) TakesValue() bool - TakesValue returns true if the flag takes a value, otherwise false +type Int64Flag = flagImpl[int64] type Int64Slice struct { // Has unexported fields. @@ -1263,65 +1147,7 @@ func (f *Int64SliceFlag) String() string func (f *Int64SliceFlag) TakesValue() bool TakesValue returns true if the flag takes a value, otherwise false -type IntFlag struct { - Name string - - Category string - DefaultText string - FilePath string - Usage string - - Required bool - Hidden bool - HasBeenSet bool - - Value int - Destination *int - - Aliases []string - EnvVars []string -} - IntFlag is a flag with type int - -func (f *IntFlag) Apply(set *flag.FlagSet) error - Apply populates the flag given the flag set and environment - -func (f *IntFlag) Get(ctx *Context) int - Get returns the flag’s value in the given Context. - -func (f *IntFlag) GetCategory() string - GetCategory returns the category of the flag - -func (f *IntFlag) GetDefaultText() string - GetDefaultText returns the default text for this flag - -func (f *IntFlag) GetEnvVars() []string - GetEnvVars returns the env vars for this flag - -func (f *IntFlag) GetUsage() string - GetUsage returns the usage string for the flag - -func (f *IntFlag) GetValue() string - GetValue returns the flags value as string representation and an empty - string if the flag takes no value at all. - -func (f *IntFlag) IsRequired() bool - IsRequired returns whether or not the flag is required - -func (f *IntFlag) IsSet() bool - IsSet returns whether or not the flag has been set through env or file - -func (f *IntFlag) IsVisible() bool - IsVisible returns true if the flag is not hidden, otherwise false - -func (f *IntFlag) Names() []string - Names returns the names of the flag - -func (f *IntFlag) String() string - String returns a readable representation of this value (for usage defaults) - -func (f *IntFlag) TakesValue() bool - TakesValue returns true if the flag takes a value, otherwise false +type IntFlag = flagImpl[int] type IntSlice struct { // Has unexported fields. @@ -1820,125 +1646,9 @@ func (f *TimestampFlag) String() string func (f *TimestampFlag) TakesValue() bool TakesValue returns true if the flag takes a value, otherwise false -type Uint64Flag struct { - Name string - - Category string - DefaultText string - FilePath string - Usage string - - Required bool - Hidden bool - HasBeenSet bool - - Value uint64 - Destination *uint64 - - Aliases []string - EnvVars []string -} - Uint64Flag is a flag with type uint64 - -func (f *Uint64Flag) Apply(set *flag.FlagSet) error - Apply populates the flag given the flag set and environment - -func (f *Uint64Flag) Get(ctx *Context) uint64 - Get returns the flag’s value in the given Context. - -func (f *Uint64Flag) GetCategory() string - GetCategory returns the category of the flag - -func (f *Uint64Flag) GetDefaultText() string - GetDefaultText returns the default text for this flag - -func (f *Uint64Flag) GetEnvVars() []string - GetEnvVars returns the env vars for this flag - -func (f *Uint64Flag) GetUsage() string - GetUsage returns the usage string for the flag +type Uint64Flag = flagImpl[uint64] -func (f *Uint64Flag) GetValue() string - GetValue returns the flags value as string representation and an empty - string if the flag takes no value at all. - -func (f *Uint64Flag) IsRequired() bool - IsRequired returns whether or not the flag is required - -func (f *Uint64Flag) IsSet() bool - IsSet returns whether or not the flag has been set through env or file - -func (f *Uint64Flag) IsVisible() bool - IsVisible returns true if the flag is not hidden, otherwise false - -func (f *Uint64Flag) Names() []string - Names returns the names of the flag - -func (f *Uint64Flag) String() string - String returns a readable representation of this value (for usage defaults) - -func (f *Uint64Flag) TakesValue() bool - TakesValue returns true if the flag takes a value, otherwise false - -type UintFlag struct { - Name string - - Category string - DefaultText string - FilePath string - Usage string - - Required bool - Hidden bool - HasBeenSet bool - - Value uint - Destination *uint - - Aliases []string - EnvVars []string -} - UintFlag is a flag with type uint - -func (f *UintFlag) Apply(set *flag.FlagSet) error - Apply populates the flag given the flag set and environment - -func (f *UintFlag) Get(ctx *Context) uint - Get returns the flag’s value in the given Context. - -func (f *UintFlag) GetCategory() string - GetCategory returns the category of the flag - -func (f *UintFlag) GetDefaultText() string - GetDefaultText returns the default text for this flag - -func (f *UintFlag) GetEnvVars() []string - GetEnvVars returns the env vars for this flag - -func (f *UintFlag) GetUsage() string - GetUsage returns the usage string for the flag - -func (f *UintFlag) GetValue() string - GetValue returns the flags value as string representation and an empty - string if the flag takes no value at all. - -func (f *UintFlag) IsRequired() bool - IsRequired returns whether or not the flag is required - -func (f *UintFlag) IsSet() bool - IsSet returns whether or not the flag has been set through env or file - -func (f *UintFlag) IsVisible() bool - IsVisible returns true if the flag is not hidden, otherwise false - -func (f *UintFlag) Names() []string - Names returns the names of the flag - -func (f *UintFlag) String() string - String returns a readable representation of this value (for usage defaults) - -func (f *UintFlag) TakesValue() bool - TakesValue returns true if the flag takes a value, otherwise false +type UintFlag = flagImpl[uint] type VisibleFlagCategory interface { // Name returns the category name string diff --git a/testdata/godoc-v2.x.txt b/testdata/godoc-v2.x.txt index 1ba48cc659..5e283df5ff 100644 --- a/testdata/godoc-v2.x.txt +++ b/testdata/godoc-v2.x.txt @@ -64,8 +64,8 @@ GLOBAL OPTIONS: COPYRIGHT: {{wrap .Copyright 3}}{{end}} ` - AppHelpTemplate is the text template for the Default help topic. cli.go uses - text/template to render templates. You can render custom help text by + AppHelpTemplate is the text template for the Default help topic. cli.go + uses text/template to render templates. You can render custom help text by setting this variable. var CommandHelpTemplate = `NAME: @@ -201,9 +201,9 @@ func DefaultAppComplete(cCtx *Context) func DefaultCompleteWithFlags(cmd *Command) func(cCtx *Context) func FlagNames(name string, aliases []string) []string func HandleAction(action interface{}, cCtx *Context) (err error) - HandleAction attempts to figure out which Action signature was used. If it's - an ActionFunc or a func with the legacy signature for Action, the func is - run! + HandleAction attempts to figure out which Action signature was used. + If it's an ActionFunc or a func with the legacy signature for Action, + the func is run! func HandleExitCoder(err error) HandleExitCoder handles errors implementing ExitCoder by printing their @@ -360,14 +360,14 @@ func (a *App) RunAsSubcommand(ctx *Context) (err error) to generate command-specific flags func (a *App) RunContext(ctx context.Context, arguments []string) (err error) - RunContext is like Run except it takes a Context that will be passed to its - commands and sub-commands. Through this, you can propagate timeouts and + RunContext is like Run except it takes a Context that will be passed to + its commands and sub-commands. Through this, you can propagate timeouts and cancellation requests func (a *App) Setup() - Setup runs initialization code to ensure all data structures are ready for - `Run` or inspection prior to `Run`. It is internally called by `Run`, but - will return early if setup has already happened. + Setup runs initialization code to ensure all data structures are ready + for `Run` or inspection prior to `Run`. It is internally called by `Run`, + but will return early if setup has already happened. func (a *App) ToFishCompletion() (string, error) ToFishCompletion creates a fish completion string for the `*App` The @@ -460,7 +460,7 @@ func (f *BoolFlag) Get(ctx *Context) bool Get returns the flag’s value in the given Context. func (f *BoolFlag) GetCategory() string - GetCategory returns the category for the flag + GetCategory returns the category of the flag func (f *BoolFlag) GetDefaultText() string GetDefaultText returns the default text for this flag @@ -491,15 +491,7 @@ func (f *BoolFlag) String() string String returns a readable representation of this value (for usage defaults) func (f *BoolFlag) TakesValue() bool - TakesValue returns true of the flag takes a value, otherwise false - -type CategorizableFlag interface { - VisibleFlag - - GetCategory() string -} - CategorizableFlag is an interface that allows us to potentially use a flag - in a categorized representation. + TakesValue returns true if the flag takes a value, otherwise false type Command struct { // The name of the command @@ -637,7 +629,7 @@ func (cCtx *Context) FlagNames() []string its parent contexts. func (cCtx *Context) Float64(name string) float64 - Float64 looks up the value of a local Float64Flag, returns 0 if not found + Int looks up the value of a local IntFlag, returns 0 if not found func (cCtx *Context) Float64Slice(name string) []float64 Float64Slice looks up the value of a local Float64SliceFlag, returns nil if @@ -693,36 +685,14 @@ func (cCtx *Context) Timestamp(name string) *time.Time Timestamp gets the timestamp from a flag name func (cCtx *Context) Uint(name string) uint - Uint looks up the value of a local UintFlag, returns 0 if not found + Int looks up the value of a local IntFlag, returns 0 if not found func (cCtx *Context) Uint64(name string) uint64 - Uint64 looks up the value of a local Uint64Flag, returns 0 if not found + Int64 looks up the value of a local Int64Flag, returns 0 if not found func (cCtx *Context) Value(name string) interface{} Value returns the value of the flag corresponding to `name` -type DocGenerationFlag interface { - Flag - - // TakesValue returns true if the flag takes a value, otherwise false - TakesValue() bool - - // GetUsage returns the usage string for the flag - GetUsage() string - - // GetValue returns the flags value as string representation and an empty - // string if the flag takes no value at all. - GetValue() string - - // GetDefaultText returns the default text for this flag - GetDefaultText() string - - // GetEnvVars returns the env vars for this flag - GetEnvVars() []string -} - DocGenerationFlag is an interface that allows documentation generation for - the flag - type DurationFlag struct { Name string @@ -750,7 +720,7 @@ func (f *DurationFlag) Get(ctx *Context) time.Duration Get returns the flag’s value in the given Context. func (f *DurationFlag) GetCategory() string - GetCategory returns the category for the flag + GetCategory returns the category of the flag func (f *DurationFlag) GetDefaultText() string GetDefaultText returns the default text for this flag @@ -781,7 +751,7 @@ func (f *DurationFlag) String() string String returns a readable representation of this value (for usage defaults) func (f *DurationFlag) TakesValue() bool - TakesValue returns true of the flag takes a value, otherwise false + TakesValue returns true if the flag takes a value, otherwise false type ErrorFormatter interface { Format(s fmt.State, verb rune) @@ -799,9 +769,9 @@ func Exit(message interface{}, exitCode int) ExitCoder Exit wraps a message and exit code into an error, which by default is handled with a call to os.Exit during default error handling. - This is the simplest way to trigger a non-zero exit code for an App without - having to call os.Exit manually. During testing, this behavior can be - avoided by overiding the ExitErrHandler function on an App or the + This is the simplest way to trigger a non-zero exit code for an App + without having to call os.Exit manually. During testing, this behavior + can be avoided by overiding the ExitErrHandler function on an App or the package-global OsExiter function. func NewExitError(message interface{}, exitCode int) ExitCoder @@ -816,10 +786,40 @@ type ExitErrHandlerFunc func(cCtx *Context, err error) type Flag interface { fmt.Stringer + // Apply Flag settings to the given flag set Apply(*flag.FlagSet) error + + // All possible names for this flag Names() []string + + // Whether the flag has been set or not IsSet() bool + + // whether the flag is a required flag or not + IsRequired() bool + + // IsVisible returns true if the flag is not hidden, otherwise false + IsVisible() bool + + // Returns the category of the flag + GetCategory() string + + // GetUsage returns the usage string for the flag + GetUsage() string + + // GetEnvVars returns the env vars for this flag + GetEnvVars() []string + + // TakesValue returns true if the flag takes a value, otherwise false + TakesValue() bool + + // GetDefaultText returns the default text for this flag + GetDefaultText() string + + // GetValue returns the flags value as string representation and an empty + // string if the flag takes no value at all. + GetValue() string } Flag is a common interface related to parsing flags in cli. For more advanced flag parsing techniques, it is recommended that this interface be @@ -896,65 +896,7 @@ func (f FlagsByName) Less(i, j int) bool func (f FlagsByName) Swap(i, j int) -type Float64Flag struct { - Name string - - Category string - DefaultText string - FilePath string - Usage string - - Required bool - Hidden bool - HasBeenSet bool - - Value float64 - Destination *float64 - - Aliases []string - EnvVars []string -} - Float64Flag is a flag with type float64 - -func (f *Float64Flag) Apply(set *flag.FlagSet) error - Apply populates the flag given the flag set and environment - -func (f *Float64Flag) Get(ctx *Context) float64 - Get returns the flag’s value in the given Context. - -func (f *Float64Flag) GetCategory() string - GetCategory returns the category for the flag - -func (f *Float64Flag) GetDefaultText() string - GetDefaultText returns the default text for this flag - -func (f *Float64Flag) GetEnvVars() []string - GetEnvVars returns the env vars for this flag - -func (f *Float64Flag) GetUsage() string - GetUsage returns the usage string for the flag - -func (f *Float64Flag) GetValue() string - GetValue returns the flags value as string representation and an empty - string if the flag takes no value at all. - -func (f *Float64Flag) IsRequired() bool - IsRequired returns whether or not the flag is required - -func (f *Float64Flag) IsSet() bool - IsSet returns whether or not the flag has been set through env or file - -func (f *Float64Flag) IsVisible() bool - IsVisible returns true if the flag is not hidden, otherwise false - -func (f *Float64Flag) Names() []string - Names returns the names of the flag - -func (f *Float64Flag) String() string - String returns a readable representation of this value (for usage defaults) - -func (f *Float64Flag) TakesValue() bool - TakesValue returns true of the flag takes a value, otherwise false +type Float64Flag = flagImpl[float64] type Float64Slice struct { // Has unexported fields. @@ -1006,7 +948,7 @@ func (f *Float64SliceFlag) Get(ctx *Context) []float64 Get returns the flag’s value in the given Context. func (f *Float64SliceFlag) GetCategory() string - GetCategory returns the category for the flag + GetCategory returns the category of the flag func (f *Float64SliceFlag) GetDefaultText() string GetDefaultText returns the default text for this flag @@ -1081,7 +1023,7 @@ func (f *GenericFlag) Get(ctx *Context) interface{} Get returns the flag’s value in the given Context. func (f *GenericFlag) GetCategory() string - GetCategory returns the category for the flag + GetCategory returns the category of the flag func (f *GenericFlag) GetDefaultText() string GetDefaultText returns the default text for this flag @@ -1112,67 +1054,9 @@ func (f *GenericFlag) String() string String returns a readable representation of this value (for usage defaults) func (f *GenericFlag) TakesValue() bool - TakesValue returns true of the flag takes a value, otherwise false - -type Int64Flag struct { - Name string - - Category string - DefaultText string - FilePath string - Usage string - - Required bool - Hidden bool - HasBeenSet bool - - Value int64 - Destination *int64 - - Aliases []string - EnvVars []string -} - Int64Flag is a flag with type int64 - -func (f *Int64Flag) Apply(set *flag.FlagSet) error - Apply populates the flag given the flag set and environment - -func (f *Int64Flag) Get(ctx *Context) int64 - Get returns the flag’s value in the given Context. - -func (f *Int64Flag) GetCategory() string - GetCategory returns the category for the flag - -func (f *Int64Flag) GetDefaultText() string - GetDefaultText returns the default text for this flag - -func (f *Int64Flag) GetEnvVars() []string - GetEnvVars returns the env vars for this flag - -func (f *Int64Flag) GetUsage() string - GetUsage returns the usage string for the flag - -func (f *Int64Flag) GetValue() string - GetValue returns the flags value as string representation and an empty - string if the flag takes no value at all. - -func (f *Int64Flag) IsRequired() bool - IsRequired returns whether or not the flag is required - -func (f *Int64Flag) IsSet() bool - IsSet returns whether or not the flag has been set through env or file - -func (f *Int64Flag) IsVisible() bool - IsVisible returns true if the flag is not hidden, otherwise false - -func (f *Int64Flag) Names() []string - Names returns the names of the flag - -func (f *Int64Flag) String() string - String returns a readable representation of this value (for usage defaults) + TakesValue returns true if the flag takes a value, otherwise false -func (f *Int64Flag) TakesValue() bool - TakesValue returns true of the flag takes a value, otherwise false +type Int64Flag = flagImpl[int64] type Int64Slice struct { // Has unexported fields. @@ -1224,7 +1108,7 @@ func (f *Int64SliceFlag) Get(ctx *Context) []int64 Get returns the flag’s value in the given Context. func (f *Int64SliceFlag) GetCategory() string - GetCategory returns the category for the flag + GetCategory returns the category of the flag func (f *Int64SliceFlag) GetDefaultText() string GetDefaultText returns the default text for this flag @@ -1261,67 +1145,9 @@ func (f *Int64SliceFlag) String() string String returns a readable representation of this value (for usage defaults) func (f *Int64SliceFlag) TakesValue() bool - TakesValue returns true of the flag takes a value, otherwise false - -type IntFlag struct { - Name string - - Category string - DefaultText string - FilePath string - Usage string - - Required bool - Hidden bool - HasBeenSet bool - - Value int - Destination *int - - Aliases []string - EnvVars []string -} - IntFlag is a flag with type int - -func (f *IntFlag) Apply(set *flag.FlagSet) error - Apply populates the flag given the flag set and environment - -func (f *IntFlag) Get(ctx *Context) int - Get returns the flag’s value in the given Context. - -func (f *IntFlag) GetCategory() string - GetCategory returns the category for the flag - -func (f *IntFlag) GetDefaultText() string - GetDefaultText returns the default text for this flag - -func (f *IntFlag) GetEnvVars() []string - GetEnvVars returns the env vars for this flag - -func (f *IntFlag) GetUsage() string - GetUsage returns the usage string for the flag - -func (f *IntFlag) GetValue() string - GetValue returns the flags value as string representation and an empty - string if the flag takes no value at all. - -func (f *IntFlag) IsRequired() bool - IsRequired returns whether or not the flag is required - -func (f *IntFlag) IsSet() bool - IsSet returns whether or not the flag has been set through env or file - -func (f *IntFlag) IsVisible() bool - IsVisible returns true if the flag is not hidden, otherwise false - -func (f *IntFlag) Names() []string - Names returns the names of the flag - -func (f *IntFlag) String() string - String returns a readable representation of this value (for usage defaults) + TakesValue returns true if the flag takes a value, otherwise false -func (f *IntFlag) TakesValue() bool - TakesValue returns true of the flag takes a value, otherwise false +type IntFlag = flagImpl[int] type IntSlice struct { // Has unexported fields. @@ -1377,7 +1203,7 @@ func (f *IntSliceFlag) Get(ctx *Context) []int Get returns the flag’s value in the given Context. func (f *IntSliceFlag) GetCategory() string - GetCategory returns the category for the flag + GetCategory returns the category of the flag func (f *IntSliceFlag) GetDefaultText() string GetDefaultText returns the default text for this flag @@ -1414,7 +1240,7 @@ func (f *IntSliceFlag) String() string String returns a readable representation of this value (for usage defaults) func (f *IntSliceFlag) TakesValue() bool - TakesValue returns true of the flag takes a value, otherwise false + TakesValue returns true if the flag takes a value, otherwise false type MultiError interface { error @@ -1431,8 +1257,8 @@ type MultiInt64Flag = SliceFlag[*Int64SliceFlag, []int64, int64] directly, as Value and/or Destination. See also SliceFlag. type MultiIntFlag = SliceFlag[*IntSliceFlag, []int, int] - MultiIntFlag extends IntSliceFlag with support for using slices directly, as - Value and/or Destination. See also SliceFlag. + MultiIntFlag extends IntSliceFlag with support for using slices directly, + as Value and/or Destination. See also SliceFlag. type MultiStringFlag = SliceFlag[*StringSliceFlag, []string, string] MultiStringFlag extends StringSliceFlag with support for using slices @@ -1475,7 +1301,7 @@ func (f *PathFlag) Get(ctx *Context) string Get returns the flag’s value in the given Context. func (f *PathFlag) GetCategory() string - GetCategory returns the category for the flag + GetCategory returns the category of the flag func (f *PathFlag) GetDefaultText() string GetDefaultText returns the default text for this flag @@ -1506,16 +1332,7 @@ func (f *PathFlag) String() string String returns a readable representation of this value (for usage defaults) func (f *PathFlag) TakesValue() bool - TakesValue returns true of the flag takes a value, otherwise false - -type RequiredFlag interface { - Flag - - IsRequired() bool -} - RequiredFlag is an interface that allows us to mark flags as required it - allows flags required flags to be backwards compatible with the Flag - interface + TakesValue returns true if the flag takes a value, otherwise false type Serializer interface { Serialize() string @@ -1527,9 +1344,9 @@ type SliceFlag[T SliceFlagTarget[E], S ~[]E, E any] struct { Value S Destination *S } - SliceFlag extends implementations like StringSliceFlag and IntSliceFlag with - support for using slices directly, as Value and/or Destination. See also - SliceFlagTarget, MultiStringFlag, MultiFloat64Flag, MultiInt64Flag, + SliceFlag extends implementations like StringSliceFlag and IntSliceFlag + with support for using slices directly, as Value and/or Destination. + See also SliceFlagTarget, MultiStringFlag, MultiFloat64Flag, MultiInt64Flag, MultiIntFlag. func (x *SliceFlag[T, S, E]) Apply(set *flag.FlagSet) error @@ -1564,10 +1381,6 @@ func (x *SliceFlag[T, S, E]) TakesValue() bool type SliceFlagTarget[E any] interface { Flag - RequiredFlag - DocGenerationFlag - VisibleFlag - CategorizableFlag // SetValue should propagate the given slice to the target, ideally as a new value. // Note that a nil slice should nil/clear any existing value (modelled as ~[]E). @@ -1603,6 +1416,176 @@ type StringFlag struct { TakesFile bool } + IntFlag is a flag with type int + + type IntFlag struct { + Name string + + Category string + DefaultText string + FilePath string + Usage string + + Required bool + Hidden bool + HasBeenSet bool + + Value int + Destination *int + + Aliases []string + EnvVars []string + } + + // String returns a readable representation of this value (for usage + defaults) + + func (f *IntFlag) String() string { + return FlagStringer(f) + } + + // IsSet returns whether or not the flag has been set through env or file + + func (f *IntFlag) IsSet() bool { + return f.HasBeenSet + } + + // Names returns the names of the flag + + func (f *IntFlag) Names() []string { + return FlagNames(f.Name, f.Aliases) + } + + // IsRequired returns whether or not the flag is required + + func (f *IntFlag) IsRequired() bool { + return f.Required + } + + // IsVisible returns true if the flag is not hidden, otherwise false + + func (f *IntFlag) IsVisible() bool { + return !f.Hidden + } + + // GetCategory returns the category of the flag + + func (f *IntFlag) GetCategory() string { + return f.Category + } + + // GetUsage returns the usage string for the flag + + func (f *IntFlag) GetUsage() string { + return f.Usage + } + + // GetEnvVars returns the env vars for this flag + + func (f *IntFlag) GetEnvVars() []string { + return f.EnvVars + } + + // TakesValue returns true if the flag takes a value, otherwise false + + func (f *IntFlag) TakesValue() bool { + return "IntFlag" != "BoolFlag" + } + + // GetDefaultText returns the default text for this flag + + func (f *IntFlag) GetDefaultText() string { + if f.DefaultText != "" { + return f.DefaultText + } + return f.GetValue() + } + + // Int64Flag is a flag with type int64 + + type Int64Flag struct { + Name string + + Category string + DefaultText string + FilePath string + Usage string + + Required bool + Hidden bool + HasBeenSet bool + + Value int64 + Destination *int64 + + Aliases []string + EnvVars []string + } + + // String returns a readable representation of this value (for usage + defaults) + + func (f *Int64Flag) String() string { + return FlagStringer(f) + } + + // IsSet returns whether or not the flag has been set through env or file + + func (f *Int64Flag) IsSet() bool { + return f.HasBeenSet + } + + // Names returns the names of the flag + + func (f *Int64Flag) Names() []string { + return FlagNames(f.Name, f.Aliases) + } + + // IsRequired returns whether or not the flag is required + + func (f *Int64Flag) IsRequired() bool { + return f.Required + } + + // IsVisible returns true if the flag is not hidden, otherwise false + + func (f *Int64Flag) IsVisible() bool { + return !f.Hidden + } + + // GetCategory returns the category of the flag + + func (f *Int64Flag) GetCategory() string { + return f.Category + } + + // GetUsage returns the usage string for the flag + + func (f *Int64Flag) GetUsage() string { + return f.Usage + } + + // GetEnvVars returns the env vars for this flag + + func (f *Int64Flag) GetEnvVars() []string { + return f.EnvVars + } + + // TakesValue returns true if the flag takes a value, otherwise false + + func (f *Int64Flag) TakesValue() bool { + return "Int64Flag" != "BoolFlag" + } + + // GetDefaultText returns the default text for this flag + + func (f *Int64Flag) GetDefaultText() string { + if f.DefaultText != "" { + return f.DefaultText + } + return f.GetValue() + } + StringFlag is a flag with type string func (f *StringFlag) Apply(set *flag.FlagSet) error @@ -1612,7 +1595,7 @@ func (f *StringFlag) Get(ctx *Context) string Get returns the flag’s value in the given Context. func (f *StringFlag) GetCategory() string - GetCategory returns the category for the flag + GetCategory returns the category of the flag func (f *StringFlag) GetDefaultText() string GetDefaultText returns the default text for this flag @@ -1643,7 +1626,7 @@ func (f *StringFlag) String() string String returns a readable representation of this value (for usage defaults) func (f *StringFlag) TakesValue() bool - TakesValue returns true of the flag takes a value, otherwise false + TakesValue returns true if the flag takes a value, otherwise false type StringSlice struct { // Has unexported fields. @@ -1697,7 +1680,7 @@ func (f *StringSliceFlag) Get(ctx *Context) []string Get returns the flag’s value in the given Context. func (f *StringSliceFlag) GetCategory() string - GetCategory returns the category for the flag + GetCategory returns the category of the flag func (f *StringSliceFlag) GetDefaultText() string GetDefaultText returns the default text for this flag @@ -1734,7 +1717,7 @@ func (f *StringSliceFlag) String() string String returns a readable representation of this value (for usage defaults) func (f *StringSliceFlag) TakesValue() bool - TakesValue returns true of the flag takes a value, otherwise false + TakesValue returns true if the flag takes a value, otherwise false type SuggestCommandFunc func(commands []*Command, provided string) string @@ -1800,7 +1783,7 @@ func (f *TimestampFlag) Get(ctx *Context) *time.Time Get returns the flag’s value in the given Context. func (f *TimestampFlag) GetCategory() string - GetCategory returns the category for the flag + GetCategory returns the category of the flag func (f *TimestampFlag) GetDefaultText() string GetDefaultText returns the default text for this flag @@ -1831,141 +1814,17 @@ func (f *TimestampFlag) String() string String returns a readable representation of this value (for usage defaults) func (f *TimestampFlag) TakesValue() bool - TakesValue returns true of the flag takes a value, otherwise false - -type Uint64Flag struct { - Name string - - Category string - DefaultText string - FilePath string - Usage string - - Required bool - Hidden bool - HasBeenSet bool - - Value uint64 - Destination *uint64 - - Aliases []string - EnvVars []string -} - Uint64Flag is a flag with type uint64 - -func (f *Uint64Flag) Apply(set *flag.FlagSet) error - Apply populates the flag given the flag set and environment - -func (f *Uint64Flag) Get(ctx *Context) uint64 - Get returns the flag’s value in the given Context. - -func (f *Uint64Flag) GetCategory() string - GetCategory returns the category for the flag - -func (f *Uint64Flag) GetDefaultText() string - GetDefaultText returns the default text for this flag - -func (f *Uint64Flag) GetEnvVars() []string - GetEnvVars returns the env vars for this flag - -func (f *Uint64Flag) GetUsage() string - GetUsage returns the usage string for the flag - -func (f *Uint64Flag) GetValue() string - GetValue returns the flags value as string representation and an empty - string if the flag takes no value at all. - -func (f *Uint64Flag) IsRequired() bool - IsRequired returns whether or not the flag is required - -func (f *Uint64Flag) IsSet() bool - IsSet returns whether or not the flag has been set through env or file - -func (f *Uint64Flag) IsVisible() bool - IsVisible returns true if the flag is not hidden, otherwise false - -func (f *Uint64Flag) Names() []string - Names returns the names of the flag - -func (f *Uint64Flag) String() string - String returns a readable representation of this value (for usage defaults) - -func (f *Uint64Flag) TakesValue() bool - TakesValue returns true of the flag takes a value, otherwise false - -type UintFlag struct { - Name string - - Category string - DefaultText string - FilePath string - Usage string - - Required bool - Hidden bool - HasBeenSet bool - - Value uint - Destination *uint - - Aliases []string - EnvVars []string -} - UintFlag is a flag with type uint - -func (f *UintFlag) Apply(set *flag.FlagSet) error - Apply populates the flag given the flag set and environment - -func (f *UintFlag) Get(ctx *Context) uint - Get returns the flag’s value in the given Context. - -func (f *UintFlag) GetCategory() string - GetCategory returns the category for the flag - -func (f *UintFlag) GetDefaultText() string - GetDefaultText returns the default text for this flag - -func (f *UintFlag) GetEnvVars() []string - GetEnvVars returns the env vars for this flag - -func (f *UintFlag) GetUsage() string - GetUsage returns the usage string for the flag - -func (f *UintFlag) GetValue() string - GetValue returns the flags value as string representation and an empty - string if the flag takes no value at all. - -func (f *UintFlag) IsRequired() bool - IsRequired returns whether or not the flag is required - -func (f *UintFlag) IsSet() bool - IsSet returns whether or not the flag has been set through env or file - -func (f *UintFlag) IsVisible() bool - IsVisible returns true if the flag is not hidden, otherwise false - -func (f *UintFlag) Names() []string - Names returns the names of the flag - -func (f *UintFlag) String() string - String returns a readable representation of this value (for usage defaults) - -func (f *UintFlag) TakesValue() bool - TakesValue returns true of the flag takes a value, otherwise false + TakesValue returns true if the flag takes a value, otherwise false -type VisibleFlag interface { - Flag +type Uint64Flag = flagImpl[uint64] - // IsVisible returns true if the flag is not hidden, otherwise false - IsVisible() bool -} - VisibleFlag is an interface that allows to check if a flag is visible +type UintFlag = flagImpl[uint] type VisibleFlagCategory interface { // Name returns the category name string Name() string // Flags returns a slice of VisibleFlag sorted by name - Flags() []VisibleFlag + Flags() []Flag } VisibleFlagCategory is a category containing flags. @@ -1986,9 +1845,9 @@ func InitInputSource(flags []cli.Flag, createInputSource func() (InputSourceCont that are supported by the input source func InitInputSourceWithContext(flags []cli.Flag, createInputSource func(cCtx *cli.Context) (InputSourceContext, error)) cli.BeforeFunc - InitInputSourceWithContext is used to to setup an InputSourceContext on a - cli.Command Before method. It will create a new input source based on the - func provided with potentially using existing cli.Context values to + InitInputSourceWithContext is used to to setup an InputSourceContext on + a cli.Command Before method. It will create a new input source based on + the func provided with potentially using existing cli.Context values to initialize itself. If there is no error it will then apply the new input source to any flags that are supported by the input source diff --git a/zz_generated.flags.go b/zz_generated.flags.go index 685d97d7b2..1b32c60665 100644 --- a/zz_generated.flags.go +++ b/zz_generated.flags.go @@ -562,225 +562,6 @@ func (f *BoolFlag) TakesValue() bool { return "BoolFlag" != "BoolFlag" } -// Float64Flag is a flag with type float64 -type Float64Flag struct { - Name string - - Category string - DefaultText string - FilePath string - Usage string - - Required bool - Hidden bool - HasBeenSet bool - - Value float64 - Destination *float64 - - Aliases []string - EnvVars []string -} - -// String returns a readable representation of this value (for usage defaults) -func (f *Float64Flag) String() string { - return FlagStringer(f) -} - -// IsSet returns whether or not the flag has been set through env or file -func (f *Float64Flag) IsSet() bool { - return f.HasBeenSet -} - -// Names returns the names of the flag -func (f *Float64Flag) Names() []string { - return FlagNames(f.Name, f.Aliases) -} - -// IsRequired returns whether or not the flag is required -func (f *Float64Flag) IsRequired() bool { - return f.Required -} - -// IsVisible returns true if the flag is not hidden, otherwise false -func (f *Float64Flag) IsVisible() bool { - return !f.Hidden -} - -// GetCategory returns the category of the flag -func (f *Float64Flag) GetCategory() string { - return f.Category -} - -// GetUsage returns the usage string for the flag -func (f *Float64Flag) GetUsage() string { - return f.Usage -} - -// GetEnvVars returns the env vars for this flag -func (f *Float64Flag) GetEnvVars() []string { - return f.EnvVars -} - -// TakesValue returns true if the flag takes a value, otherwise false -func (f *Float64Flag) TakesValue() bool { - return "Float64Flag" != "BoolFlag" -} - -// GetDefaultText returns the default text for this flag -func (f *Float64Flag) GetDefaultText() string { - if f.DefaultText != "" { - return f.DefaultText - } - return f.GetValue() -} - -// IntFlag is a flag with type int -type IntFlag struct { - Name string - - Category string - DefaultText string - FilePath string - Usage string - - Required bool - Hidden bool - HasBeenSet bool - - Value int - Destination *int - - Aliases []string - EnvVars []string -} - -// String returns a readable representation of this value (for usage defaults) -func (f *IntFlag) String() string { - return FlagStringer(f) -} - -// IsSet returns whether or not the flag has been set through env or file -func (f *IntFlag) IsSet() bool { - return f.HasBeenSet -} - -// Names returns the names of the flag -func (f *IntFlag) Names() []string { - return FlagNames(f.Name, f.Aliases) -} - -// IsRequired returns whether or not the flag is required -func (f *IntFlag) IsRequired() bool { - return f.Required -} - -// IsVisible returns true if the flag is not hidden, otherwise false -func (f *IntFlag) IsVisible() bool { - return !f.Hidden -} - -// GetCategory returns the category of the flag -func (f *IntFlag) GetCategory() string { - return f.Category -} - -// GetUsage returns the usage string for the flag -func (f *IntFlag) GetUsage() string { - return f.Usage -} - -// GetEnvVars returns the env vars for this flag -func (f *IntFlag) GetEnvVars() []string { - return f.EnvVars -} - -// TakesValue returns true if the flag takes a value, otherwise false -func (f *IntFlag) TakesValue() bool { - return "IntFlag" != "BoolFlag" -} - -// GetDefaultText returns the default text for this flag -func (f *IntFlag) GetDefaultText() string { - if f.DefaultText != "" { - return f.DefaultText - } - return f.GetValue() -} - -// Int64Flag is a flag with type int64 -type Int64Flag struct { - Name string - - Category string - DefaultText string - FilePath string - Usage string - - Required bool - Hidden bool - HasBeenSet bool - - Value int64 - Destination *int64 - - Aliases []string - EnvVars []string -} - -// String returns a readable representation of this value (for usage defaults) -func (f *Int64Flag) String() string { - return FlagStringer(f) -} - -// IsSet returns whether or not the flag has been set through env or file -func (f *Int64Flag) IsSet() bool { - return f.HasBeenSet -} - -// Names returns the names of the flag -func (f *Int64Flag) Names() []string { - return FlagNames(f.Name, f.Aliases) -} - -// IsRequired returns whether or not the flag is required -func (f *Int64Flag) IsRequired() bool { - return f.Required -} - -// IsVisible returns true if the flag is not hidden, otherwise false -func (f *Int64Flag) IsVisible() bool { - return !f.Hidden -} - -// GetCategory returns the category of the flag -func (f *Int64Flag) GetCategory() string { - return f.Category -} - -// GetUsage returns the usage string for the flag -func (f *Int64Flag) GetUsage() string { - return f.Usage -} - -// GetEnvVars returns the env vars for this flag -func (f *Int64Flag) GetEnvVars() []string { - return f.EnvVars -} - -// TakesValue returns true if the flag takes a value, otherwise false -func (f *Int64Flag) TakesValue() bool { - return "Int64Flag" != "BoolFlag" -} - -// GetDefaultText returns the default text for this flag -func (f *Int64Flag) GetDefaultText() string { - if f.DefaultText != "" { - return f.DefaultText - } - return f.GetValue() -} - // StringFlag is a flag with type string type StringFlag struct { Name string @@ -921,150 +702,4 @@ func (f *DurationFlag) GetDefaultText() string { return f.GetValue() } -// UintFlag is a flag with type uint -type UintFlag struct { - Name string - - Category string - DefaultText string - FilePath string - Usage string - - Required bool - Hidden bool - HasBeenSet bool - - Value uint - Destination *uint - - Aliases []string - EnvVars []string -} - -// String returns a readable representation of this value (for usage defaults) -func (f *UintFlag) String() string { - return FlagStringer(f) -} - -// IsSet returns whether or not the flag has been set through env or file -func (f *UintFlag) IsSet() bool { - return f.HasBeenSet -} - -// Names returns the names of the flag -func (f *UintFlag) Names() []string { - return FlagNames(f.Name, f.Aliases) -} - -// IsRequired returns whether or not the flag is required -func (f *UintFlag) IsRequired() bool { - return f.Required -} - -// IsVisible returns true if the flag is not hidden, otherwise false -func (f *UintFlag) IsVisible() bool { - return !f.Hidden -} - -// GetCategory returns the category of the flag -func (f *UintFlag) GetCategory() string { - return f.Category -} - -// GetUsage returns the usage string for the flag -func (f *UintFlag) GetUsage() string { - return f.Usage -} - -// GetEnvVars returns the env vars for this flag -func (f *UintFlag) GetEnvVars() []string { - return f.EnvVars -} - -// TakesValue returns true if the flag takes a value, otherwise false -func (f *UintFlag) TakesValue() bool { - return "UintFlag" != "BoolFlag" -} - -// GetDefaultText returns the default text for this flag -func (f *UintFlag) GetDefaultText() string { - if f.DefaultText != "" { - return f.DefaultText - } - return f.GetValue() -} - -// Uint64Flag is a flag with type uint64 -type Uint64Flag struct { - Name string - - Category string - DefaultText string - FilePath string - Usage string - - Required bool - Hidden bool - HasBeenSet bool - - Value uint64 - Destination *uint64 - - Aliases []string - EnvVars []string -} - -// String returns a readable representation of this value (for usage defaults) -func (f *Uint64Flag) String() string { - return FlagStringer(f) -} - -// IsSet returns whether or not the flag has been set through env or file -func (f *Uint64Flag) IsSet() bool { - return f.HasBeenSet -} - -// Names returns the names of the flag -func (f *Uint64Flag) Names() []string { - return FlagNames(f.Name, f.Aliases) -} - -// IsRequired returns whether or not the flag is required -func (f *Uint64Flag) IsRequired() bool { - return f.Required -} - -// IsVisible returns true if the flag is not hidden, otherwise false -func (f *Uint64Flag) IsVisible() bool { - return !f.Hidden -} - -// GetCategory returns the category of the flag -func (f *Uint64Flag) GetCategory() string { - return f.Category -} - -// GetUsage returns the usage string for the flag -func (f *Uint64Flag) GetUsage() string { - return f.Usage -} - -// GetEnvVars returns the env vars for this flag -func (f *Uint64Flag) GetEnvVars() []string { - return f.EnvVars -} - -// TakesValue returns true if the flag takes a value, otherwise false -func (f *Uint64Flag) TakesValue() bool { - return "Uint64Flag" != "BoolFlag" -} - -// GetDefaultText returns the default text for this flag -func (f *Uint64Flag) GetDefaultText() string { - if f.DefaultText != "" { - return f.DefaultText - } - return f.GetValue() -} - // vim:ro diff --git a/zz_generated.flags_test.go b/zz_generated.flags_test.go index 16519e62aa..fef840ddf2 100644 --- a/zz_generated.flags_test.go +++ b/zz_generated.flags_test.go @@ -185,81 +185,6 @@ func TestBoolFlag_SatisfiesFmtStringerInterface(t *testing.T) { _ = f.String() } -func TestFloat64Flag_SatisfiesFlagInterface(t *testing.T) { - var f cli.Flag = &cli.Float64Flag{} - - _ = f.IsSet() - _ = f.Names() -} - -func TestFloat64Flag_SatisfiesRequiredFlagInterface(t *testing.T) { - var f cli.Flag = &cli.Float64Flag{} - - _ = f.IsRequired() -} - -func TestFloat64Flag_SatisfiesVisibleFlagInterface(t *testing.T) { - var f cli.Flag = &cli.Float64Flag{} - - _ = f.IsVisible() -} - -func TestFloat64Flag_SatisfiesFmtStringerInterface(t *testing.T) { - var f fmt.Stringer = &cli.Float64Flag{} - - _ = f.String() -} - -func TestIntFlag_SatisfiesFlagInterface(t *testing.T) { - var f cli.Flag = &cli.IntFlag{} - - _ = f.IsSet() - _ = f.Names() -} - -func TestIntFlag_SatisfiesRequiredFlagInterface(t *testing.T) { - var f cli.Flag = &cli.IntFlag{} - - _ = f.IsRequired() -} - -func TestIntFlag_SatisfiesVisibleFlagInterface(t *testing.T) { - var f cli.Flag = &cli.IntFlag{} - - _ = f.IsVisible() -} - -func TestIntFlag_SatisfiesFmtStringerInterface(t *testing.T) { - var f fmt.Stringer = &cli.IntFlag{} - - _ = f.String() -} - -func TestInt64Flag_SatisfiesFlagInterface(t *testing.T) { - var f cli.Flag = &cli.Int64Flag{} - - _ = f.IsSet() - _ = f.Names() -} - -func TestInt64Flag_SatisfiesRequiredFlagInterface(t *testing.T) { - var f cli.Flag = &cli.Int64Flag{} - - _ = f.IsRequired() -} - -func TestInt64Flag_SatisfiesVisibleFlagInterface(t *testing.T) { - var f cli.Flag = &cli.Int64Flag{} - - _ = f.IsVisible() -} - -func TestInt64Flag_SatisfiesFmtStringerInterface(t *testing.T) { - var f fmt.Stringer = &cli.Int64Flag{} - - _ = f.String() -} - func TestStringFlag_SatisfiesFlagInterface(t *testing.T) { var f cli.Flag = &cli.StringFlag{} @@ -310,54 +235,4 @@ func TestDurationFlag_SatisfiesFmtStringerInterface(t *testing.T) { _ = f.String() } -func TestUintFlag_SatisfiesFlagInterface(t *testing.T) { - var f cli.Flag = &cli.UintFlag{} - - _ = f.IsSet() - _ = f.Names() -} - -func TestUintFlag_SatisfiesRequiredFlagInterface(t *testing.T) { - var f cli.Flag = &cli.UintFlag{} - - _ = f.IsRequired() -} - -func TestUintFlag_SatisfiesVisibleFlagInterface(t *testing.T) { - var f cli.Flag = &cli.UintFlag{} - - _ = f.IsVisible() -} - -func TestUintFlag_SatisfiesFmtStringerInterface(t *testing.T) { - var f fmt.Stringer = &cli.UintFlag{} - - _ = f.String() -} - -func TestUint64Flag_SatisfiesFlagInterface(t *testing.T) { - var f cli.Flag = &cli.Uint64Flag{} - - _ = f.IsSet() - _ = f.Names() -} - -func TestUint64Flag_SatisfiesRequiredFlagInterface(t *testing.T) { - var f cli.Flag = &cli.Uint64Flag{} - - _ = f.IsRequired() -} - -func TestUint64Flag_SatisfiesVisibleFlagInterface(t *testing.T) { - var f cli.Flag = &cli.Uint64Flag{} - - _ = f.IsVisible() -} - -func TestUint64Flag_SatisfiesFmtStringerInterface(t *testing.T) { - var f fmt.Stringer = &cli.Uint64Flag{} - - _ = f.String() -} - // vim:ro