提交 23681727 作者: Christian Couder

parse: fix parsing optional arg with stdin

License: MIT
Signed-off-by: 's avatarChristian Couder <chriscool@tuxfamily.org>
上级 be3b7e13
...@@ -223,7 +223,7 @@ func parseArgs(inputs []string, stdin *os.File, argDefs []cmds.Argument, recursi ...@@ -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 // if there is at least one ArgDef, we can safely trigger the inputs loop
// below to parse stdin. // below to parse stdin.
numInputs := len(inputs) numInputs := len(inputs)
if len(argDefs) > 0 && stdin != nil { if len(argDefs) > 0 && argDefs[len(argDefs)-1].SupportsStdin && stdin != nil {
numInputs += 1 numInputs += 1
} }
......
...@@ -283,4 +283,7 @@ func TestArgumentParsing(t *testing.T) { ...@@ -283,4 +283,7 @@ func TestArgumentParsing(t *testing.T) {
fstdin = fileToSimulateStdin(t, "stdin1") fstdin = fileToSimulateStdin(t, "stdin1")
test([]string{"noarg"}, fstdin, []string{}) test([]string{"noarg"}, fstdin, []string{})
fstdin = fileToSimulateStdin(t, "stdin1")
test([]string{"optionalsecond", "value1", "value2"}, fstdin, []string{"value1", "value2"})
} }
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论