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.
This commit is contained in:
Lars Gierth 2015-05-20 04:24:31 +02:00
parent 4e0ca860e9
commit 2eea1b05b7

View File

@ -219,9 +219,11 @@ func parseArgs(inputs []string, stdin *os.File, argDefs []cmds.Argument, recursi
}
}
// count number of values provided by user
// count number of values provided by user.
// if there is at least one ArgDef, we can safely trigger the inputs loop
// below to parse stdin.
numInputs := len(inputs)
if stdin != nil {
if argDef := getArgDef(0, argDefs); argDef != nil && stdin != nil {
numInputs += 1
}