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:
@ -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"})
|
||||
}
|
||||
|
Reference in New Issue
Block a user