Rewrote DebugFlags() function

This commit is contained in:
spf13 2013-09-10 18:27:31 -04:00
parent c5eb49e3f5
commit 90b975fd8e
1 changed files with 36 additions and 8 deletions

View File

@ -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) })
}
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() {
x.DebugFlags()
for _, y := range x.commands {
debugflags(y)
}
}
}
debugflags(c)
}
// Usage prints the usage details to the standard output.