Accept any single character arguments including '-'
diff --git a/parser_private.go b/parser_private.go
index e25cffd..f361aec 100644
--- a/parser_private.go
+++ b/parser_private.go
@@ -170,7 +170,7 @@
arg = *argument
} else {
arg = s.pop()
- if argumentIsOption(arg) {
+ if len(arg) > 1 && argumentIsOption(arg) {
return newErrorf(ErrExpectedArgument, "expected argument for flag `%s', but got option `%s'", option, arg)
}
}
diff --git a/parser_test.go b/parser_test.go
index 30ecb5e..9b5d8f7 100644
--- a/parser_test.go
+++ b/parser_test.go
@@ -328,9 +328,21 @@
errMsg: "expected argument for flag `--string-slice', but got option `--other-option'",
},
{
+ // long option must not be accepted as argument
+ args: []string{"--string-slice", "--"},
+ expectError: true,
+ errType: ErrExpectedArgument,
+ errMsg: "expected argument for flag `--string-slice', but got option `--'",
+ },
+
+ {
// quoted and appended option should be accepted as argument (even if it looks like an option)
args: []string{"--string-slice", "foobar", "--string-slice=\"--other-option\""},
},
+ {
+ //Accept any single character arguments including '-'
+ args: []string{"--string-slice", "-"},
+ },
}
var opts struct {
StringSlice []string `long:"string-slice"`