Extend flag categorization to top-level (global) flags

This commit is contained in:
2022-04-22 15:44:59 -04:00
parent 75e4ee69e9
commit e4580f0c50
3 changed files with 73 additions and 38 deletions

10
app.go
View File

@@ -52,7 +52,7 @@ type App struct {
HideVersion bool
// categories contains the categorized commands and is populated on app startup
categories CommandCategories
// Populate on app startup, only gettable through method Categories()
// flagCategories contains the categorized flags and is populated on app startup
flagCategories FlagCategories
// An action to execute when the shell completion flag is set
BashComplete BashCompleteFunc
@@ -217,6 +217,14 @@ func (a *App) Setup() {
}
sort.Sort(a.categories.(*commandCategories))
a.flagCategories = FlagCategories{}
for _, fl := range a.Flags {
if cf, ok := fl.(CategorizableFlag); ok {
a.flagCategories.AddFlag(cf.GetCategory(), cf)
}
}
sort.Sort(a.flagCategories)
if a.Metadata == nil {
a.Metadata = make(map[string]interface{})
}