1
0
mirror of https://github.com/ipfs/kubo.git synced 2025-08-06 19:44:01 +08:00

parse: fix parsing optional arg with stdin

License: MIT
Signed-off-by: Christian Couder <chriscool@tuxfamily.org>
This commit is contained in:
Christian Couder
2015-05-21 00:30:08 +02:00
parent be3b7e13e3
commit 23681727e0
2 changed files with 4 additions and 1 deletions

View File

@ -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
}

View File

@ -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"})
}