Skip to content

Commit 8a6c85f

Browse files
authored
Merge pull request #409 from ShawnJeffersonWang/master
fix: correct argument length check in FlagSet.Parse
2 parents bca0664 + f9b6619 commit 8a6c85f

File tree

2 files changed

+7
-1
lines changed

2 files changed

+7
-1
lines changed

flag.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1156,7 +1156,7 @@ func (f *FlagSet) Parse(arguments []string) error {
11561156
}
11571157
f.parsed = true
11581158

1159-
if len(arguments) < 0 {
1159+
if len(arguments) == 0 {
11601160
return nil
11611161
}
11621162

flag_test.go

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -100,6 +100,12 @@ func TestEverything(t *testing.T) {
100100
}
101101
}
102102

103+
func TestNoArgument(t *testing.T) {
104+
if GetCommandLine().Parse([]string{}) != nil {
105+
t.Error("parse failed for empty argument list")
106+
}
107+
}
108+
103109
func TestUsage(t *testing.T) {
104110
called := false
105111
ResetForTesting(func() { called = true })

0 commit comments

Comments
 (0)