HelpText returns the computed help of the command and its subcommands.
()
| 74 | |
| 75 | // HelpText returns the computed help of the command and its subcommands. |
| 76 | func (c Cmd) HelpText() string { |
| 77 | var b bytes.Buffer |
| 78 | p := func(s ...interface{}) { |
| 79 | fmt.Fprintln(&b) |
| 80 | if len(s) > 0 { |
| 81 | fmt.Fprintln(&b, s...) |
| 82 | } |
| 83 | } |
| 84 | if c.LongHelp != "" { |
| 85 | p(c.LongHelp) |
| 86 | } else if c.Help != "" { |
| 87 | p(c.Help) |
| 88 | } else if c.Name != "" { |
| 89 | p(c.Name, "has no help") |
| 90 | } |
| 91 | if c.hasSubcommand() { |
| 92 | p("Commands:") |
| 93 | w := tabwriter.NewWriter(&b, 0, 4, 2, ' ', 0) |
| 94 | for _, child := range c.Children() { |
| 95 | fmt.Fprintf(w, "\t%s\t\t\t%s\n", child.Name, child.Help) |
| 96 | } |
| 97 | w.Flush() |
| 98 | p() |
| 99 | } |
| 100 | return b.String() |
| 101 | } |
| 102 | |
| 103 | // findChildCmd returns the subcommand with matching name or alias. |
| 104 | func (c *Cmd) findChildCmd(name string) *Cmd { |
nothing calls this directly
no test coverage detected