From e5762054c9a6429fa7c234897707d53740d6ad5d Mon Sep 17 00:00:00 2001 From: Anthony Fok Date: Sat, 7 Nov 2015 23:21:50 -0700 Subject: [PATCH] Limit the verbose test workaround to "cobra.test" only so that full path to the executable or a renamed executable parses command-line arguments correctly as before. Special thanks to @apriendeau for discovering "go test -v" failing and for providing the initial workaround, see #155 and subsequent discussions. --- command.go | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/command.go b/command.go index 558fed45..7e55a0bc 100644 --- a/command.go +++ b/command.go @@ -20,6 +20,7 @@ import ( "fmt" "io" "os" + "path/filepath" "runtime" "strings" "time" @@ -618,7 +619,8 @@ func (c *Command) Execute() (err error) { var args []string - if len(c.args) == 0 && os.Args[0] == c.Name() { + // Workaround FAIL with "go test -v" or "cobra.test -test.v", see #155 + if len(c.args) == 0 && filepath.Base(os.Args[0]) != "cobra.test" { args = os.Args[1:] } else { args = c.args