Merge pull request #114 from shirayu/onechararg
Accept any single character arguments including ``-``
diff --git a/parser_private.go b/parser_private.go
index e25cffd..a64b679 100644
--- a/parser_private.go
+++ b/parser_private.go
@@ -170,7 +170,9 @@
arg = *argument
} else {
arg = s.pop()
- if argumentIsOption(arg) {
+ // Accept any single character arguments including '-'.
+ // '-' is the special file name for the standard input or the standard output in many cases.
+ 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..3026b33 100644
--- a/parser_test.go
+++ b/parser_test.go
@@ -328,9 +328,20 @@
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"`