parse: fix handling of unwanted stdin
There can be non-terminal (i.e. non-interactive) sessions that are *not* a pipe, for example: ssh user@host ipfs version In this case, it looks like we should read from stdin. Parsing stdin is accomplished by deliberately triggering the parsing loop once. We didn't previously check whether there is an ArgDef to support that loop iteration.
Lars Gierth committed
May 20, 2015 at 04:24 UTC
2eea1b05b7c307516f26c90b8ee3b1b86c7c52fb
1 file changed
+4
-2
commands/cli/parse.go
+4
-2
@@ -219,9 +219,11 @@ func parseArgs(inputs []string, stdin *os.File, argDefs []cmds.Argument, recursi
219
}
220
}
221
222
- // count number of values provided by user
222
+ // count number of values provided by user.
223
+ // if there is at least one ArgDef, we can safely trigger the inputs loop
224
+ // below to parse stdin.
225
numInputs := len(inputs)
224
- if stdin != nil {
226
+ if argDef := getArgDef(0, argDefs); argDef != nil && stdin != nil {
227
numInputs += 1
228
}
229