Commit 23681727 authored by Christian Couder's avatar Christian Couder

parse: fix parsing optional arg with stdin

License: MIT
Signed-off-by: default avatarChristian Couder <chriscool@tuxfamily.org>
parent be3b7e13
......@@ -223,7 +223,7 @@ func parseArgs(inputs []string, stdin *os.File, argDefs []cmds.Argument, recursi
// if there is at least one ArgDef, we can safely trigger the inputs loop
// below to parse stdin.
numInputs := len(inputs)
if len(argDefs) > 0 && stdin != nil {
if len(argDefs) > 0 && argDefs[len(argDefs)-1].SupportsStdin && stdin != nil {
numInputs += 1
}
......
......@@ -283,4 +283,7 @@ func TestArgumentParsing(t *testing.T) {
fstdin = fileToSimulateStdin(t, "stdin1")
test([]string{"noarg"}, fstdin, []string{})
fstdin = fileToSimulateStdin(t, "stdin1")
test([]string{"optionalsecond", "value1", "value2"}, fstdin, []string{"value1", "value2"})
}
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment