From 47d325e64f5d57c3c395a463e77a834d8134c643 Mon Sep 17 00:00:00 2001 From: Edelweiss-Snow <1759279542@qq.com> Date: Fri, 28 Oct 2022 19:49:06 +0800 Subject: [PATCH 1/3] Feature:(issue_1550):Add support Int64Slice by read toml config file Feature:(issue_1550):add test flag test function --- altsrc/flag.go | 31 +++++++++++++++++++++++++++++++ altsrc/flag_test.go | 23 +++++++++++++++++++++++ altsrc/input_source_context.go | 1 + altsrc/json_source_context.go | 23 +++++++++++++++++++++++ altsrc/map_input_source.go | 29 +++++++++++++++++++++++++++++ altsrc/map_input_source_test.go | 11 +++++++++++ 6 files changed, 118 insertions(+) diff --git a/altsrc/flag.go b/altsrc/flag.go index 8697b29d0a..d8256d7605 100644 --- a/altsrc/flag.go +++ b/altsrc/flag.go @@ -148,6 +148,37 @@ func (f *IntSliceFlag) ApplyInputSourceValue(cCtx *cli.Context, isc InputSourceC return nil } +// ApplyInputSourceValue applies a Int64Slice value if required +func (f *Int64SliceFlag) ApplyInputSourceValue(cCtx *cli.Context, isc InputSourceContext) error { + if f.set == nil || cCtx.IsSet(f.Name) || isEnvVarSet(f.EnvVars) { + return nil + } + for _, name := range f.Int64SliceFlag.Names() { + if !isc.isSet(name) { + continue + } + value, err := isc.Int64Slice(name) + if err != nil { + return err + } + if value == nil { + continue + } + var sliceValue = *(cli.NewInt64Slice(value...)) + for _, n := range f.Names() { + underlyingFlag := f.set.Lookup(n) + if underlyingFlag == nil { + continue + } + underlyingFlag.Value = &sliceValue + } + if f.Destination != nil { + f.Destination.Set(sliceValue.Serialize()) + } + } + return nil +} + // ApplyInputSourceValue applies a Bool value to the flagSet if required func (f *BoolFlag) ApplyInputSourceValue(cCtx *cli.Context, isc InputSourceContext) error { if f.set == nil || cCtx.IsSet(f.Name) || isEnvVarSet(f.EnvVars) { diff --git a/altsrc/flag_test.go b/altsrc/flag_test.go index caf62d87f2..ad66dab43c 100644 --- a/altsrc/flag_test.go +++ b/altsrc/flag_test.go @@ -257,6 +257,29 @@ func TestIntSliceApplyInputSourceMethodEnvVarSet(t *testing.T) { refute(t, c.IntSlice("test"), []int{3, 4}) } +func TestInt64SliceFlagApplyInputSourceValue(t *testing.T) { + dest := cli.NewInt64Slice() + tis := testApplyInputSource{ + Flag: NewInt64SliceFlag(&cli.Int64SliceFlag{Name: "test", Destination: dest}), + FlagName: "test", + MapValue: []interface{}{int64(1), int64(2)}, + } + c := runTest(t, tis) + expect(t, c.Int64Slice("test"), []int64{1, 2}) + expect(t, dest.Value(), []int64{1, 2}) + + // reset dest + dest = cli.NewInt64Slice() + tis = testApplyInputSource{ + Flag: NewInt64SliceFlag(&cli.Int64SliceFlag{Name: "test", Destination: dest}), + FlagName: "test", + MapValue: []interface{}{int64(1), int64(2)}, + } + c = runRacyTest(t, tis) + refute(t, c.IntSlice("test"), []int64{1, 2}) + refute(t, dest.Value(), []int64{1, 2}) +} + func TestBoolApplyInputSourceMethodSet(t *testing.T) { tis := testApplyInputSource{ Flag: NewBoolFlag(&cli.BoolFlag{Name: "test"}), diff --git a/altsrc/input_source_context.go b/altsrc/input_source_context.go index d743253050..24579d16a9 100644 --- a/altsrc/input_source_context.go +++ b/altsrc/input_source_context.go @@ -20,6 +20,7 @@ type InputSourceContext interface { String(name string) (string, error) StringSlice(name string) ([]string, error) IntSlice(name string) ([]int, error) + Int64Slice(name string) ([]int64, error) Generic(name string) (cli.Generic, error) Bool(name string) (bool, error) diff --git a/altsrc/json_source_context.go b/altsrc/json_source_context.go index 168b6dade0..ac0532076c 100644 --- a/altsrc/json_source_context.go +++ b/altsrc/json_source_context.go @@ -160,6 +160,29 @@ func (x *jsonSource) IntSlice(name string) ([]int, error) { } } +func (x *jsonSource) Int64Slice(name string) ([]int64, error) { + i, err := x.getValue(name) + if err != nil { + return nil, err + } + switch v := i.(type) { + default: + return nil, fmt.Errorf("unexpected type %T for %q", i, name) + case []int64: + return v, nil + case []interface{}: + c := []int64{} + for _, s := range v { + if i2, ok := s.(int64); ok { + c = append(c, i2) + } else { + return c, fmt.Errorf("unexpected item type %T in %T for %q", s, c, name) + } + } + return c, nil + } +} + func (x *jsonSource) Generic(name string) (cli.Generic, error) { i, err := x.getValue(name) if err != nil { diff --git a/altsrc/map_input_source.go b/altsrc/map_input_source.go index 07de00fcc6..2505b270eb 100644 --- a/altsrc/map_input_source.go +++ b/altsrc/map_input_source.go @@ -207,6 +207,35 @@ func (fsm *MapInputSource) IntSlice(name string) ([]int, error) { return intSlice, nil } +// Int64Slice returns an []int64 from the map if it exists otherwise returns nil +func (fsm *MapInputSource) Int64Slice(name string) ([]int64, error) { + otherGenericValue, exists := fsm.valueMap[name] + if !exists { + otherGenericValue, exists = nestedVal(name, fsm.valueMap) + if !exists { + return nil, nil + } + } + + otherValue, isType := otherGenericValue.([]interface{}) + if !isType { + return nil, incorrectTypeForFlagError(name, "[]interface{}", otherGenericValue) + } + + var int64Slice = make([]int64, 0, len(otherValue)) + for i, v := range otherValue { + int64Value, isType := v.(int64) + + if !isType { + return nil, incorrectTypeForFlagError(fmt.Sprintf("%s[%d]", name, i), "int", v) + } + + int64Slice = append(int64Slice, int64Value) + } + + return int64Slice, nil +} + // Generic returns an cli.Generic from the map if it exists otherwise returns nil func (fsm *MapInputSource) Generic(name string) (cli.Generic, error) { otherGenericValue, exists := fsm.valueMap[name] diff --git a/altsrc/map_input_source_test.go b/altsrc/map_input_source_test.go index b90f796b30..cf399b5354 100644 --- a/altsrc/map_input_source_test.go +++ b/altsrc/map_input_source_test.go @@ -22,3 +22,14 @@ func TestMapDuration(t *testing.T) { _, err = inputSource.Duration("duration_of_int_type") refute(t, nil, err) } + +func TestMapInputSource_Int64Slice(t *testing.T) { + inputSource := NewMapInputSource( + "test", + map[interface{}]interface{}{ + "test_num": []interface{}{int64(1), int64(2), int64(3)}, + }) + d, err := inputSource.Int64Slice("test_num") + expect(t, []int64{1, 2, 3}, d) + expect(t, nil, err) +} From 76769bafc7883e25a50ef8a7b0cddaa0813572f8 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E4=B8=87=E9=9F=AC?= Date: Mon, 31 Oct 2022 11:46:40 +0800 Subject: [PATCH 2/3] make v2approve --- godoc-current.txt | 54 +++++++++++++++++++++++------------------ testdata/godoc-v2.x.txt | 54 +++++++++++++++++++++++------------------ 2 files changed, 62 insertions(+), 46 deletions(-) diff --git a/godoc-current.txt b/godoc-current.txt index fadb7f8629..11082c087a 100644 --- a/godoc-current.txt +++ b/godoc-current.txt @@ -55,8 +55,8 @@ GLOBAL OPTIONS:{{template "visibleFlagTemplate" .}}{{end}}{{if .Copyright}} COPYRIGHT: {{template "copyrightTemplate" .}}{{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: @@ -184,9 +184,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 @@ -355,14 +355,14 @@ func (a *App) RunAsSubcommand(ctx *Context) (err error) Deprecated: use App.Run or App.RunContext 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 @@ -841,9 +841,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 overriding 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 overriding the ExitErrHandler function on an App or the package-global OsExiter function. func NewExitError(message interface{}, exitCode int) ExitCoder @@ -1532,8 +1532,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 @@ -1620,8 +1620,8 @@ type RequiredFlag interface { 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 + 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 type Serializer interface { @@ -1634,9 +1634,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 @@ -2312,9 +2312,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 @@ -2432,6 +2432,7 @@ type InputSourceContext interface { String(name string) (string, error) StringSlice(name string) ([]string, error) IntSlice(name string) ([]int, error) + Int64Slice(name string) ([]int64, error) Generic(name string) (cli.Generic, error) Bool(name string) (bool, error) @@ -2489,6 +2490,9 @@ func (f *Int64SliceFlag) Apply(set *flag.FlagSet) error Apply saves the flagSet for later usage calls, then calls the wrapped Int64SliceFlag.Apply +func (f *Int64SliceFlag) ApplyInputSourceValue(cCtx *cli.Context, isc InputSourceContext) error + ApplyInputSourceValue applies a Int64Slice value if required + type IntFlag struct { *cli.IntFlag // Has unexported fields. @@ -2549,6 +2553,10 @@ func (fsm *MapInputSource) Generic(name string) (cli.Generic, error) func (fsm *MapInputSource) Int(name string) (int, error) Int returns an int from the map if it exists otherwise returns 0 +func (fsm *MapInputSource) Int64Slice(name string) ([]int64, error) + Int64Slice returns an []int64 from the map if it exists otherwise returns + nil + func (fsm *MapInputSource) IntSlice(name string) ([]int, error) IntSlice returns an []int from the map if it exists otherwise returns nil diff --git a/testdata/godoc-v2.x.txt b/testdata/godoc-v2.x.txt index fadb7f8629..11082c087a 100644 --- a/testdata/godoc-v2.x.txt +++ b/testdata/godoc-v2.x.txt @@ -55,8 +55,8 @@ GLOBAL OPTIONS:{{template "visibleFlagTemplate" .}}{{end}}{{if .Copyright}} COPYRIGHT: {{template "copyrightTemplate" .}}{{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: @@ -184,9 +184,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 @@ -355,14 +355,14 @@ func (a *App) RunAsSubcommand(ctx *Context) (err error) Deprecated: use App.Run or App.RunContext 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 @@ -841,9 +841,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 overriding 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 overriding the ExitErrHandler function on an App or the package-global OsExiter function. func NewExitError(message interface{}, exitCode int) ExitCoder @@ -1532,8 +1532,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 @@ -1620,8 +1620,8 @@ type RequiredFlag interface { 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 + 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 type Serializer interface { @@ -1634,9 +1634,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 @@ -2312,9 +2312,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 @@ -2432,6 +2432,7 @@ type InputSourceContext interface { String(name string) (string, error) StringSlice(name string) ([]string, error) IntSlice(name string) ([]int, error) + Int64Slice(name string) ([]int64, error) Generic(name string) (cli.Generic, error) Bool(name string) (bool, error) @@ -2489,6 +2490,9 @@ func (f *Int64SliceFlag) Apply(set *flag.FlagSet) error Apply saves the flagSet for later usage calls, then calls the wrapped Int64SliceFlag.Apply +func (f *Int64SliceFlag) ApplyInputSourceValue(cCtx *cli.Context, isc InputSourceContext) error + ApplyInputSourceValue applies a Int64Slice value if required + type IntFlag struct { *cli.IntFlag // Has unexported fields. @@ -2549,6 +2553,10 @@ func (fsm *MapInputSource) Generic(name string) (cli.Generic, error) func (fsm *MapInputSource) Int(name string) (int, error) Int returns an int from the map if it exists otherwise returns 0 +func (fsm *MapInputSource) Int64Slice(name string) ([]int64, error) + Int64Slice returns an []int64 from the map if it exists otherwise returns + nil + func (fsm *MapInputSource) IntSlice(name string) ([]int, error) IntSlice returns an []int from the map if it exists otherwise returns nil From b11badc45cc11687fec4645292294ba1fc4152fb Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E4=B8=87=E9=9F=AC?= Date: Mon, 31 Oct 2022 12:07:56 +0800 Subject: [PATCH 3/3] make v2approve --- godoc-current.txt | 46 ++++++++++++++++++++--------------------- testdata/godoc-v2.x.txt | 46 ++++++++++++++++++++--------------------- 2 files changed, 46 insertions(+), 46 deletions(-) diff --git a/godoc-current.txt b/godoc-current.txt index 11082c087a..a0def3587a 100644 --- a/godoc-current.txt +++ b/godoc-current.txt @@ -55,8 +55,8 @@ GLOBAL OPTIONS:{{template "visibleFlagTemplate" .}}{{end}}{{if .Copyright}} COPYRIGHT: {{template "copyrightTemplate" .}}{{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: @@ -184,9 +184,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 @@ -355,14 +355,14 @@ func (a *App) RunAsSubcommand(ctx *Context) (err error) Deprecated: use App.Run or App.RunContext 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 @@ -841,9 +841,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 overriding 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 overriding the ExitErrHandler function on an App or the package-global OsExiter function. func NewExitError(message interface{}, exitCode int) ExitCoder @@ -1532,8 +1532,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 @@ -1620,8 +1620,8 @@ type RequiredFlag interface { 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 + 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 type Serializer interface { @@ -1634,9 +1634,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 @@ -2312,9 +2312,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/testdata/godoc-v2.x.txt b/testdata/godoc-v2.x.txt index 11082c087a..a0def3587a 100644 --- a/testdata/godoc-v2.x.txt +++ b/testdata/godoc-v2.x.txt @@ -55,8 +55,8 @@ GLOBAL OPTIONS:{{template "visibleFlagTemplate" .}}{{end}}{{if .Copyright}} COPYRIGHT: {{template "copyrightTemplate" .}}{{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: @@ -184,9 +184,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 @@ -355,14 +355,14 @@ func (a *App) RunAsSubcommand(ctx *Context) (err error) Deprecated: use App.Run or App.RunContext 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 @@ -841,9 +841,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 overriding 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 overriding the ExitErrHandler function on an App or the package-global OsExiter function. func NewExitError(message interface{}, exitCode int) ExitCoder @@ -1532,8 +1532,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 @@ -1620,8 +1620,8 @@ type RequiredFlag interface { 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 + 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 type Serializer interface { @@ -1634,9 +1634,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 @@ -2312,9 +2312,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