From 2eea1b05b7c307516f26c90b8ee3b1b86c7c52fb Mon Sep 17 00:00:00 2001
From: Lars Gierth <larsg@systemli.org>
Date: Wed, 20 May 2015 04:24:31 +0200
Subject: [PATCH] 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.
---
 commands/cli/parse.go | 6 ++++--
 1 file changed, 4 insertions(+), 2 deletions(-)

diff --git a/commands/cli/parse.go b/commands/cli/parse.go
index 92be53fa6..4ff7103a0 100644
--- a/commands/cli/parse.go
+++ b/commands/cli/parse.go
@@ -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
 	}
 
-- 
GitLab