UsageCommands builds a section template that generates a help text showing the list of allowed commands and sub-commands.
(data []*CommandData)
| 248 | // UsageCommands builds a section template that generates a help text showing |
| 249 | // the list of allowed commands and sub-commands. |
| 250 | func UsageCommands(data []*CommandData) *codegen.SectionTemplate { |
| 251 | usages := make([]string, len(data)) |
| 252 | for i, cmd := range data { |
| 253 | subs := make([]string, len(cmd.Subcommands)) |
| 254 | for i, s := range cmd.Subcommands { |
| 255 | subs[i] = s.Name |
| 256 | } |
| 257 | var lp, rp string |
| 258 | if len(subs) > 1 { |
| 259 | lp = "(" |
| 260 | rp = ")" |
| 261 | } |
| 262 | usages[i] = fmt.Sprintf("%s %s%s%s", cmd.Name, lp, strings.Join(subs, "|"), rp) |
| 263 | } |
| 264 | |
| 265 | return &codegen.SectionTemplate{Source: cliTemplates.Read(usageCommandsT), Data: usages} |
| 266 | } |
| 267 | |
| 268 | // UsageExamples builds a section template that generates a help text showing |
| 269 | // a valid invocation of the CLI tool. |
no test coverage detected