Remove CategorizedHelp from App and allow subcommands to have categories

Just place all subcommands in categories, the default category will be
"" which will properly format the output (and group commands that have
no category).

Also allow subcommands to have categories.

Lastly, augment the test to check the output.
This commit is contained in:
Jesse Szwedko
2016-03-20 12:17:13 -07:00
parent d0997e8f99
commit 042842b819
4 changed files with 31 additions and 21 deletions

16
app.go
View File

@@ -35,8 +35,6 @@ type App struct {
HideHelp bool
// Boolean to hide built-in version flag
HideVersion bool
// Display commands by category
CategorizedHelp bool
// Populate on app startup, only gettable throught method Categories()
categories CommandCategories
// An action to execute when the bash-completion flag is set
@@ -100,14 +98,6 @@ 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 = CommandCategories{}
for _, command := range a.Commands {
a.categories = a.categories.AddCommand(command.Category, command)
}
}
sort.Sort(a.categories)
newCmds := []Command{}
for _, c := range a.Commands {
if c.HelpName == "" {
@@ -117,6 +107,12 @@ func (a *App) Run(arguments []string) (err error) {
}
a.Commands = newCmds
a.categories = CommandCategories{}
for _, command := range a.Commands {
a.categories = a.categories.AddCommand(command.Category, command)
}
sort.Sort(a.categories)
// append help to commands
if a.Command(helpCommand.Name) == nil && !a.HideHelp {
a.Commands = append(a.Commands, helpCommand)