diff --git a/.github/workflows/cli.yml b/.github/workflows/cli.yml index ef5195c241..5c8db7a668 100644 --- a/.github/workflows/cli.yml +++ b/.github/workflows/cli.yml @@ -3,11 +3,14 @@ on: push: branches: - main + - v3-dev-main tags: - v2.* + - v3.* pull_request: branches: - main + - v3-dev-main permissions: contents: read jobs: @@ -15,7 +18,7 @@ jobs: strategy: matrix: os: [ubuntu-latest, macos-latest, windows-latest] - go: [1.17.x, 1.18.x, 1.19.x] + go: [1.18.x, 1.19.x] name: ${{ matrix.os }} @ Go ${{ matrix.go }} runs-on: ${{ matrix.os }} steps: @@ -43,13 +46,17 @@ jobs: - if: matrix.go == '1.19.x' && matrix.os == 'ubuntu-latest' run: make generate - run: make diffcheck - - if: matrix.go == '1.19.x' && matrix.os == 'ubuntu-latest' + # TODO: switch once v3 is released {{ + # - if: matrix.go == '1.19.x' && matrix.os == 'ubuntu-latest' + - if: 'false' run: make v2diff + # }} - if: success() && matrix.go == '1.19.x' && matrix.os == 'ubuntu-latest' uses: codecov/codecov-action@v3 with: token: ${{ secrets.CODECOV_TOKEN }} fail_ci_if_error: true + test-docs: name: test-docs runs-on: ubuntu-latest @@ -66,12 +73,15 @@ jobs: - run: make ensure-gfmrun - run: make gfmrun env: - FLAGS: --walk docs/v2/ + FLAGS: --walk docs/v3/ - run: make diffcheck publish: permissions: contents: write - if: startswith(github.ref, 'refs/tags/') + # TODO: switch once v3 is released {{ + # if: startswith(github.ref, 'refs/tags/') + if: 'false' + # }} name: publish needs: [test-docs] runs-on: ubuntu-latest diff --git a/.gitignore b/.gitignore index d7d26b1fca..3c6768f8c9 100644 --- a/.gitignore +++ b/.gitignore @@ -5,9 +5,8 @@ .envrc .idea /.local/ +/cmd/urfave-cli-genflags/urfave-cli-genflags /site/ coverage.txt internal/*/built-example vendor -/cmd/urfave-cli-genflags/urfave-cli-genflags -*.exe diff --git a/Makefile b/Makefile index f0d41905ea..a167052506 100644 --- a/Makefile +++ b/Makefile @@ -7,7 +7,7 @@ GO_RUN_BUILD := go run internal/build/build.go .PHONY: all -all: generate vet test check-binary-size gfmrun yamlfmt v2diff +all: generate vet test check-binary-size gfmrun yamlfmt # NOTE: this is a special catch-all rule to run any of the commands # defined in internal/build/build.go with optional arguments passed diff --git a/README.md b/README.md index eaed356307..3ac693bdb0 100644 --- a/README.md +++ b/README.md @@ -1,6 +1,6 @@ # cli -[![GoDoc](https://godoc.org/github.com/urfave/cli?status.svg)](https://pkg.go.dev/github.com/urfave/cli/v2) +[![GoDoc](https://godoc.org/github.com/urfave/cli?status.svg)](https://pkg.go.dev/github.com/urfave/cli/v3) [![codebeat](https://codebeat.co/badges/0a8f30aa-f975-404b-b878-5fab3ae1cc5f)](https://codebeat.co/projects/github-com-urfave-cli) [![Go Report Card](https://goreportcard.com/badge/urfave/cli)](https://goreportcard.com/report/urfave/cli) [![codecov](https://codecov.io/gh/urfave/cli/branch/main/graph/badge.svg)](https://codecov.io/gh/urfave/cli) diff --git a/altsrc/flag.go b/altsrc/flag.go index d8256d7605..50ebd9e368 100644 --- a/altsrc/flag.go +++ b/altsrc/flag.go @@ -6,7 +6,7 @@ import ( "strconv" "syscall" - "github.com/urfave/cli/v2" + "github.com/urfave/cli/v3" ) // FlagInputSourceExtension is an extension interface of cli.Flag that diff --git a/altsrc/flag_generated.go b/altsrc/flag_generated.go index 9490417e47..2a521d1988 100644 --- a/altsrc/flag_generated.go +++ b/altsrc/flag_generated.go @@ -5,7 +5,7 @@ package altsrc import ( "flag" - "github.com/urfave/cli/v2" + "github.com/urfave/cli/v3" ) // BoolFlag is the flag type that wraps cli.BoolFlag to allow diff --git a/altsrc/flag_test.go b/altsrc/flag_test.go index ad66dab43c..7f85d7401d 100644 --- a/altsrc/flag_test.go +++ b/altsrc/flag_test.go @@ -10,7 +10,7 @@ import ( "testing" "time" - "github.com/urfave/cli/v2" + "github.com/urfave/cli/v3" ) type testApplyInputSource struct { diff --git a/altsrc/input_source_context.go b/altsrc/input_source_context.go index 24579d16a9..4cd8392450 100644 --- a/altsrc/input_source_context.go +++ b/altsrc/input_source_context.go @@ -3,7 +3,7 @@ package altsrc import ( "time" - "github.com/urfave/cli/v2" + "github.com/urfave/cli/v3" ) // InputSourceContext is an interface used to allow diff --git a/altsrc/json_command_test.go b/altsrc/json_command_test.go index f2d3a8196d..e39dabc06c 100644 --- a/altsrc/json_command_test.go +++ b/altsrc/json_command_test.go @@ -6,7 +6,7 @@ import ( "os" "testing" - "github.com/urfave/cli/v2" + "github.com/urfave/cli/v3" ) const ( diff --git a/altsrc/json_source_context.go b/altsrc/json_source_context.go index ac0532076c..5589d592a9 100644 --- a/altsrc/json_source_context.go +++ b/altsrc/json_source_context.go @@ -8,7 +8,7 @@ import ( "strings" "time" - "github.com/urfave/cli/v2" + "github.com/urfave/cli/v3" ) // NewJSONSourceFromFlagFunc returns a func that takes a cli.Context diff --git a/altsrc/map_input_source.go b/altsrc/map_input_source.go index 2505b270eb..4bac92c271 100644 --- a/altsrc/map_input_source.go +++ b/altsrc/map_input_source.go @@ -6,7 +6,7 @@ import ( "strings" "time" - "github.com/urfave/cli/v2" + "github.com/urfave/cli/v3" ) // MapInputSource implements InputSourceContext to return diff --git a/altsrc/toml_command_test.go b/altsrc/toml_command_test.go index d6def0efd2..9e52435e45 100644 --- a/altsrc/toml_command_test.go +++ b/altsrc/toml_command_test.go @@ -6,7 +6,7 @@ import ( "os" "testing" - "github.com/urfave/cli/v2" + "github.com/urfave/cli/v3" ) func TestCommandTomFileTest(t *testing.T) { diff --git a/altsrc/toml_file_loader.go b/altsrc/toml_file_loader.go index dfc9b7b1c8..0e614e3468 100644 --- a/altsrc/toml_file_loader.go +++ b/altsrc/toml_file_loader.go @@ -5,7 +5,7 @@ import ( "reflect" "github.com/BurntSushi/toml" - "github.com/urfave/cli/v2" + "github.com/urfave/cli/v3" ) type tomlMap struct { diff --git a/altsrc/yaml_command_test.go b/altsrc/yaml_command_test.go index a297bd2d28..ed67d800f9 100644 --- a/altsrc/yaml_command_test.go +++ b/altsrc/yaml_command_test.go @@ -6,7 +6,7 @@ import ( "os" "testing" - "github.com/urfave/cli/v2" + "github.com/urfave/cli/v3" ) func TestCommandYamlFileTest(t *testing.T) { diff --git a/altsrc/yaml_file_loader.go b/altsrc/yaml_file_loader.go index 62e8965782..b1f6c843f1 100644 --- a/altsrc/yaml_file_loader.go +++ b/altsrc/yaml_file_loader.go @@ -9,7 +9,7 @@ import ( "runtime" "strings" - "github.com/urfave/cli/v2" + "github.com/urfave/cli/v3" "gopkg.in/yaml.v3" ) diff --git a/altsrc/yaml_file_loader_test.go b/altsrc/yaml_file_loader_test.go index 814586b917..37455c6c8c 100644 --- a/altsrc/yaml_file_loader_test.go +++ b/altsrc/yaml_file_loader_test.go @@ -6,8 +6,8 @@ import ( "os" "time" - "github.com/urfave/cli/v2" - "github.com/urfave/cli/v2/altsrc" + "github.com/urfave/cli/v3" + "github.com/urfave/cli/v3/altsrc" ) func ExampleApp_Run_yamlFileLoaderDuration() { diff --git a/app_test.go b/app_test.go index 7091c40ef9..b85848f740 100644 --- a/app_test.go +++ b/app_test.go @@ -2486,6 +2486,26 @@ func (c *customBoolFlag) IsSet() bool { return false } +func (c *customBoolFlag) IsRequired() bool { + return false +} + +func (c *customBoolFlag) IsVisible() bool { + return false +} + +func (c *customBoolFlag) GetCategory() string { + return "" +} + +func (c *customBoolFlag) GetEnvVars() []string { + return nil +} + +func (c *customBoolFlag) GetDefaultText() string { + return "" +} + func TestCustomFlagsUnused(t *testing.T) { app := &App{ Flags: []Flag{&customBoolFlag{"custom"}}, diff --git a/cmd/urfave-cli-genflags/generated.gotmpl b/cmd/urfave-cli-genflags/generated.gotmpl index 3720e6a1b8..6b16829841 100644 --- a/cmd/urfave-cli-genflags/generated.gotmpl +++ b/cmd/urfave-cli-genflags/generated.gotmpl @@ -47,21 +47,38 @@ func (f *{{.TypeName}}) Names() []string { return {{$.UrfaveCLINamespace}}FlagNames(f.Name, f.Aliases) } -{{end}}{{/* /if .GenerateFlagInterface */}} - -{{if .GenerateRequiredFlagInterface}} // IsRequired returns whether or not the flag is required func (f *{{.TypeName}}) IsRequired() bool { return f.Required } -{{end}}{{/* /if .GenerateRequiredFlagInterface */}} -{{if .GenerateVisibleFlagInterface}} // IsVisible returns true if the flag is not hidden, otherwise false func (f *{{.TypeName}}) IsVisible() bool { return !f.Hidden } -{{end}}{{/* /if .GenerateVisibleFlagInterface */}} + +// GetCategory returns the category of the flag +func (f *{{.TypeName}}) GetCategory() string { + return f.Category +} + +// GetUsage returns the usage string for the flag +func (f *{{.TypeName}}) GetUsage() string { + return f.Usage +} + +// GetEnvVars returns the env vars for this flag +func (f *{{.TypeName}}) GetEnvVars() []string { + return f.EnvVars +} + +// TakesValue returns true if the flag takes a value, otherwise false +func (f *{{.TypeName}}) TakesValue() bool { + return "{{.TypeName }}" != "BoolFlag" +} + +{{end}}{{/* /if .GenerateFlagInterface */}} + {{end}}{{/* /range .SortedFlagTypes */}} // vim{{/* 👻 */}}:ro diff --git a/cmd/urfave-cli-genflags/generated_altsrc.gotmpl b/cmd/urfave-cli-genflags/generated_altsrc.gotmpl index 737eb82d17..8fc6d0ea2e 100644 --- a/cmd/urfave-cli-genflags/generated_altsrc.gotmpl +++ b/cmd/urfave-cli-genflags/generated_altsrc.gotmpl @@ -2,11 +2,6 @@ package {{.PackageName}} -import ( - "flag" - "github.com/urfave/cli/v2" -) - {{range .SortedFlagTypes}} // {{.TypeName}} is the flag type that wraps cli.{{.TypeName}} to allow // for other values to be specified diff --git a/cmd/urfave-cli-genflags/generated_test.gotmpl b/cmd/urfave-cli-genflags/generated_test.gotmpl index 52de4e4bf4..83229b06ba 100644 --- a/cmd/urfave-cli-genflags/generated_test.gotmpl +++ b/cmd/urfave-cli-genflags/generated_test.gotmpl @@ -10,31 +10,30 @@ func Test{{.TypeName}}_SatisfiesFlagInterface(t *testing.T) { _ = f.IsSet() _ = f.Names() } -{{end}} - -{{if .GenerateFmtStringerInterface}} -func Test{{.TypeName}}_SatisfiesFmtStringerInterface(t *testing.T) { - var f fmt.Stringer = &{{$.UrfaveCLITestNamespace}}{{.TypeName}}{} - _ = f.String() -} -{{end}} - -{{if .GenerateRequiredFlagInterface}} func Test{{.TypeName}}_SatisfiesRequiredFlagInterface(t *testing.T) { var f {{$.UrfaveCLITestNamespace}}RequiredFlag = &{{$.UrfaveCLITestNamespace}}{{.TypeName}}{} _ = f.IsRequired() } -{{end}} -{{if .GenerateVisibleFlagInterface}} func Test{{.TypeName}}_SatisfiesVisibleFlagInterface(t *testing.T) { var f {{$.UrfaveCLITestNamespace}}VisibleFlag = &{{$.UrfaveCLITestNamespace}}{{.TypeName}}{} _ = f.IsVisible() } + {{end}} + +{{if .GenerateFmtStringerInterface}} +func Test{{.TypeName}}_SatisfiesFmtStringerInterface(t *testing.T) { + var f fmt.Stringer = &{{$.UrfaveCLITestNamespace}}{{.TypeName}}{} + + _ = f.String() +} +{{end}} + + {{end}} // vim{{/* 👻 */}}:ro diff --git a/docs/v2/examples/flags.md b/docs/v2/examples/flags.md index eaec6f4a39..492f38bb00 100644 --- a/docs/v2/examples/flags.md +++ b/docs/v2/examples/flags.md @@ -240,7 +240,7 @@ For example this: ```go package main diff --git a/docs/v3/index.md b/docs/v3/index.md new file mode 100644 index 0000000000..9632522e67 --- /dev/null +++ b/docs/v3/index.md @@ -0,0 +1 @@ +# v3 guide diff --git a/flag-spec.yaml b/flag-spec.yaml index 76480ba47c..a38b933379 100644 --- a/flag-spec.yaml +++ b/flag-spec.yaml @@ -3,6 +3,7 @@ # `Spec` type that maps to this file structure. flag_types: bool: + no_default_text: true struct_fields: - name: Count type: int diff --git a/flag.go b/flag.go index b66a75da5e..a776c7497a 100644 --- a/flag.go +++ b/flag.go @@ -97,9 +97,14 @@ type ActionableFlag interface { // this interface be implemented. 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 } @@ -108,6 +113,7 @@ type Flag interface { type RequiredFlag interface { Flag + // whether the flag is a required flag or not IsRequired() bool } @@ -140,6 +146,12 @@ type DocGenerationSliceFlag interface { IsSliceFlag() bool } +// Countable is an interface to enable detection of flag values which support +// repetitive flags +type Countable interface { + Count() int +} + // VisibleFlag is an interface that allows to check if a flag is visible type VisibleFlag interface { Flag @@ -153,15 +165,10 @@ type VisibleFlag interface { type CategorizableFlag interface { VisibleFlag + // Returns the category of the flag GetCategory() string } -// Countable is an interface to enable detection of flag values which support -// repetitive flags -type Countable interface { - Count() int -} - func flagSet(name string, flags []Flag) (*flag.FlagSet, error) { set := flag.NewFlagSet(name, flag.ContinueOnError) diff --git a/flag_bool.go b/flag_bool.go index f64d1cd92c..94de7351a1 100644 --- a/flag_bool.go +++ b/flag_bool.go @@ -58,21 +58,6 @@ func (b *boolValue) Count() int { return 0 } -// TakesValue returns true of the flag takes a value, otherwise false -func (f *BoolFlag) TakesValue() bool { - return false -} - -// GetUsage returns the usage string for the flag -func (f *BoolFlag) GetUsage() string { - return f.Usage -} - -// GetCategory returns the category for the flag -func (f *BoolFlag) GetCategory() string { - return f.Category -} - // GetValue returns the flags value as string representation and an empty // string if the flag takes no value at all. func (f *BoolFlag) GetValue() string { @@ -87,11 +72,6 @@ func (f *BoolFlag) GetDefaultText() string { return fmt.Sprintf("%v", f.defaultValue) } -// GetEnvVars returns the env vars for this flag -func (f *BoolFlag) GetEnvVars() []string { - return f.EnvVars -} - // RunAction executes flag action if set func (f *BoolFlag) RunAction(c *Context) error { if f.Action != nil { diff --git a/flag_duration.go b/flag_duration.go index eac4cb8332..ad2b83d1c8 100644 --- a/flag_duration.go +++ b/flag_duration.go @@ -6,21 +6,6 @@ import ( "time" ) -// TakesValue returns true of the flag takes a value, otherwise false -func (f *DurationFlag) TakesValue() bool { - return true -} - -// GetUsage returns the usage string for the flag -func (f *DurationFlag) GetUsage() string { - return f.Usage -} - -// GetCategory returns the category for the flag -func (f *DurationFlag) GetCategory() string { - return f.Category -} - // GetValue returns the flags value as string representation and an empty // string if the flag takes no value at all. func (f *DurationFlag) GetValue() string { @@ -35,11 +20,6 @@ func (f *DurationFlag) GetDefaultText() string { return f.defaultValue.String() } -// GetEnvVars returns the env vars for this flag -func (f *DurationFlag) GetEnvVars() []string { - return f.EnvVars -} - // Apply populates the flag given the flag set and environment func (f *DurationFlag) Apply(set *flag.FlagSet) error { // set default value so that environment wont be able to overwrite it diff --git a/flag_float64.go b/flag_float64.go index bce26c1958..d522ac0436 100644 --- a/flag_float64.go +++ b/flag_float64.go @@ -6,21 +6,6 @@ import ( "strconv" ) -// TakesValue returns true of the flag takes a value, otherwise false -func (f *Float64Flag) TakesValue() bool { - return true -} - -// GetUsage returns the usage string for the flag -func (f *Float64Flag) GetUsage() string { - return f.Usage -} - -// GetCategory returns the category for the flag -func (f *Float64Flag) GetCategory() string { - return f.Category -} - // 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 { @@ -35,11 +20,6 @@ func (f *Float64Flag) GetDefaultText() string { return f.GetValue() } -// GetEnvVars returns the env vars for this flag -func (f *Float64Flag) GetEnvVars() []string { - return f.EnvVars -} - // 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 { diff --git a/flag_float64_slice.go b/flag_float64_slice.go index 413aa50e9f..d060432f06 100644 --- a/flag_float64_slice.go +++ b/flag_float64_slice.go @@ -86,21 +86,6 @@ func (f *Float64SliceFlag) String() string { return FlagStringer(f) } -// TakesValue returns true if the flag takes a value, otherwise false -func (f *Float64SliceFlag) TakesValue() bool { - return true -} - -// GetUsage returns the usage string for the flag -func (f *Float64SliceFlag) GetUsage() string { - return f.Usage -} - -// GetCategory returns the category for the flag -func (f *Float64SliceFlag) GetCategory() string { - return f.Category -} - // GetValue returns the flags value as string representation and an empty // string if the flag takes no value at all. func (f *Float64SliceFlag) GetValue() string { @@ -121,11 +106,6 @@ func (f *Float64SliceFlag) GetDefaultText() string { return f.GetValue() } -// GetEnvVars returns the env vars for this flag -func (f *Float64SliceFlag) GetEnvVars() []string { - return f.EnvVars -} - // IsSliceFlag implements DocGenerationSliceFlag. func (f *Float64SliceFlag) IsSliceFlag() bool { return true diff --git a/flag_generic.go b/flag_generic.go index 4f9ac0a7ff..0797e5a22a 100644 --- a/flag_generic.go +++ b/flag_generic.go @@ -24,21 +24,6 @@ func (s *stringGeneric) String() string { return s.value } -// TakesValue returns true of the flag takes a value, otherwise false -func (f *GenericFlag) TakesValue() bool { - return true -} - -// GetUsage returns the usage string for the flag -func (f *GenericFlag) GetUsage() string { - return f.Usage -} - -// GetCategory returns the category for the flag -func (f *GenericFlag) GetCategory() string { - return f.Category -} - // GetValue returns the flags value as string representation and an empty // string if the flag takes no value at all. func (f *GenericFlag) GetValue() string { @@ -59,11 +44,6 @@ func (f *GenericFlag) GetDefaultText() string { return "" } -// GetEnvVars returns the env vars for this flag -func (f *GenericFlag) GetEnvVars() []string { - return f.EnvVars -} - // Apply takes the flagset and calls Set on the generic flag with the value // provided by the user for parsing by the flag func (f *GenericFlag) Apply(set *flag.FlagSet) error { diff --git a/flag_int.go b/flag_int.go index d681270a23..c76e101de1 100644 --- a/flag_int.go +++ b/flag_int.go @@ -6,21 +6,6 @@ import ( "strconv" ) -// TakesValue returns true of the flag takes a value, otherwise false -func (f *IntFlag) TakesValue() bool { - return true -} - -// GetUsage returns the usage string for the flag -func (f *IntFlag) GetUsage() string { - return f.Usage -} - -// GetCategory returns the category for the flag -func (f *IntFlag) GetCategory() string { - return f.Category -} - // 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 { @@ -35,11 +20,6 @@ func (f *IntFlag) GetDefaultText() string { return fmt.Sprintf("%d", f.defaultValue) } -// GetEnvVars returns the env vars for this flag -func (f *IntFlag) GetEnvVars() []string { - return f.EnvVars -} - // Apply populates the flag given the flag set and environment func (f *IntFlag) Apply(set *flag.FlagSet) error { // set default value so that environment wont be able to overwrite it diff --git a/flag_int64.go b/flag_int64.go index 6f8c8d27d8..93eae07524 100644 --- a/flag_int64.go +++ b/flag_int64.go @@ -6,21 +6,6 @@ import ( "strconv" ) -// TakesValue returns true of the flag takes a value, otherwise false -func (f *Int64Flag) TakesValue() bool { - return true -} - -// GetUsage returns the usage string for the flag -func (f *Int64Flag) GetUsage() string { - return f.Usage -} - -// GetCategory returns the category for the flag -func (f *Int64Flag) GetCategory() string { - return f.Category -} - // 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 { @@ -35,11 +20,6 @@ func (f *Int64Flag) GetDefaultText() string { return fmt.Sprintf("%d", f.defaultValue) } -// GetEnvVars returns the env vars for this flag -func (f *Int64Flag) GetEnvVars() []string { - return f.EnvVars -} - // Apply populates the flag given the flag set and environment func (f *Int64Flag) Apply(set *flag.FlagSet) error { // set default value so that environment wont be able to overwrite it diff --git a/flag_int64_slice.go b/flag_int64_slice.go index c45c43d3ab..2db2ceab24 100644 --- a/flag_int64_slice.go +++ b/flag_int64_slice.go @@ -87,21 +87,6 @@ func (f *Int64SliceFlag) String() string { return FlagStringer(f) } -// TakesValue returns true of the flag takes a value, otherwise false -func (f *Int64SliceFlag) TakesValue() bool { - return true -} - -// GetUsage returns the usage string for the flag -func (f *Int64SliceFlag) GetUsage() string { - return f.Usage -} - -// GetCategory returns the category for the flag -func (f *Int64SliceFlag) GetCategory() string { - return f.Category -} - // GetValue returns the flags value as string representation and an empty // string if the flag takes no value at all. func (f *Int64SliceFlag) GetValue() string { @@ -122,11 +107,6 @@ func (f *Int64SliceFlag) GetDefaultText() string { return f.GetValue() } -// GetEnvVars returns the env vars for this flag -func (f *Int64SliceFlag) GetEnvVars() []string { - return f.EnvVars -} - // IsSliceFlag implements DocGenerationSliceFlag. func (f *Int64SliceFlag) IsSliceFlag() bool { return true diff --git a/flag_int_slice.go b/flag_int_slice.go index d4006e594c..a2c9f21301 100644 --- a/flag_int_slice.go +++ b/flag_int_slice.go @@ -98,21 +98,6 @@ func (f *IntSliceFlag) String() string { return FlagStringer(f) } -// TakesValue returns true of the flag takes a value, otherwise false -func (f *IntSliceFlag) TakesValue() bool { - return true -} - -// GetUsage returns the usage string for the flag -func (f *IntSliceFlag) GetUsage() string { - return f.Usage -} - -// GetCategory returns the category for the flag -func (f *IntSliceFlag) GetCategory() string { - return f.Category -} - // GetValue returns the flags value as string representation and an empty // string if the flag takes no value at all. func (f *IntSliceFlag) GetValue() string { @@ -133,11 +118,6 @@ func (f *IntSliceFlag) GetDefaultText() string { return f.GetValue() } -// GetEnvVars returns the env vars for this flag -func (f *IntSliceFlag) GetEnvVars() []string { - return f.EnvVars -} - // IsSliceFlag implements DocGenerationSliceFlag. func (f *IntSliceFlag) IsSliceFlag() bool { return true diff --git a/flag_path.go b/flag_path.go index 6434d3224f..8e75953e2e 100644 --- a/flag_path.go +++ b/flag_path.go @@ -7,21 +7,6 @@ import ( type Path = string -// TakesValue returns true of the flag takes a value, otherwise false -func (f *PathFlag) TakesValue() bool { - return true -} - -// GetUsage returns the usage string for the flag -func (f *PathFlag) GetUsage() string { - return f.Usage -} - -// GetCategory returns the category for the flag -func (f *PathFlag) GetCategory() string { - return f.Category -} - // GetValue returns the flags value as string representation and an empty // string if the flag takes no value at all. func (f *PathFlag) GetValue() string { @@ -39,11 +24,6 @@ func (f *PathFlag) GetDefaultText() string { return fmt.Sprintf("%q", f.defaultValue) } -// GetEnvVars returns the env vars for this flag -func (f *PathFlag) GetEnvVars() []string { - return f.EnvVars -} - // Apply populates the flag given the flag set and environment func (f *PathFlag) Apply(set *flag.FlagSet) error { // set default value so that environment wont be able to overwrite it diff --git a/flag_string.go b/flag_string.go index 3050086e87..b7b78c63ec 100644 --- a/flag_string.go +++ b/flag_string.go @@ -5,21 +5,6 @@ import ( "fmt" ) -// TakesValue returns true of the flag takes a value, otherwise false -func (f *StringFlag) TakesValue() bool { - return true -} - -// GetUsage returns the usage string for the flag -func (f *StringFlag) GetUsage() string { - return f.Usage -} - -// GetCategory returns the category for the flag -func (f *StringFlag) GetCategory() string { - return f.Category -} - // GetValue returns the flags value as string representation and an empty // string if the flag takes no value at all. func (f *StringFlag) GetValue() string { @@ -37,11 +22,6 @@ func (f *StringFlag) GetDefaultText() string { return fmt.Sprintf("%q", f.defaultValue) } -// GetEnvVars returns the env vars for this flag -func (f *StringFlag) GetEnvVars() []string { - return f.EnvVars -} - // Apply populates the flag given the flag set and environment func (f *StringFlag) Apply(set *flag.FlagSet) error { // set default value so that environment wont be able to overwrite it diff --git a/flag_string_slice.go b/flag_string_slice.go index baca2a2fb9..f53c0e6098 100644 --- a/flag_string_slice.go +++ b/flag_string_slice.go @@ -77,21 +77,6 @@ func (f *StringSliceFlag) String() string { return FlagStringer(f) } -// TakesValue returns true of the flag takes a value, otherwise false -func (f *StringSliceFlag) TakesValue() bool { - return true -} - -// GetUsage returns the usage string for the flag -func (f *StringSliceFlag) GetUsage() string { - return f.Usage -} - -// GetCategory returns the category for the flag -func (f *StringSliceFlag) GetCategory() string { - return f.Category -} - // GetValue returns the flags value as string representation and an empty // string if the flag takes no value at all. func (f *StringSliceFlag) GetValue() string { @@ -114,11 +99,6 @@ func (f *StringSliceFlag) GetDefaultText() string { return f.GetValue() } -// GetEnvVars returns the env vars for this flag -func (f *StringSliceFlag) GetEnvVars() []string { - return f.EnvVars -} - // IsSliceFlag implements DocGenerationSliceFlag. func (f *StringSliceFlag) IsSliceFlag() bool { return true diff --git a/flag_test.go b/flag_test.go index 3a2bc2b67e..e1a040d965 100644 --- a/flag_test.go +++ b/flag_test.go @@ -224,7 +224,7 @@ func TestFlagsFromEnv(t *testing.T) { f, ok := test.flag.(DocGenerationFlag) if !ok { - t.Errorf("flag %v needs to implement DocGenerationFlag to retrieve env vars", test.flag) + t.Errorf("flag %[1]q (%[1]T) needs to implement DocGenerationFlag to retrieve env vars", test.flag) } envVarSlice := f.GetEnvVars() _ = os.Setenv(envVarSlice[0], test.input) diff --git a/flag_timestamp.go b/flag_timestamp.go index fa0671fe4e..cc90d42f00 100644 --- a/flag_timestamp.go +++ b/flag_timestamp.go @@ -91,21 +91,6 @@ func (t *Timestamp) clone() *Timestamp { return tc } -// TakesValue returns true of the flag takes a value, otherwise false -func (f *TimestampFlag) TakesValue() bool { - return true -} - -// GetUsage returns the usage string for the flag -func (f *TimestampFlag) GetUsage() string { - return f.Usage -} - -// GetCategory returns the category for the flag -func (f *TimestampFlag) GetCategory() string { - return f.Category -} - // GetValue returns the flags value as string representation and an empty // string if the flag takes no value at all. func (f *TimestampFlag) GetValue() string { @@ -127,11 +112,6 @@ func (f *TimestampFlag) GetDefaultText() string { return "" } -// GetEnvVars returns the env vars for this flag -func (f *TimestampFlag) GetEnvVars() []string { - return f.EnvVars -} - // Apply populates the flag given the flag set and environment func (f *TimestampFlag) Apply(set *flag.FlagSet) error { if f.Layout == "" { diff --git a/flag_uint.go b/flag_uint.go index d11aa0a891..90a5318607 100644 --- a/flag_uint.go +++ b/flag_uint.go @@ -6,21 +6,6 @@ import ( "strconv" ) -// TakesValue returns true of the flag takes a value, otherwise false -func (f *UintFlag) TakesValue() bool { - return true -} - -// GetUsage returns the usage string for the flag -func (f *UintFlag) GetUsage() string { - return f.Usage -} - -// GetCategory returns the category for the flag -func (f *UintFlag) GetCategory() string { - return f.Category -} - // Apply populates the flag given the flag set and environment func (f *UintFlag) Apply(set *flag.FlagSet) error { // set default value so that environment wont be able to overwrite it @@ -49,15 +34,6 @@ func (f *UintFlag) Apply(set *flag.FlagSet) error { return nil } -// RunAction executes flag action if set -func (f *UintFlag) RunAction(c *Context) error { - if f.Action != nil { - return f.Action(c, c.Uint(f.Name)) - } - - 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 { @@ -72,16 +48,20 @@ func (f *UintFlag) GetDefaultText() string { return fmt.Sprintf("%d", f.defaultValue) } -// GetEnvVars returns the env vars for this flag -func (f *UintFlag) GetEnvVars() []string { - return f.EnvVars -} - // Get returns the flag’s value in the given Context. func (f *UintFlag) Get(ctx *Context) uint { return ctx.Uint(f.Name) } +// RunAction executes flag action if set +func (f *UintFlag) RunAction(c *Context) error { + if f.Action != nil { + return f.Action(c, c.Uint(f.Name)) + } + + return nil +} + // Uint looks up the value of a local UintFlag, returns // 0 if not found func (cCtx *Context) Uint(name string) uint { diff --git a/flag_uint64.go b/flag_uint64.go index ea73100a97..c66367b0af 100644 --- a/flag_uint64.go +++ b/flag_uint64.go @@ -6,21 +6,6 @@ import ( "strconv" ) -// TakesValue returns true of the flag takes a value, otherwise false -func (f *Uint64Flag) TakesValue() bool { - return true -} - -// GetUsage returns the usage string for the flag -func (f *Uint64Flag) GetUsage() string { - return f.Usage -} - -// GetCategory returns the category for the flag -func (f *Uint64Flag) GetCategory() string { - return f.Category -} - // Apply populates the flag given the flag set and environment func (f *Uint64Flag) Apply(set *flag.FlagSet) error { // set default value so that environment wont be able to overwrite it @@ -49,15 +34,6 @@ func (f *Uint64Flag) Apply(set *flag.FlagSet) error { return nil } -// RunAction executes flag action if set -func (f *Uint64Flag) RunAction(c *Context) error { - if f.Action != nil { - return f.Action(c, c.Uint64(f.Name)) - } - - 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 { @@ -72,16 +48,20 @@ func (f *Uint64Flag) GetDefaultText() string { return fmt.Sprintf("%d", f.defaultValue) } -// GetEnvVars returns the env vars for this flag -func (f *Uint64Flag) GetEnvVars() []string { - return f.EnvVars -} - // Get returns the flag’s value in the given Context. func (f *Uint64Flag) Get(ctx *Context) uint64 { return ctx.Uint64(f.Name) } +// RunAction executes flag action if set +func (f *Uint64Flag) RunAction(c *Context) error { + if f.Action != nil { + return f.Action(c, c.Uint64(f.Name)) + } + + return nil +} + // Uint64 looks up the value of a local Uint64Flag, returns // 0 if not found func (cCtx *Context) Uint64(name string) uint64 { diff --git a/flag_uint64_slice.go b/flag_uint64_slice.go index 61bb30b551..ae251ac793 100644 --- a/flag_uint64_slice.go +++ b/flag_uint64_slice.go @@ -91,21 +91,6 @@ func (f *Uint64SliceFlag) String() string { return FlagStringer(f) } -// TakesValue returns true of the flag takes a value, otherwise false -func (f *Uint64SliceFlag) TakesValue() bool { - return true -} - -// GetUsage returns the usage string for the flag -func (f *Uint64SliceFlag) GetUsage() string { - return f.Usage -} - -// GetCategory returns the category for the flag -func (f *Uint64SliceFlag) GetCategory() string { - return f.Category -} - // GetValue returns the flags value as string representation and an empty // string if the flag takes no value at all. func (f *Uint64SliceFlag) GetValue() string { @@ -126,11 +111,6 @@ func (f *Uint64SliceFlag) GetDefaultText() string { return f.GetValue() } -// GetEnvVars returns the env vars for this flag -func (f *Uint64SliceFlag) GetEnvVars() []string { - return f.EnvVars -} - // IsSliceFlag implements DocGenerationSliceFlag. func (f *Uint64SliceFlag) IsSliceFlag() bool { return true @@ -180,6 +160,15 @@ func (f *Uint64SliceFlag) Get(ctx *Context) []uint64 { return ctx.Uint64Slice(f.Name) } +// RunAction executes flag action if set +func (f *Uint64SliceFlag) RunAction(c *Context) error { + if f.Action != nil { + return f.Action(c, c.Uint64Slice(f.Name)) + } + + return nil +} + // Uint64Slice looks up the value of a local Uint64SliceFlag, returns // nil if not found func (cCtx *Context) Uint64Slice(name string) []uint64 { diff --git a/flag_uint_slice.go b/flag_uint_slice.go index 363aa657f3..92848f22fc 100644 --- a/flag_uint_slice.go +++ b/flag_uint_slice.go @@ -102,21 +102,6 @@ func (f *UintSliceFlag) String() string { return FlagStringer(f) } -// TakesValue returns true of the flag takes a value, otherwise false -func (f *UintSliceFlag) TakesValue() bool { - return true -} - -// GetUsage returns the usage string for the flag -func (f *UintSliceFlag) GetUsage() string { - return f.Usage -} - -// GetCategory returns the category for the flag -func (f *UintSliceFlag) GetCategory() string { - return f.Category -} - // GetValue returns the flags value as string representation and an empty // string if the flag takes no value at all. func (f *UintSliceFlag) GetValue() string { @@ -137,11 +122,6 @@ func (f *UintSliceFlag) GetDefaultText() string { return f.GetValue() } -// GetEnvVars returns the env vars for this flag -func (f *UintSliceFlag) GetEnvVars() []string { - return f.EnvVars -} - // IsSliceFlag implements DocGenerationSliceFlag. func (f *UintSliceFlag) IsSliceFlag() bool { return true @@ -191,6 +171,15 @@ func (f *UintSliceFlag) Get(ctx *Context) []uint { return ctx.UintSlice(f.Name) } +// RunAction executes flag action if set +func (f *UintSliceFlag) RunAction(c *Context) error { + if f.Action != nil { + return f.Action(c, c.UintSlice(f.Name)) + } + + return nil +} + // UintSlice looks up the value of a local UintSliceFlag, returns // nil if not found func (cCtx *Context) UintSlice(name string) []uint { diff --git a/go.mod b/go.mod index 09ef1477d8..d2774262a0 100644 --- a/go.mod +++ b/go.mod @@ -1,4 +1,4 @@ -module github.com/urfave/cli/v2 +module github.com/urfave/cli/v3 go 1.18 diff --git a/godoc-current.txt b/godoc-current.txt index b8dbf6ad0a..9abda4be5f 100644 --- a/godoc-current.txt +++ b/godoc-current.txt @@ -1,4 +1,4 @@ -package cli // import "github.com/urfave/cli/v2" +package cli // import "github.com/urfave/cli/v3" Package cli provides a minimal framework for creating and organizing command line Go applications. cli is designed to be easy to understand and write, @@ -465,7 +465,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 @@ -499,11 +499,12 @@ 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 + TakesValue returns true if the flag takes a value, otherwise false type CategorizableFlag interface { VisibleFlag + // Returns the category of the flag GetCategory() string } CategorizableFlag is an interface that allows us to potentially use a flag @@ -794,7 +795,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 @@ -828,7 +829,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) @@ -863,9 +864,14 @@ 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 } Flag is a common interface related to parsing flags in cli. For more @@ -973,7 +979,7 @@ 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 + GetCategory returns the category of the flag func (f *Float64Flag) GetDefaultText() string GetDefaultText returns the default text for this flag @@ -1007,7 +1013,7 @@ 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 + TakesValue returns true if the flag takes a value, otherwise false type Float64Slice struct { // Has unexported fields. @@ -1062,7 +1068,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 @@ -1146,7 +1152,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 @@ -1180,7 +1186,7 @@ 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 + TakesValue returns true if the flag takes a value, otherwise false type Int64Flag struct { Name string @@ -1214,7 +1220,7 @@ 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 + GetCategory returns the category of the flag func (f *Int64Flag) GetDefaultText() string GetDefaultText returns the default text for this flag @@ -1248,7 +1254,7 @@ func (f *Int64Flag) String() string String returns a readable representation of this value (for usage defaults) func (f *Int64Flag) 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 Int64Slice struct { // Has unexported fields. @@ -1303,7 +1309,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 @@ -1346,7 +1352,7 @@ 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 + TakesValue returns true if the flag takes a value, otherwise false type IntFlag struct { Name string @@ -1380,7 +1386,7 @@ 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 + GetCategory returns the category of the flag func (f *IntFlag) GetDefaultText() string GetDefaultText returns the default text for this flag @@ -1414,7 +1420,7 @@ func (f *IntFlag) String() string String returns a readable representation of this value (for usage defaults) func (f *IntFlag) 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 IntSlice struct { // Has unexported fields. @@ -1473,7 +1479,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 @@ -1516,7 +1522,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 InvalidFlagAccessFunc func(*Context, string) InvalidFlagAccessFunc is executed when an invalid flag is accessed from the @@ -1584,7 +1590,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 @@ -1618,11 +1624,12 @@ 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 + TakesValue returns true if the flag takes a value, otherwise false type RequiredFlag interface { Flag + // whether the flag is a required flag or not IsRequired() bool } RequiredFlag is an interface that allows us to mark flags as required @@ -1727,7 +1734,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 @@ -1761,7 +1768,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. @@ -1818,7 +1825,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 @@ -1861,7 +1868,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 @@ -1930,7 +1937,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 @@ -1964,7 +1971,7 @@ 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 + TakesValue returns true if the flag takes a value, otherwise false type Uint64Flag struct { Name string @@ -1998,7 +2005,7 @@ 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 + GetCategory returns the category of the flag func (f *Uint64Flag) GetDefaultText() string GetDefaultText returns the default text for this flag @@ -2032,7 +2039,7 @@ 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 + TakesValue returns true if the flag takes a value, otherwise false type Uint64Slice struct { // Has unexported fields. @@ -2087,7 +2094,7 @@ func (f *Uint64SliceFlag) Get(ctx *Context) []uint64 Get returns the flag’s value in the given Context. func (f *Uint64SliceFlag) GetCategory() string - GetCategory returns the category for the flag + GetCategory returns the category of the flag func (f *Uint64SliceFlag) GetDefaultText() string GetDefaultText returns the default text for this flag @@ -2117,11 +2124,14 @@ func (f *Uint64SliceFlag) IsVisible() bool func (f *Uint64SliceFlag) Names() []string Names returns the names of the flag +func (f *Uint64SliceFlag) RunAction(c *Context) error + RunAction executes flag action if set + func (f *Uint64SliceFlag) String() string String returns a readable representation of this value (for usage defaults) func (f *Uint64SliceFlag) 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 UintFlag struct { Name string @@ -2155,7 +2165,7 @@ 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 + GetCategory returns the category of the flag func (f *UintFlag) GetDefaultText() string GetDefaultText returns the default text for this flag @@ -2189,7 +2199,7 @@ 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 UintSlice struct { // Has unexported fields. @@ -2248,7 +2258,7 @@ func (f *UintSliceFlag) Get(ctx *Context) []uint Get returns the flag’s value in the given Context. func (f *UintSliceFlag) GetCategory() string - GetCategory returns the category for the flag + GetCategory returns the category of the flag func (f *UintSliceFlag) GetDefaultText() string GetDefaultText returns the default text for this flag @@ -2278,11 +2288,14 @@ func (f *UintSliceFlag) IsVisible() bool func (f *UintSliceFlag) Names() []string Names returns the names of the flag +func (f *UintSliceFlag) RunAction(c *Context) error + RunAction executes flag action if set + func (f *UintSliceFlag) String() string String returns a readable representation of this value (for usage defaults) func (f *UintSliceFlag) 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 @@ -2300,7 +2313,7 @@ type VisibleFlagCategory interface { } VisibleFlagCategory is a category containing flags. -package altsrc // import "github.com/urfave/cli/v2/altsrc" +package altsrc // import "github.com/urfave/cli/v3/altsrc" FUNCTIONS diff --git a/internal/build/build.go b/internal/build/build.go index 04d0668814..dcef50b143 100644 --- a/internal/build/build.go +++ b/internal/build/build.go @@ -18,7 +18,7 @@ import ( "runtime" "strings" - "github.com/urfave/cli/v2" + "github.com/urfave/cli/v3" ) const ( @@ -240,10 +240,10 @@ func TestActionFunc(c *cli.Context) error { tags := c.String("tags") for _, pkg := range c.StringSlice("packages") { - packageName := "github.com/urfave/cli/v2" + packageName := "github.com/urfave/cli/v3" if pkg != "cli" { - packageName = fmt.Sprintf("github.com/urfave/cli/v2/%s", pkg) + packageName = fmt.Sprintf("github.com/urfave/cli/v3/%s", pkg) } args := []string{"test"} diff --git a/internal/example-cli/example-cli.go b/internal/example-cli/example-cli.go index 06cbbfffcb..3e6e4dae4d 100644 --- a/internal/example-cli/example-cli.go +++ b/internal/example-cli/example-cli.go @@ -3,7 +3,7 @@ package main import ( - "github.com/urfave/cli/v2" + "github.com/urfave/cli/v3" ) func main() { diff --git a/sliceflag.go b/sliceflag.go index 7dea3576a3..b2ca59041f 100644 --- a/sliceflag.go +++ b/sliceflag.go @@ -1,6 +1,3 @@ -//go:build go1.18 -// +build go1.18 - package cli import ( diff --git a/sliceflag_pre18.go b/sliceflag_pre18.go deleted file mode 100644 index 1173ae7402..0000000000 --- a/sliceflag_pre18.go +++ /dev/null @@ -1,10 +0,0 @@ -//go:build !go1.18 -// +build !go1.18 - -package cli - -import ( - "flag" -) - -func unwrapFlagValue(v flag.Value) flag.Value { return v } diff --git a/sliceflag_test.go b/sliceflag_test.go index 83374172c8..78dc5d509d 100644 --- a/sliceflag_test.go +++ b/sliceflag_test.go @@ -1,6 +1,3 @@ -//go:build go1.18 -// +build go1.18 - package cli import ( diff --git a/testdata/godoc-v2.x.txt b/testdata/godoc-v2.x.txt index b8dbf6ad0a..ec5d8632c0 100644 --- a/testdata/godoc-v2.x.txt +++ b/testdata/godoc-v2.x.txt @@ -1,4 +1,4 @@ -package cli // import "github.com/urfave/cli/v2" +package cli // import "github.com/urfave/cli/v3" Package cli provides a minimal framework for creating and organizing command line Go applications. cli is designed to be easy to understand and write, @@ -73,8 +73,7 @@ DESCRIPTION: OPTIONS:{{template "visibleFlagCategoryTemplate" .}}{{else if .VisibleFlags}} -OPTIONS:{{template "visibleFlagTemplate" .}}{{end}} -` +OPTIONS:{{template "visibleFlagTemplate" .}}{{end}}` CommandHelpTemplate is the text template for the command help topic. cli.go uses text/template to render templates. You can render custom help text by setting this variable. @@ -145,8 +144,7 @@ COMMANDS:{{template "visibleCommandTemplate" .}}{{end}}{{if .VisibleFlagCategori OPTIONS:{{template "visibleFlagCategoryTemplate" .}}{{else if .VisibleFlags}} -OPTIONS:{{template "visibleFlagTemplate" .}}{{end}} -` +OPTIONS:{{template "visibleFlagTemplate" .}}{{end}}` SubcommandHelpTemplate is the text template for the subcommand help topic. cli.go uses text/template to render templates. You can render custom help text by setting this variable. @@ -465,7 +463,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 @@ -499,11 +497,12 @@ 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 + TakesValue returns true if the flag takes a value, otherwise false type CategorizableFlag interface { VisibleFlag + // Returns the category of the flag GetCategory() string } CategorizableFlag is an interface that allows us to potentially use a flag @@ -794,7 +793,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 @@ -828,7 +827,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) @@ -863,9 +862,14 @@ 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 } Flag is a common interface related to parsing flags in cli. For more @@ -973,7 +977,7 @@ 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 + GetCategory returns the category of the flag func (f *Float64Flag) GetDefaultText() string GetDefaultText returns the default text for this flag @@ -1007,7 +1011,7 @@ 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 + TakesValue returns true if the flag takes a value, otherwise false type Float64Slice struct { // Has unexported fields. @@ -1062,7 +1066,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 @@ -1146,7 +1150,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 @@ -1180,7 +1184,7 @@ 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 + TakesValue returns true if the flag takes a value, otherwise false type Int64Flag struct { Name string @@ -1214,7 +1218,7 @@ 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 + GetCategory returns the category of the flag func (f *Int64Flag) GetDefaultText() string GetDefaultText returns the default text for this flag @@ -1248,7 +1252,7 @@ func (f *Int64Flag) String() string String returns a readable representation of this value (for usage defaults) func (f *Int64Flag) 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 Int64Slice struct { // Has unexported fields. @@ -1303,7 +1307,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 @@ -1346,7 +1350,7 @@ 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 + TakesValue returns true if the flag takes a value, otherwise false type IntFlag struct { Name string @@ -1380,7 +1384,7 @@ 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 + GetCategory returns the category of the flag func (f *IntFlag) GetDefaultText() string GetDefaultText returns the default text for this flag @@ -1414,7 +1418,7 @@ func (f *IntFlag) String() string String returns a readable representation of this value (for usage defaults) func (f *IntFlag) 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 IntSlice struct { // Has unexported fields. @@ -1473,7 +1477,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 @@ -1516,7 +1520,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 InvalidFlagAccessFunc func(*Context, string) InvalidFlagAccessFunc is executed when an invalid flag is accessed from the @@ -1584,7 +1588,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 @@ -1618,11 +1622,12 @@ 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 + TakesValue returns true if the flag takes a value, otherwise false type RequiredFlag interface { Flag + // whether the flag is a required flag or not IsRequired() bool } RequiredFlag is an interface that allows us to mark flags as required @@ -1727,7 +1732,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 @@ -1761,7 +1766,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. @@ -1818,7 +1823,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 @@ -1861,7 +1866,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 @@ -1930,7 +1935,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 @@ -1964,7 +1969,7 @@ 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 + TakesValue returns true if the flag takes a value, otherwise false type Uint64Flag struct { Name string @@ -1998,7 +2003,7 @@ 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 + GetCategory returns the category of the flag func (f *Uint64Flag) GetDefaultText() string GetDefaultText returns the default text for this flag @@ -2032,7 +2037,7 @@ 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 + TakesValue returns true if the flag takes a value, otherwise false type Uint64Slice struct { // Has unexported fields. @@ -2117,6 +2122,9 @@ func (f *Uint64SliceFlag) IsVisible() bool func (f *Uint64SliceFlag) Names() []string Names returns the names of the flag +func (f *Uint64SliceFlag) RunAction(c *Context) error + RunAction executes flag action if set + func (f *Uint64SliceFlag) String() string String returns a readable representation of this value (for usage defaults) @@ -2155,7 +2163,7 @@ 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 + GetCategory returns the category of the flag func (f *UintFlag) GetDefaultText() string GetDefaultText returns the default text for this flag @@ -2189,7 +2197,7 @@ 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 UintSlice struct { // Has unexported fields. @@ -2278,6 +2286,9 @@ func (f *UintSliceFlag) IsVisible() bool func (f *UintSliceFlag) Names() []string Names returns the names of the flag +func (f *UintSliceFlag) RunAction(c *Context) error + RunAction executes flag action if set + func (f *UintSliceFlag) String() string String returns a readable representation of this value (for usage defaults) @@ -2300,7 +2311,7 @@ type VisibleFlagCategory interface { } VisibleFlagCategory is a category containing flags. -package altsrc // import "github.com/urfave/cli/v2/altsrc" +package altsrc // import "github.com/urfave/cli/v3/altsrc" FUNCTIONS diff --git a/zz_generated.flags.go b/zz_generated.flags.go index 7d0a267f78..e8497ee45b 100644 --- a/zz_generated.flags.go +++ b/zz_generated.flags.go @@ -48,6 +48,26 @@ func (f *Float64SliceFlag) IsVisible() bool { return !f.Hidden } +// GetCategory returns the category of the flag +func (f *Float64SliceFlag) GetCategory() string { + return f.Category +} + +// GetUsage returns the usage string for the flag +func (f *Float64SliceFlag) GetUsage() string { + return f.Usage +} + +// GetEnvVars returns the env vars for this flag +func (f *Float64SliceFlag) GetEnvVars() []string { + return f.EnvVars +} + +// TakesValue returns true if the flag takes a value, otherwise false +func (f *Float64SliceFlag) TakesValue() bool { + return "Float64SliceFlag" != "BoolFlag" +} + // GenericFlag is a flag with type Generic type GenericFlag struct { Name string @@ -99,6 +119,26 @@ func (f *GenericFlag) IsVisible() bool { return !f.Hidden } +// GetCategory returns the category of the flag +func (f *GenericFlag) GetCategory() string { + return f.Category +} + +// GetUsage returns the usage string for the flag +func (f *GenericFlag) GetUsage() string { + return f.Usage +} + +// GetEnvVars returns the env vars for this flag +func (f *GenericFlag) GetEnvVars() []string { + return f.EnvVars +} + +// TakesValue returns true if the flag takes a value, otherwise false +func (f *GenericFlag) TakesValue() bool { + return "GenericFlag" != "BoolFlag" +} + // Int64SliceFlag is a flag with type *Int64Slice type Int64SliceFlag struct { Name string @@ -143,6 +183,26 @@ func (f *Int64SliceFlag) IsVisible() bool { return !f.Hidden } +// GetCategory returns the category of the flag +func (f *Int64SliceFlag) GetCategory() string { + return f.Category +} + +// GetUsage returns the usage string for the flag +func (f *Int64SliceFlag) GetUsage() string { + return f.Usage +} + +// GetEnvVars returns the env vars for this flag +func (f *Int64SliceFlag) GetEnvVars() []string { + return f.EnvVars +} + +// TakesValue returns true if the flag takes a value, otherwise false +func (f *Int64SliceFlag) TakesValue() bool { + return "Int64SliceFlag" != "BoolFlag" +} + // IntSliceFlag is a flag with type *IntSlice type IntSliceFlag struct { Name string @@ -187,6 +247,26 @@ func (f *IntSliceFlag) IsVisible() bool { return !f.Hidden } +// GetCategory returns the category of the flag +func (f *IntSliceFlag) GetCategory() string { + return f.Category +} + +// GetUsage returns the usage string for the flag +func (f *IntSliceFlag) GetUsage() string { + return f.Usage +} + +// GetEnvVars returns the env vars for this flag +func (f *IntSliceFlag) GetEnvVars() []string { + return f.EnvVars +} + +// TakesValue returns true if the flag takes a value, otherwise false +func (f *IntSliceFlag) TakesValue() bool { + return "IntSliceFlag" != "BoolFlag" +} + // PathFlag is a flag with type Path type PathFlag struct { Name string @@ -238,6 +318,26 @@ func (f *PathFlag) IsVisible() bool { return !f.Hidden } +// GetCategory returns the category of the flag +func (f *PathFlag) GetCategory() string { + return f.Category +} + +// GetUsage returns the usage string for the flag +func (f *PathFlag) GetUsage() string { + return f.Usage +} + +// GetEnvVars returns the env vars for this flag +func (f *PathFlag) GetEnvVars() []string { + return f.EnvVars +} + +// TakesValue returns true if the flag takes a value, otherwise false +func (f *PathFlag) TakesValue() bool { + return "PathFlag" != "BoolFlag" +} + // StringSliceFlag is a flag with type *StringSlice type StringSliceFlag struct { Name string @@ -284,6 +384,26 @@ func (f *StringSliceFlag) IsVisible() bool { return !f.Hidden } +// GetCategory returns the category of the flag +func (f *StringSliceFlag) GetCategory() string { + return f.Category +} + +// GetUsage returns the usage string for the flag +func (f *StringSliceFlag) GetUsage() string { + return f.Usage +} + +// GetEnvVars returns the env vars for this flag +func (f *StringSliceFlag) GetEnvVars() []string { + return f.EnvVars +} + +// TakesValue returns true if the flag takes a value, otherwise false +func (f *StringSliceFlag) TakesValue() bool { + return "StringSliceFlag" != "BoolFlag" +} + // TimestampFlag is a flag with type *Timestamp type TimestampFlag struct { Name string @@ -337,6 +457,26 @@ func (f *TimestampFlag) IsVisible() bool { return !f.Hidden } +// GetCategory returns the category of the flag +func (f *TimestampFlag) GetCategory() string { + return f.Category +} + +// GetUsage returns the usage string for the flag +func (f *TimestampFlag) GetUsage() string { + return f.Usage +} + +// GetEnvVars returns the env vars for this flag +func (f *TimestampFlag) GetEnvVars() []string { + return f.EnvVars +} + +// TakesValue returns true if the flag takes a value, otherwise false +func (f *TimestampFlag) TakesValue() bool { + return "TimestampFlag" != "BoolFlag" +} + // Uint64SliceFlag is a flag with type *Uint64Slice type Uint64SliceFlag struct { Name string @@ -381,6 +521,26 @@ func (f *Uint64SliceFlag) IsVisible() bool { return !f.Hidden } +// GetCategory returns the category of the flag +func (f *Uint64SliceFlag) GetCategory() string { + return f.Category +} + +// GetUsage returns the usage string for the flag +func (f *Uint64SliceFlag) GetUsage() string { + return f.Usage +} + +// GetEnvVars returns the env vars for this flag +func (f *Uint64SliceFlag) GetEnvVars() []string { + return f.EnvVars +} + +// TakesValue returns true if the flag takes a value, otherwise false +func (f *Uint64SliceFlag) TakesValue() bool { + return "Uint64SliceFlag" != "BoolFlag" +} + // UintSliceFlag is a flag with type *UintSlice type UintSliceFlag struct { Name string @@ -425,6 +585,26 @@ func (f *UintSliceFlag) IsVisible() bool { return !f.Hidden } +// GetCategory returns the category of the flag +func (f *UintSliceFlag) GetCategory() string { + return f.Category +} + +// GetUsage returns the usage string for the flag +func (f *UintSliceFlag) GetUsage() string { + return f.Usage +} + +// GetEnvVars returns the env vars for this flag +func (f *UintSliceFlag) GetEnvVars() []string { + return f.EnvVars +} + +// TakesValue returns true if the flag takes a value, otherwise false +func (f *UintSliceFlag) TakesValue() bool { + return "UintSliceFlag" != "BoolFlag" +} + // BoolFlag is a flag with type bool type BoolFlag struct { Name string @@ -476,6 +656,26 @@ func (f *BoolFlag) IsVisible() bool { return !f.Hidden } +// GetCategory returns the category of the flag +func (f *BoolFlag) GetCategory() string { + return f.Category +} + +// GetUsage returns the usage string for the flag +func (f *BoolFlag) GetUsage() string { + return f.Usage +} + +// GetEnvVars returns the env vars for this flag +func (f *BoolFlag) GetEnvVars() []string { + return f.EnvVars +} + +// TakesValue returns true if the flag takes a value, otherwise false +func (f *BoolFlag) TakesValue() bool { + return "BoolFlag" != "BoolFlag" +} + // Float64Flag is a flag with type float64 type Float64Flag struct { Name string @@ -525,6 +725,26 @@ 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" +} + // IntFlag is a flag with type int type IntFlag struct { Name string @@ -576,6 +796,26 @@ 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" +} + // Int64Flag is a flag with type int64 type Int64Flag struct { Name string @@ -627,6 +867,26 @@ 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" +} + // StringFlag is a flag with type string type StringFlag struct { Name string @@ -678,6 +938,26 @@ func (f *StringFlag) IsVisible() bool { return !f.Hidden } +// GetCategory returns the category of the flag +func (f *StringFlag) GetCategory() string { + return f.Category +} + +// GetUsage returns the usage string for the flag +func (f *StringFlag) GetUsage() string { + return f.Usage +} + +// GetEnvVars returns the env vars for this flag +func (f *StringFlag) GetEnvVars() []string { + return f.EnvVars +} + +// TakesValue returns true if the flag takes a value, otherwise false +func (f *StringFlag) TakesValue() bool { + return "StringFlag" != "BoolFlag" +} + // DurationFlag is a flag with type time.Duration type DurationFlag struct { Name string @@ -727,6 +1007,26 @@ func (f *DurationFlag) IsVisible() bool { return !f.Hidden } +// GetCategory returns the category of the flag +func (f *DurationFlag) GetCategory() string { + return f.Category +} + +// GetUsage returns the usage string for the flag +func (f *DurationFlag) GetUsage() string { + return f.Usage +} + +// GetEnvVars returns the env vars for this flag +func (f *DurationFlag) GetEnvVars() []string { + return f.EnvVars +} + +// TakesValue returns true if the flag takes a value, otherwise false +func (f *DurationFlag) TakesValue() bool { + return "DurationFlag" != "BoolFlag" +} + // UintFlag is a flag with type uint type UintFlag struct { Name string @@ -778,6 +1078,26 @@ 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" +} + // Uint64Flag is a flag with type uint64 type Uint64Flag struct { Name string @@ -829,4 +1149,24 @@ 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" +} + // vim:ro diff --git a/zz_generated.flags_test.go b/zz_generated.flags_test.go index 06ab7a6a7f..b7c68153c4 100644 --- a/zz_generated.flags_test.go +++ b/zz_generated.flags_test.go @@ -6,7 +6,7 @@ import ( "fmt" "testing" - "github.com/urfave/cli/v2" + "github.com/urfave/cli/v3" ) func TestFloat64SliceFlag_SatisfiesFlagInterface(t *testing.T) { @@ -35,12 +35,6 @@ func TestGenericFlag_SatisfiesFlagInterface(t *testing.T) { _ = f.Names() } -func TestGenericFlag_SatisfiesFmtStringerInterface(t *testing.T) { - var f fmt.Stringer = &cli.GenericFlag{} - - _ = f.String() -} - func TestGenericFlag_SatisfiesRequiredFlagInterface(t *testing.T) { var f cli.RequiredFlag = &cli.GenericFlag{} @@ -53,6 +47,12 @@ func TestGenericFlag_SatisfiesVisibleFlagInterface(t *testing.T) { _ = f.IsVisible() } +func TestGenericFlag_SatisfiesFmtStringerInterface(t *testing.T) { + var f fmt.Stringer = &cli.GenericFlag{} + + _ = f.String() +} + func TestInt64SliceFlag_SatisfiesFlagInterface(t *testing.T) { var f cli.Flag = &cli.Int64SliceFlag{} @@ -98,12 +98,6 @@ func TestPathFlag_SatisfiesFlagInterface(t *testing.T) { _ = f.Names() } -func TestPathFlag_SatisfiesFmtStringerInterface(t *testing.T) { - var f fmt.Stringer = &cli.PathFlag{} - - _ = f.String() -} - func TestPathFlag_SatisfiesRequiredFlagInterface(t *testing.T) { var f cli.RequiredFlag = &cli.PathFlag{} @@ -116,6 +110,12 @@ func TestPathFlag_SatisfiesVisibleFlagInterface(t *testing.T) { _ = f.IsVisible() } +func TestPathFlag_SatisfiesFmtStringerInterface(t *testing.T) { + var f fmt.Stringer = &cli.PathFlag{} + + _ = f.String() +} + func TestStringSliceFlag_SatisfiesFlagInterface(t *testing.T) { var f cli.Flag = &cli.StringSliceFlag{} @@ -142,12 +142,6 @@ func TestTimestampFlag_SatisfiesFlagInterface(t *testing.T) { _ = f.Names() } -func TestTimestampFlag_SatisfiesFmtStringerInterface(t *testing.T) { - var f fmt.Stringer = &cli.TimestampFlag{} - - _ = f.String() -} - func TestTimestampFlag_SatisfiesRequiredFlagInterface(t *testing.T) { var f cli.RequiredFlag = &cli.TimestampFlag{} @@ -160,6 +154,12 @@ func TestTimestampFlag_SatisfiesVisibleFlagInterface(t *testing.T) { _ = f.IsVisible() } +func TestTimestampFlag_SatisfiesFmtStringerInterface(t *testing.T) { + var f fmt.Stringer = &cli.TimestampFlag{} + + _ = f.String() +} + func TestUint64SliceFlag_SatisfiesFlagInterface(t *testing.T) { var f cli.Flag = &cli.Uint64SliceFlag{} @@ -205,12 +205,6 @@ func TestBoolFlag_SatisfiesFlagInterface(t *testing.T) { _ = f.Names() } -func TestBoolFlag_SatisfiesFmtStringerInterface(t *testing.T) { - var f fmt.Stringer = &cli.BoolFlag{} - - _ = f.String() -} - func TestBoolFlag_SatisfiesRequiredFlagInterface(t *testing.T) { var f cli.RequiredFlag = &cli.BoolFlag{} @@ -223,6 +217,12 @@ func TestBoolFlag_SatisfiesVisibleFlagInterface(t *testing.T) { _ = f.IsVisible() } +func TestBoolFlag_SatisfiesFmtStringerInterface(t *testing.T) { + var f fmt.Stringer = &cli.BoolFlag{} + + _ = f.String() +} + func TestFloat64Flag_SatisfiesFlagInterface(t *testing.T) { var f cli.Flag = &cli.Float64Flag{} @@ -230,12 +230,6 @@ func TestFloat64Flag_SatisfiesFlagInterface(t *testing.T) { _ = f.Names() } -func TestFloat64Flag_SatisfiesFmtStringerInterface(t *testing.T) { - var f fmt.Stringer = &cli.Float64Flag{} - - _ = f.String() -} - func TestFloat64Flag_SatisfiesRequiredFlagInterface(t *testing.T) { var f cli.RequiredFlag = &cli.Float64Flag{} @@ -248,6 +242,12 @@ func TestFloat64Flag_SatisfiesVisibleFlagInterface(t *testing.T) { _ = 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{} @@ -255,12 +255,6 @@ func TestIntFlag_SatisfiesFlagInterface(t *testing.T) { _ = f.Names() } -func TestIntFlag_SatisfiesFmtStringerInterface(t *testing.T) { - var f fmt.Stringer = &cli.IntFlag{} - - _ = f.String() -} - func TestIntFlag_SatisfiesRequiredFlagInterface(t *testing.T) { var f cli.RequiredFlag = &cli.IntFlag{} @@ -273,6 +267,12 @@ func TestIntFlag_SatisfiesVisibleFlagInterface(t *testing.T) { _ = 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{} @@ -280,12 +280,6 @@ func TestInt64Flag_SatisfiesFlagInterface(t *testing.T) { _ = f.Names() } -func TestInt64Flag_SatisfiesFmtStringerInterface(t *testing.T) { - var f fmt.Stringer = &cli.Int64Flag{} - - _ = f.String() -} - func TestInt64Flag_SatisfiesRequiredFlagInterface(t *testing.T) { var f cli.RequiredFlag = &cli.Int64Flag{} @@ -298,6 +292,12 @@ func TestInt64Flag_SatisfiesVisibleFlagInterface(t *testing.T) { _ = 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{} @@ -305,12 +305,6 @@ func TestStringFlag_SatisfiesFlagInterface(t *testing.T) { _ = f.Names() } -func TestStringFlag_SatisfiesFmtStringerInterface(t *testing.T) { - var f fmt.Stringer = &cli.StringFlag{} - - _ = f.String() -} - func TestStringFlag_SatisfiesRequiredFlagInterface(t *testing.T) { var f cli.RequiredFlag = &cli.StringFlag{} @@ -323,6 +317,12 @@ func TestStringFlag_SatisfiesVisibleFlagInterface(t *testing.T) { _ = f.IsVisible() } +func TestStringFlag_SatisfiesFmtStringerInterface(t *testing.T) { + var f fmt.Stringer = &cli.StringFlag{} + + _ = f.String() +} + func TestDurationFlag_SatisfiesFlagInterface(t *testing.T) { var f cli.Flag = &cli.DurationFlag{} @@ -330,12 +330,6 @@ func TestDurationFlag_SatisfiesFlagInterface(t *testing.T) { _ = f.Names() } -func TestDurationFlag_SatisfiesFmtStringerInterface(t *testing.T) { - var f fmt.Stringer = &cli.DurationFlag{} - - _ = f.String() -} - func TestDurationFlag_SatisfiesRequiredFlagInterface(t *testing.T) { var f cli.RequiredFlag = &cli.DurationFlag{} @@ -348,6 +342,12 @@ func TestDurationFlag_SatisfiesVisibleFlagInterface(t *testing.T) { _ = f.IsVisible() } +func TestDurationFlag_SatisfiesFmtStringerInterface(t *testing.T) { + var f fmt.Stringer = &cli.DurationFlag{} + + _ = f.String() +} + func TestUintFlag_SatisfiesFlagInterface(t *testing.T) { var f cli.Flag = &cli.UintFlag{} @@ -355,12 +355,6 @@ func TestUintFlag_SatisfiesFlagInterface(t *testing.T) { _ = f.Names() } -func TestUintFlag_SatisfiesFmtStringerInterface(t *testing.T) { - var f fmt.Stringer = &cli.UintFlag{} - - _ = f.String() -} - func TestUintFlag_SatisfiesRequiredFlagInterface(t *testing.T) { var f cli.RequiredFlag = &cli.UintFlag{} @@ -373,6 +367,12 @@ func TestUintFlag_SatisfiesVisibleFlagInterface(t *testing.T) { _ = 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{} @@ -380,12 +380,6 @@ func TestUint64Flag_SatisfiesFlagInterface(t *testing.T) { _ = f.Names() } -func TestUint64Flag_SatisfiesFmtStringerInterface(t *testing.T) { - var f fmt.Stringer = &cli.Uint64Flag{} - - _ = f.String() -} - func TestUint64Flag_SatisfiesRequiredFlagInterface(t *testing.T) { var f cli.RequiredFlag = &cli.Uint64Flag{} @@ -398,4 +392,10 @@ func TestUint64Flag_SatisfiesVisibleFlagInterface(t *testing.T) { _ = f.IsVisible() } +func TestUint64Flag_SatisfiesFmtStringerInterface(t *testing.T) { + var f fmt.Stringer = &cli.Uint64Flag{} + + _ = f.String() +} + // vim:ro