Skip to content

Commit

Permalink
Merge branch 'main' into main
Browse files Browse the repository at this point in the history
  • Loading branch information
dearchap committed Mar 29, 2024
2 parents 43da2b6 + 065ea5c commit ab284d7
Show file tree
Hide file tree
Showing 9 changed files with 73 additions and 159 deletions.
50 changes: 0 additions & 50 deletions .github/workflows/frogbot-scan-and-fix.yml

This file was deleted.

102 changes: 0 additions & 102 deletions .github/workflows/frogbot-scan-pr.yml

This file was deleted.

5 changes: 3 additions & 2 deletions args.go
Original file line number Diff line number Diff line change
Expand Up @@ -118,7 +118,7 @@ func (a *ArgumentBase[T, C, VC]) Parse(s []string) ([]string, error) {
}
values = append(values, value.Get().(T))
count++
if count >= a.Max {
if count >= a.Max && a.Max > -1 {
break
}
}
Expand All @@ -128,7 +128,7 @@ func (a *ArgumentBase[T, C, VC]) Parse(s []string) ([]string, error) {

if a.Values == nil {
a.Values = &values
} else {
} else if count > 0 {
*a.Values = values
}

Expand All @@ -139,6 +139,7 @@ func (a *ArgumentBase[T, C, VC]) Parse(s []string) ([]string, error) {
*a.Destination = t
}
}

return s[count:], nil
}

Expand Down
46 changes: 46 additions & 0 deletions args_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -174,3 +174,49 @@ func TestSingleOptionalArg(t *testing.T) {
require.NoError(t, cmd.Run(context.Background(), []string{"foo", "zbar"}))
require.Equal(t, "zbar", s1)
}

func TestUnboundedArgs(t *testing.T) {
arg := &StringArg{
Min: 0,
Max: -1,
}
tests := []struct {
name string
args []string
values []string
expected []string
}{
{
name: "cmd accepts no args",
args: []string{"foo"},
expected: nil,
},
{
name: "cmd uses given args",
args: []string{"foo", "bar", "baz"},
expected: []string{"bar", "baz"},
},
{
name: "cmd uses default values",
args: []string{"foo"},
values: []string{"zbar", "zbaz"},
expected: []string{"zbar", "zbaz"},
},
{
name: "given args override default values",
args: []string{"foo", "bar", "baz"},
values: []string{"zbar", "zbaz"},
expected: []string{"bar", "baz"},
},
}

cmd := buildMinimalTestCommand()
cmd.Arguments = []Argument{arg}
for _, test := range tests {
t.Run(test.name, func(t *testing.T) {
arg.Values = &test.values
require.NoError(t, cmd.Run(context.Background(), test.args))
require.Equal(t, test.expected, *arg.Values)
})
}
}
12 changes: 10 additions & 2 deletions category.go
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,11 @@ func newFlagCategoriesFromFlags(fs []Flag) FlagCategories {

for _, fl := range fs {
if cf, ok := fl.(CategorizableFlag); ok {
if cat := cf.GetCategory(); cat != "" {
visible := false
if vf, ok := fl.(VisibleFlag); ok {
visible = vf.IsVisible()
}
if cat := cf.GetCategory(); cat != "" && visible {
fc.AddFlag(cat, fl)
categorized = true
}
Expand All @@ -115,7 +119,11 @@ func newFlagCategoriesFromFlags(fs []Flag) FlagCategories {
if categorized {
for _, fl := range fs {
if cf, ok := fl.(CategorizableFlag); ok {
if cf.GetCategory() == "" {
visible := false
if vf, ok := fl.(VisibleFlag); ok {
visible = vf.IsVisible()
}
if cf.GetCategory() == "" && visible {
fc.AddFlag("", fl)
}
}
Expand Down
9 changes: 9 additions & 0 deletions command_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -518,11 +518,20 @@ func TestCommand_VisibleFlagCategories(t *testing.T) {
&StringFlag{
Name: "strd", // no category set
},
&StringFlag{
Name: "strd1", // no category set and also hidden
Hidden: true,
},
&IntFlag{
Name: "intd",
Aliases: []string{"altd1", "altd2"},
Category: "cat1",
},
&StringFlag{
Name: "sfd",
Category: "cat2", // category set and hidden
Hidden: true,
},
},
MutuallyExclusiveFlags: []MutuallyExclusiveFlags{{
Category: "cat2",
Expand Down
2 changes: 1 addition & 1 deletion flag.go
Original file line number Diff line number Diff line change
Expand Up @@ -137,7 +137,7 @@ type DocGenerationFlag interface {
GetEnvVars() []string
}

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

Expand Down
3 changes: 2 additions & 1 deletion godoc-current.txt
Original file line number Diff line number Diff line change
Expand Up @@ -567,7 +567,8 @@ type DocGenerationMultiValueFlag interface {
// IsMultiValueFlag returns true for flags that can be given multiple times.
IsMultiValueFlag() bool
}
DocGenerationSliceFlag extends DocGenerationFlag for slice/map based flags.
DocGenerationMultiValueFlag extends DocGenerationFlag for slice/map based
flags.

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

Expand Down
3 changes: 2 additions & 1 deletion testdata/godoc-v3.x.txt
Original file line number Diff line number Diff line change
Expand Up @@ -567,7 +567,8 @@ type DocGenerationMultiValueFlag interface {
// IsMultiValueFlag returns true for flags that can be given multiple times.
IsMultiValueFlag() bool
}
DocGenerationSliceFlag extends DocGenerationFlag for slice/map based flags.
DocGenerationMultiValueFlag extends DocGenerationFlag for slice/map based
flags.

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

Expand Down

0 comments on commit ab284d7

Please sign in to comment.