From 499475bb41e00278e1776bea49ee48624e7a1e53 Mon Sep 17 00:00:00 2001 From: Nick Craig-Wood Date: Sat, 11 Feb 2017 13:57:48 +0000 Subject: [PATCH] Fix -vv by temporarily patching vendored cobra This is a temporary fix until this pull request gets merged https://github.com/spf13/cobra/pull/391 See original ticket https://github.com/spf13/pflag/issues/112 --- vendor/github.com/spf13/cobra/command.go | 16 +++++++--------- 1 file changed, 7 insertions(+), 9 deletions(-) diff --git a/vendor/github.com/spf13/cobra/command.go b/vendor/github.com/spf13/cobra/command.go index 49889318c..6bfbe4179 100644 --- a/vendor/github.com/spf13/cobra/command.go +++ b/vendor/github.com/spf13/cobra/command.go @@ -373,20 +373,18 @@ func (c *Command) resetChildrensParents() { } } -// Test if the named flag is a boolean flag. -func isBooleanFlag(name string, f *flag.FlagSet) bool { +func hasNoOptDefVal(name string, f *flag.FlagSet) bool { flag := f.Lookup(name) if flag == nil { return false } - return flag.Value.Type() == "bool" + return len(flag.NoOptDefVal) > 0 } -// Test if the named flag is a boolean flag. -func isBooleanShortFlag(name string, f *flag.FlagSet) bool { +func shortHasNoOptDefVal(name string, fs *flag.FlagSet) bool { result := false - f.VisitAll(func(f *flag.Flag) { - if f.Shorthand == name && f.Value.Type() == "bool" { + fs.VisitAll(func(flag *flag.Flag) { + if flag.Shorthand == name && len(flag.NoOptDefVal) > 0 { result = true } }) @@ -412,8 +410,8 @@ func stripFlags(args []string, c *Command) []string { inQuote = true case strings.HasPrefix(y, "--") && !strings.Contains(y, "="): // TODO: this isn't quite right, we should really check ahead for 'true' or 'false' - inFlag = !isBooleanFlag(y[2:], c.Flags()) - case strings.HasPrefix(y, "-") && !strings.Contains(y, "=") && len(y) == 2 && !isBooleanShortFlag(y[1:], c.Flags()): + inFlag = !hasNoOptDefVal(y[2:], c.Flags()) + case strings.HasPrefix(y, "-") && !strings.Contains(y, "=") && len(y) == 2 && !shortHasNoOptDefVal(y[1:], c.Flags()): inFlag = true case inFlag: inFlag = false