Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Cleanup: Rename IsSliceValue to IsMultiValue #1615

Merged
merged 1 commit into from
Dec 6, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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