From ccbe1b23590d6cdd8f5ef71e7cfd0157ba29950b Mon Sep 17 00:00:00 2001 From: spf13 Date: Wed, 4 Sep 2013 11:26:28 -0400 Subject: [PATCH] Adding debug flags method to a command & commander --- cobra.go | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/cobra.go b/cobra.go index d30fd8a5..79a433c4 100644 --- a/cobra.go +++ b/cobra.go @@ -179,6 +179,21 @@ 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(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() + } + } + } +} + // Usage prints the usage details to the standard output. func (c *Command) PrintUsage() { if c.Runnable() {