Skip to content

Commit

Permalink
Fix category
Browse files Browse the repository at this point in the history
  • Loading branch information
skelouse committed Jan 29, 2023
1 parent a6b3713 commit e496537
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 10 deletions.
9 changes: 1 addition & 8 deletions app.go
Original file line number Diff line number Diff line change
Expand Up @@ -250,14 +250,7 @@ func (a *App) Setup() {
}
sort.Sort(a.categories.(*commandCategories))

a.flagCategories = newFlagCategories()
for _, fl := range a.Flags {
if cf, ok := fl.(CategorizableFlag); ok {
if cf.GetCategory() != "" {
a.flagCategories.AddFlag(cf.GetCategory(), cf)
}
}
}
a.flagCategories = newFlagCategoriesFromFlags(a.Flags)

if a.Metadata == nil {
a.Metadata = make(map[string]interface{})
Expand Down
17 changes: 15 additions & 2 deletions category.go
Original file line number Diff line number Diff line change
Expand Up @@ -100,10 +100,23 @@ func newFlagCategories() FlagCategories {

func newFlagCategoriesFromFlags(fs []Flag) FlagCategories {
fc := newFlagCategories()

var categorized bool
for _, fl := range fs {
if cf, ok := fl.(CategorizableFlag); ok {
if cf.GetCategory() != "" {
fc.AddFlag(cf.GetCategory(), cf)
if cat := cf.GetCategory(); cat != "" {
fc.AddFlag(cat, cf)
categorized = true
}
}
}

if categorized == true {
for _, fl := range fs {
if cf, ok := fl.(CategorizableFlag); ok {
if cf.GetCategory() == "" {
fc.AddFlag("", fl)
}
}
}
}
Expand Down

0 comments on commit e496537

Please sign in to comment.