Allow to sort commands by category

This commit is contained in:
Soulou
2014-12-15 23:35:49 +01:00
committed by Jesse Szwedko
parent aca5b047ed
commit a0801792cc
3 changed files with 25 additions and 4 deletions

11
app.go
View File

@@ -34,6 +34,10 @@ type App struct {
HideHelp bool
// Boolean to hide built-in version flag
HideVersion bool
// Display commands by category
CategorizedHelp bool
// Populate when displaying AppHelp
Categories map[string]Commands
// An action to execute when the bash-completion flag is set
BashComplete func(context *Context)
// An action to execute before any subcommands are run, but after the context is ready
@@ -95,6 +99,13 @@ func (a *App) Run(arguments []string) (err error) {
a.Authors = append(a.Authors, Author{Name: a.Author, Email: a.Email})
}
if a.CategorizedHelp {
a.Categories = make(map[string]Commands)
for _, command := range a.Commands {
a.Categories[command.Category] = append(a.Categories[command.Category], command)
}
}
newCmds := []Command{}
for _, c := range a.Commands {
if c.HelpName == "" {