diff --git a/internal/flag/set.go b/internal/flag/set.go index 17f4409..379603b 100644 --- a/internal/flag/set.go +++ b/internal/flag/set.go @@ -273,7 +273,6 @@ func (s *Set) parseLongFlag(long string, rest []string) (remaining []string, err return rest[1:], nil default: // --flag (value was required) - // Do we ever hit this? Idk when a flag would be required return nil, fmt.Errorf("flag --%s requires an argument", name) } } diff --git a/internal/flag/set_test.go b/internal/flag/set_test.go index 5832c3f..485c180 100644 --- a/internal/flag/set_test.go +++ b/internal/flag/set_test.go @@ -425,6 +425,33 @@ func TestParse(t *testing.T) { args: []string{"--count", "1"}, wantErr: false, }, + { + name: "valid long missing value", + newSet: func(t *testing.T) *flag.Set { + t.Helper() + set := flag.NewSet() + f, err := flag.New(new(int), "count", 'c', 0, "Count something") + test.Ok(t, err) + + err = flag.AddToSet(set, f) + test.Ok(t, err) + + return set + }, + test: func(t *testing.T, set *flag.Set) { + t.Helper() + entry, exists := set.Get("count") + test.True(t, exists) + + test.Equal(t, entry.Value.Type(), "int") + test.Equal(t, entry.Value.String(), "0") + + test.EqualFunc(t, set.Args(), nil, slices.Equal) + }, + args: []string{"--count"}, // Count needs an argument + wantErr: true, + errMsg: "flag --count requires an argument", + }, { name: "valid long value with args", newSet: func(t *testing.T) *flag.Set {