aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorTomas Aschan <[email protected]>2025-06-01 11:27:42 +0200
committerGitHub <[email protected]>2025-06-01 11:27:42 +0200
commit8a6c85f2ae488081f953744f9edc414bac10ee45 (patch)
tree67d437afa7187f8a88e5bce056f48dc9d0eff667
parentbca0664b6991016400b98ac29aae5a73f926bd71 (diff)
parentf9b6619ed0e0d771f7812fea23cd8b514faf2b2d (diff)
Merge pull request #409 from ShawnJeffersonWang/master
fix: correct argument length check in FlagSet.Parse
-rw-r--r--flag.go2
-rw-r--r--flag_test.go6
2 files changed, 7 insertions, 1 deletions
diff --git a/flag.go b/flag.go
index 64d268a..0b5be7a 100644
--- a/flag.go
+++ b/flag.go
@@ -1156,7 +1156,7 @@ func (f *FlagSet) Parse(arguments []string) error {
}
f.parsed = true
- if len(arguments) < 0 {
+ if len(arguments) == 0 {
return nil
}
diff --git a/flag_test.go b/flag_test.go
index aa2f434..ead0518 100644
--- a/flag_test.go
+++ b/flag_test.go
@@ -100,6 +100,12 @@ func TestEverything(t *testing.T) {
}
}
+func TestNoArgument(t *testing.T) {
+ if GetCommandLine().Parse([]string{}) != nil {
+ t.Error("parse failed for empty argument list")
+ }
+}
+
func TestUsage(t *testing.T) {
called := false
ResetForTesting(func() { called = true })