Fixed panic on empty strings as arguments -- now just passed through to the command

This commit is contained in:
Zach Musgrave
2019-03-21 14:46:37 -07:00
parent de6119bd6e
commit 5128323c45
2 changed files with 9 additions and 1 deletions
@@ -58,6 +58,14 @@ func TestParsing(t *testing.T) {
map[string]string{"message": "value"},
[]string{"b", "c"},
},
{
"empty string",
[]*Option{forceOpt, messageOpt},
[]string{"b", "--message=value", ""},
map[string]string{"message": "value"},
[]string{"b", ""},
},
}
for _, test := range tests {
+1 -1
View File
@@ -105,7 +105,7 @@ func (ap *ArgParser) Parse(args []string) (*ArgParseResults, error) {
for ; i < len(args); i++ {
arg := args[i]
if arg[0] != '-' {
if len(arg) == 0 || arg[0] != '-' { // empty strings should get passed through like other naked words
list = append(list, arg)
} else {
if arg == "--" {