Allow to sort commands by category
This commit is contained in:
11
app.go
11
app.go
@@ -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 == "" {
|
||||
|
Reference in New Issue
Block a user