From 90b975fd8e4870dc0215c3f2b94d277544cf4183 Mon Sep 17 00:00:00 2001 From: spf13 Date: Tue, 10 Sep 2013 18:27:31 -0400 Subject: [PATCH] Rewrote DebugFlags() function --- cobra.go | 44 ++++++++++++++++++++++++++++++++++++-------- 1 file changed, 36 insertions(+), 8 deletions(-) diff --git a/cobra.go b/cobra.go index 075b49e..2b9c16a 100644 --- a/cobra.go +++ b/cobra.go @@ -180,18 +180,46 @@ func (c *Command) Usage(depth ...int) string { } func (c *Command) DebugFlags() { - fmt.Println("called on", c.Name()) - if c.HasSubCommands() { - for _, x := range c.commands { + fmt.Println("DebugFlags called on", c.Name()) + var debugflags func(*Command) + + debugflags = func(x *Command) { + if x.HasFlags() || x.HasPersistentFlags() { fmt.Println(x.Name()) - x.flags.VisitAll(func(f *flag.Flag) { fmt.Println(" l:"+f.Name, f.Shorthand, f.DefValue, ":", f.Value) }) - x.pflags.VisitAll(func(f *flag.Flag) { fmt.Println(" p:"+f.Name, f.Shorthand, f.DefValue, ":", f.Value) }) - fmt.Println(x.flagErrorBuf) - if x.HasSubCommands() { - x.DebugFlags() + } + if x.HasFlags() { + x.flags.VisitAll(func(f *flag.Flag) { + if x.HasPersistentFlags() { + if x.persistentFlag(f.Name) == nil { + fmt.Println(" -"+f.Shorthand+",", "--"+f.Name, "["+f.DefValue+"]", "", f.Value, " [L]") + } else { + fmt.Println(" -"+f.Shorthand+",", "--"+f.Name, "["+f.DefValue+"]", "", f.Value, " [LP]") + } + } else { + fmt.Println(" -"+f.Shorthand+",", "--"+f.Name, "["+f.DefValue+"]", "", f.Value, " [L]") + } + }) + } + if x.HasPersistentFlags() { + x.pflags.VisitAll(func(f *flag.Flag) { + if x.HasFlags() { + if x.flags.Lookup(f.Name) == nil { + fmt.Println(" -"+f.Shorthand+",", "--"+f.Name, "["+f.DefValue+"]", "", f.Value, " [P]") + } + } else { + fmt.Println(" -"+f.Shorthand+",", "--"+f.Name, "["+f.DefValue+"]", "", f.Value, " [P]") + } + }) + } + fmt.Println(x.flagErrorBuf) + if x.HasSubCommands() { + for _, y := range x.commands { + debugflags(y) } } } + + debugflags(c) } // Usage prints the usage details to the standard output.