Skip to content

Commit

Permalink
Merge pull request #1615 from dearchap/rename_is_slice_value
Browse files Browse the repository at this point in the history
  • Loading branch information
dearchap authored Dec 6, 2022
2 parents d56fe25 + 7a9c3db commit 1510efe
Show file tree
Hide file tree
Showing 5 changed files with 27 additions and 23 deletions.
Binary file added cmd/urfave-cli-genflags/urfave-cli-genflags
Binary file not shown.
12 changes: 6 additions & 6 deletions flag.go
Original file line number Diff line number Diff line change
Expand Up @@ -141,12 +141,12 @@ type DocGenerationFlag interface {
GetEnvVars() []string
}

// DocGenerationSliceFlag extends DocGenerationFlag for slice-based flags.
type DocGenerationSliceFlag interface {
// DocGenerationSliceFlag extends DocGenerationFlag for slice/map based flags.
type DocGenerationMultiValueFlag interface {
DocGenerationFlag

// IsSliceFlag returns true for flags that can be given multiple times.
IsSliceFlag() bool
// IsMultiValueFlag returns true for flags that can be given multiple times.
IsMultiValueFlag() bool
}

// Countable is an interface to enable detection of flag values which support
Expand Down Expand Up @@ -357,8 +357,8 @@ func stringifyFlag(f Flag) string {
usageWithDefault := strings.TrimSpace(usage + defaultValueString)

pn := prefixedNames(df.Names(), placeholder)
sliceFlag, ok := f.(DocGenerationSliceFlag)
if ok && sliceFlag.IsSliceFlag() {
sliceFlag, ok := f.(DocGenerationMultiValueFlag)
if ok && sliceFlag.IsMultiValueFlag() {
pn = pn + " [ " + pn + " ]"
}

Expand Down
8 changes: 5 additions & 3 deletions flag_impl.go
Original file line number Diff line number Diff line change
Expand Up @@ -189,10 +189,12 @@ func (f *FlagBase[T, C, V]) RunAction(ctx *Context) error {
return nil
}

// IsSliceFlag returns true if the value type T is of kind slice
func (f *FlagBase[T, C, VC]) IsSliceFlag() bool {
// IsMultiValueFlag returns true if the value type T can take multiple
// values from cmd line. This is true for slice and map type flags
func (f *FlagBase[T, C, VC]) IsMultiValueFlag() bool {
// TBD how to specify
return reflect.TypeOf(f.Value).Kind() == reflect.Slice
return reflect.TypeOf(f.Value).Kind() == reflect.Slice ||
reflect.TypeOf(f.Value).Kind() == reflect.Map
}

// IsPersistent returns true if flag needs to be persistent across subcommands
Expand Down
15 changes: 8 additions & 7 deletions godoc-current.txt
Original file line number Diff line number Diff line change
Expand Up @@ -693,13 +693,13 @@ type DocGenerationFlag interface {
DocGenerationFlag is an interface that allows documentation generation for
the flag

type DocGenerationSliceFlag interface {
type DocGenerationMultiValueFlag interface {
DocGenerationFlag

// IsSliceFlag returns true for flags that can be given multiple times.
IsSliceFlag() bool
// IsMultiValueFlag returns true for flags that can be given multiple times.
IsMultiValueFlag() bool
}
DocGenerationSliceFlag extends DocGenerationFlag for slice-based flags.
DocGenerationSliceFlag extends DocGenerationFlag for slice/map based flags.

type DurationFlag = FlagBase[time.Duration, NoConfig, durationValue]

Expand Down Expand Up @@ -827,6 +827,10 @@ func (f *FlagBase[T, C, V]) GetValue() string
GetValue returns the flags value as string representation and an empty
string if the flag takes no value at all.

func (f *FlagBase[T, C, VC]) IsMultiValueFlag() bool
IsMultiValueFlag returns true if the value type T can take multiple values
from cmd line. This is true for slice and map type flags

func (f *FlagBase[T, C, VC]) IsPersistent() bool
IsPersistent returns true if flag needs to be persistent across subcommands

Expand All @@ -836,9 +840,6 @@ func (f *FlagBase[T, C, V]) IsRequired() bool
func (f *FlagBase[T, C, V]) IsSet() bool
IsSet returns whether or not the flag has been set through env or file

func (f *FlagBase[T, C, VC]) IsSliceFlag() bool
IsSliceFlag returns true if the value type T is of kind slice

func (f *FlagBase[T, C, V]) IsVisible() bool
IsVisible returns true if the flag is not hidden, otherwise false

Expand Down
15 changes: 8 additions & 7 deletions testdata/godoc-v3.x.txt
Original file line number Diff line number Diff line change
Expand Up @@ -693,13 +693,13 @@ type DocGenerationFlag interface {
DocGenerationFlag is an interface that allows documentation generation for
the flag

type DocGenerationSliceFlag interface {
type DocGenerationMultiValueFlag interface {
DocGenerationFlag

// IsSliceFlag returns true for flags that can be given multiple times.
IsSliceFlag() bool
// IsMultiValueFlag returns true for flags that can be given multiple times.
IsMultiValueFlag() bool
}
DocGenerationSliceFlag extends DocGenerationFlag for slice-based flags.
DocGenerationSliceFlag extends DocGenerationFlag for slice/map based flags.

type DurationFlag = FlagBase[time.Duration, NoConfig, durationValue]

Expand Down Expand Up @@ -827,6 +827,10 @@ func (f *FlagBase[T, C, V]) GetValue() string
GetValue returns the flags value as string representation and an empty
string if the flag takes no value at all.

func (f *FlagBase[T, C, VC]) IsMultiValueFlag() bool
IsMultiValueFlag returns true if the value type T can take multiple values
from cmd line. This is true for slice and map type flags

func (f *FlagBase[T, C, VC]) IsPersistent() bool
IsPersistent returns true if flag needs to be persistent across subcommands

Expand All @@ -836,9 +840,6 @@ func (f *FlagBase[T, C, V]) IsRequired() bool
func (f *FlagBase[T, C, V]) IsSet() bool
IsSet returns whether or not the flag has been set through env or file

func (f *FlagBase[T, C, VC]) IsSliceFlag() bool
IsSliceFlag returns true if the value type T is of kind slice

func (f *FlagBase[T, C, V]) IsVisible() bool
IsVisible returns true if the flag is not hidden, otherwise false

Expand Down

0 comments on commit 1510efe

Please sign in to comment.