Categories as slice, not a map anymore, order is always preserved

This commit is contained in:
Soulou
2015-08-21 10:58:14 +02:00
committed by Jesse Szwedko
parent a0801792cc
commit 994a7028e2
3 changed files with 37 additions and 5 deletions

8
app.go
View File

@@ -6,6 +6,7 @@ import (
"io/ioutil"
"os"
"path"
"sort"
"time"
)
@@ -37,7 +38,7 @@ type App struct {
// Display commands by category
CategorizedHelp bool
// Populate when displaying AppHelp
Categories map[string]Commands
Categories CommandCategories
// 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
@@ -100,11 +101,12 @@ func (a *App) Run(arguments []string) (err error) {
}
if a.CategorizedHelp {
a.Categories = make(map[string]Commands)
a.Categories = CommandCategories{}
for _, command := range a.Commands {
a.Categories[command.Category] = append(a.Categories[command.Category], command)
a.Categories = a.Categories.AddCommand(command.Category, command)
}
}
sort.Sort(a.Categories)
newCmds := []Command{}
for _, c := range a.Commands {