parse: fix parsing optional arg with stdin
License: MIT Signed-off-by: Christian Couder <chriscool@tuxfamily.org>
Christian Couder committed
May 21, 2015 at 00:30 UTC
23681727e04e652b7f67f8bfa94065209a8b63f3
2 files changed
+4
-1
commands/cli/parse.go
+1
-1
@@ -223,7 +223,7 @@ func parseArgs(inputs []string, stdin *os.File, argDefs []cmds.Argument, recursi
223
// if there is at least one ArgDef, we can safely trigger the inputs loop
224
// below to parse stdin.
225
numInputs := len(inputs)
226
- if len(argDefs) > 0 && stdin != nil {
226
+ if len(argDefs) > 0 && argDefs[len(argDefs)-1].SupportsStdin && stdin != nil {
227
numInputs += 1
228
}
229
commands/cli/parse_test.go
+3
@@ -283,4 +283,7 @@ func TestArgumentParsing(t *testing.T) {
283
284
fstdin = fileToSimulateStdin(t, "stdin1")
285
test([]string{"noarg"}, fstdin, []string{})
286
+
287
+ fstdin = fileToSimulateStdin(t, "stdin1")
288
+ test([]string{"optionalsecond", "value1", "value2"}, fstdin, []string{"value1", "value2"})
289
}