Some changes per feedback in #1368
This commit is contained in:
parent
156eaafb22
commit
16d5d5a3df
11
app.go
11
app.go
@ -184,14 +184,7 @@ func (a *App) Setup() {
|
|||||||
c.HelpName = fmt.Sprintf("%s %s", a.HelpName, c.Name)
|
c.HelpName = fmt.Sprintf("%s %s", a.HelpName, c.Name)
|
||||||
}
|
}
|
||||||
|
|
||||||
fc := newFlagCategories()
|
c.flagCategories = newFlagCategoriesFromFlags(c.Flags)
|
||||||
for _, fl := range c.Flags {
|
|
||||||
if cf, ok := fl.(CategorizableFlag); ok {
|
|
||||||
fc.AddFlag(cf.GetCategory(), cf)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
c.flagCategories = fc
|
|
||||||
newCommands = append(newCommands, c)
|
newCommands = append(newCommands, c)
|
||||||
}
|
}
|
||||||
a.Commands = newCommands
|
a.Commands = newCommands
|
||||||
@ -502,7 +495,7 @@ func (a *App) VisibleCommands() []*Command {
|
|||||||
// VisibleFlagCategories returns a slice containing all the categories with the flags they contain
|
// VisibleFlagCategories returns a slice containing all the categories with the flags they contain
|
||||||
func (a *App) VisibleFlagCategories() []VisibleFlagCategory {
|
func (a *App) VisibleFlagCategories() []VisibleFlagCategory {
|
||||||
if a.flagCategories == nil {
|
if a.flagCategories == nil {
|
||||||
a.flagCategories = newFlagCategories()
|
return []VisibleFlagCategory{}
|
||||||
}
|
}
|
||||||
return a.flagCategories.VisibleCategories()
|
return a.flagCategories.VisibleCategories()
|
||||||
}
|
}
|
||||||
|
11
category.go
11
category.go
@ -98,6 +98,17 @@ func newFlagCategories() FlagCategories {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func newFlagCategoriesFromFlags(fs []Flag) FlagCategories {
|
||||||
|
fc := newFlagCategories()
|
||||||
|
for _, fl := range fs {
|
||||||
|
if cf, ok := fl.(CategorizableFlag); ok {
|
||||||
|
fc.AddFlag(cf.GetCategory(), cf)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return fc
|
||||||
|
}
|
||||||
|
|
||||||
func (f *defaultFlagCategories) AddFlag(category string, fl Flag) {
|
func (f *defaultFlagCategories) AddFlag(category string, fl Flag) {
|
||||||
if _, ok := f.m[category]; !ok {
|
if _, ok := f.m[category]; !ok {
|
||||||
f.m[category] = &defaultVisibleFlagCategory{name: category, m: map[string]Flag{}}
|
f.m[category] = &defaultVisibleFlagCategory{name: category, m: map[string]Flag{}}
|
||||||
|
@ -284,7 +284,7 @@ func (c *Command) startApp(ctx *Context) error {
|
|||||||
// VisibleFlagCategories returns a slice containing all the visible flag categories with the flags they contain
|
// VisibleFlagCategories returns a slice containing all the visible flag categories with the flags they contain
|
||||||
func (c *Command) VisibleFlagCategories() []VisibleFlagCategory {
|
func (c *Command) VisibleFlagCategories() []VisibleFlagCategory {
|
||||||
if c.flagCategories == nil {
|
if c.flagCategories == nil {
|
||||||
c.flagCategories = newFlagCategories()
|
return []VisibleFlagCategory{}
|
||||||
}
|
}
|
||||||
return c.flagCategories.VisibleCategories()
|
return c.flagCategories.VisibleCategories()
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user