Skip to content

Commit

Permalink
Merge branch 'main' into issue_1505
Browse files Browse the repository at this point in the history
  • Loading branch information
dearchap committed Oct 6, 2022
2 parents 194ed2b + 8f469ab commit 86809ce
Show file tree
Hide file tree
Showing 5 changed files with 105 additions and 0 deletions.
2 changes: 2 additions & 0 deletions .github/workflows/cli.yml
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,8 @@ jobs:
GFLAGS: -tags urfave_cli_no_docs
- run: make check-binary-size
- run: make yamlfmt
- 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'
run: make v2diff
Expand Down
4 changes: 4 additions & 0 deletions flag_generic.go
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,10 @@ func (f *GenericFlag) Apply(set *flag.FlagSet) error {
}

for _, name := range f.Names() {
if f.Destination != nil {
set.Var(f.Destination, name, f.Usage)
continue
}
set.Var(f.Value, name, f.Usage)
}

Expand Down
47 changes: 47 additions & 0 deletions flag_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -2724,6 +2724,53 @@ func TestParseGeneric(t *testing.T) {
}).Run([]string{"run", "-s", "10,20"})
}

type genericType struct {
s []string
}

func (g *genericType) Set(value string) error {
g.s = strings.Split(value, "-")
return nil
}

func (g *genericType) String() string {
return strings.Join(g.s, "-")
}

func TestParseDestinationGeneric(t *testing.T) {
expectedString := "abc1-123d"
expectedGeneric := &genericType{[]string{"abc1", "123d"}}
dest := &genericType{}

_ = (&App{
Flags: []Flag{
&GenericFlag{
Name: "dest",
Destination: dest,
},
},
Action: func(ctx *Context) error {

if !reflect.DeepEqual(dest, expectedGeneric) {
t.Errorf(
"expected destination generic: %+v, actual: %+v",
expectedGeneric,
dest,
)
}

if dest.String() != expectedString {
t.Errorf(
"expected destination string: %s, actual: %s",
expectedString,
dest.String(),
)
}
return nil
},
}).Run([]string{"run", "--dest", expectedString})
}

func TestParseGenericFromEnv(t *testing.T) {
defer resetEnv(os.Environ())
os.Clearenv()
Expand Down
26 changes: 26 additions & 0 deletions godoc-current.txt
Original file line number Diff line number Diff line change
Expand Up @@ -740,6 +740,14 @@ type DocGenerationFlag interface {
DocGenerationFlag is an interface that allows documentation generation for
the flag

type DocGenerationSliceFlag interface {
DocGenerationFlag

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

type DurationFlag struct {
Name string

Expand Down Expand Up @@ -1058,6 +1066,9 @@ func (f *Float64SliceFlag) IsRequired() bool
func (f *Float64SliceFlag) IsSet() bool
IsSet returns whether or not the flag has been set through env or file

func (f *Float64SliceFlag) IsSliceFlag() bool
IsSliceFlag implements DocGenerationSliceFlag.

func (f *Float64SliceFlag) IsVisible() bool
IsVisible returns true if the flag is not hidden, otherwise false

Expand Down Expand Up @@ -1293,6 +1304,9 @@ func (f *Int64SliceFlag) IsRequired() bool
func (f *Int64SliceFlag) IsSet() bool
IsSet returns whether or not the flag has been set through env or file

func (f *Int64SliceFlag) IsSliceFlag() bool
IsSliceFlag implements DocGenerationSliceFlag.

func (f *Int64SliceFlag) IsVisible() bool
IsVisible returns true if the flag is not hidden, otherwise false

Expand Down Expand Up @@ -1458,6 +1472,9 @@ func (f *IntSliceFlag) IsRequired() bool
func (f *IntSliceFlag) IsSet() bool
IsSet returns whether or not the flag has been set through env or file

func (f *IntSliceFlag) IsSliceFlag() bool
IsSliceFlag implements DocGenerationSliceFlag.

func (f *IntSliceFlag) IsVisible() bool
IsVisible returns true if the flag is not hidden, otherwise false

Expand Down Expand Up @@ -1797,6 +1814,9 @@ func (f *StringSliceFlag) IsRequired() bool
func (f *StringSliceFlag) IsSet() bool
IsSet returns whether or not the flag has been set through env or file

func (f *StringSliceFlag) IsSliceFlag() bool
IsSliceFlag implements DocGenerationSliceFlag.

func (f *StringSliceFlag) IsVisible() bool
IsVisible returns true if the flag is not hidden, otherwise false

Expand Down Expand Up @@ -2058,6 +2078,9 @@ func (f *Uint64SliceFlag) IsRequired() bool
func (f *Uint64SliceFlag) IsSet() bool
IsSet returns whether or not the flag has been set through env or file

func (f *Uint64SliceFlag) IsSliceFlag() bool
IsSliceFlag implements DocGenerationSliceFlag.

func (f *Uint64SliceFlag) IsVisible() bool
IsVisible returns true if the flag is not hidden, otherwise false

Expand Down Expand Up @@ -2214,6 +2237,9 @@ func (f *UintSliceFlag) IsRequired() bool
func (f *UintSliceFlag) IsSet() bool
IsSet returns whether or not the flag has been set through env or file

func (f *UintSliceFlag) IsSliceFlag() bool
IsSliceFlag implements DocGenerationSliceFlag.

func (f *UintSliceFlag) IsVisible() bool
IsVisible returns true if the flag is not hidden, otherwise false

Expand Down
26 changes: 26 additions & 0 deletions testdata/godoc-v2.x.txt
Original file line number Diff line number Diff line change
Expand Up @@ -740,6 +740,14 @@ type DocGenerationFlag interface {
DocGenerationFlag is an interface that allows documentation generation for
the flag

type DocGenerationSliceFlag interface {
DocGenerationFlag

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

type DurationFlag struct {
Name string

Expand Down Expand Up @@ -1058,6 +1066,9 @@ func (f *Float64SliceFlag) IsRequired() bool
func (f *Float64SliceFlag) IsSet() bool
IsSet returns whether or not the flag has been set through env or file

func (f *Float64SliceFlag) IsSliceFlag() bool
IsSliceFlag implements DocGenerationSliceFlag.

func (f *Float64SliceFlag) IsVisible() bool
IsVisible returns true if the flag is not hidden, otherwise false

Expand Down Expand Up @@ -1293,6 +1304,9 @@ func (f *Int64SliceFlag) IsRequired() bool
func (f *Int64SliceFlag) IsSet() bool
IsSet returns whether or not the flag has been set through env or file

func (f *Int64SliceFlag) IsSliceFlag() bool
IsSliceFlag implements DocGenerationSliceFlag.

func (f *Int64SliceFlag) IsVisible() bool
IsVisible returns true if the flag is not hidden, otherwise false

Expand Down Expand Up @@ -1458,6 +1472,9 @@ func (f *IntSliceFlag) IsRequired() bool
func (f *IntSliceFlag) IsSet() bool
IsSet returns whether or not the flag has been set through env or file

func (f *IntSliceFlag) IsSliceFlag() bool
IsSliceFlag implements DocGenerationSliceFlag.

func (f *IntSliceFlag) IsVisible() bool
IsVisible returns true if the flag is not hidden, otherwise false

Expand Down Expand Up @@ -1797,6 +1814,9 @@ func (f *StringSliceFlag) IsRequired() bool
func (f *StringSliceFlag) IsSet() bool
IsSet returns whether or not the flag has been set through env or file

func (f *StringSliceFlag) IsSliceFlag() bool
IsSliceFlag implements DocGenerationSliceFlag.

func (f *StringSliceFlag) IsVisible() bool
IsVisible returns true if the flag is not hidden, otherwise false

Expand Down Expand Up @@ -2058,6 +2078,9 @@ func (f *Uint64SliceFlag) IsRequired() bool
func (f *Uint64SliceFlag) IsSet() bool
IsSet returns whether or not the flag has been set through env or file

func (f *Uint64SliceFlag) IsSliceFlag() bool
IsSliceFlag implements DocGenerationSliceFlag.

func (f *Uint64SliceFlag) IsVisible() bool
IsVisible returns true if the flag is not hidden, otherwise false

Expand Down Expand Up @@ -2214,6 +2237,9 @@ func (f *UintSliceFlag) IsRequired() bool
func (f *UintSliceFlag) IsSet() bool
IsSet returns whether or not the flag has been set through env or file

func (f *UintSliceFlag) IsSliceFlag() bool
IsSliceFlag implements DocGenerationSliceFlag.

func (f *UintSliceFlag) IsVisible() bool
IsVisible returns true if the flag is not hidden, otherwise false

Expand Down

0 comments on commit 86809ce

Please sign in to comment.