make categories private
This commit is contained in:
parent
3415a1aade
commit
3bd997859c
12
app.go
12
app.go
@ -47,8 +47,8 @@ type App struct {
|
||||
HideHelp bool
|
||||
// Boolean to hide built-in version flag and the VERSION section of help
|
||||
HideVersion bool
|
||||
// Categories contains the categorized commands and is populated on app startup
|
||||
Categories CommandCategories
|
||||
// categories contains the categorized commands and is populated on app startup
|
||||
categories CommandCategories
|
||||
// An action to execute when the shell completion flag is set
|
||||
BashComplete BashCompleteFunc
|
||||
// An action to execute before any subcommands are run, but after the context is ready
|
||||
@ -182,11 +182,11 @@ func (a *App) Setup() {
|
||||
a.appendFlag(VersionFlag)
|
||||
}
|
||||
|
||||
a.Categories = newCommandCategories()
|
||||
a.categories = newCommandCategories()
|
||||
for _, command := range a.Commands {
|
||||
a.Categories.AddCommand(command.Category, command)
|
||||
a.categories.AddCommand(command.Category, command)
|
||||
}
|
||||
sort.Sort(a.Categories.(*commandCategories))
|
||||
sort.Sort(a.categories.(*commandCategories))
|
||||
|
||||
if a.Metadata == nil {
|
||||
a.Metadata = make(map[string]interface{})
|
||||
@ -449,7 +449,7 @@ func (a *App) Command(name string) *Command {
|
||||
// Hidden=false
|
||||
func (a *App) VisibleCategories() []CommandCategory {
|
||||
ret := []CommandCategory{}
|
||||
for _, category := range a.Categories.Categories() {
|
||||
for _, category := range a.categories.Categories() {
|
||||
if visible := func() CommandCategory {
|
||||
if len(category.VisibleCommands()) > 0 {
|
||||
return category
|
||||
|
@ -1719,8 +1719,8 @@ func TestApp_Run_Categories(t *testing.T) {
|
||||
},
|
||||
})
|
||||
|
||||
if !reflect.DeepEqual(app.Categories, &expect) {
|
||||
t.Fatalf("expected categories %#v, to equal %#v", app.Categories, &expect)
|
||||
if !reflect.DeepEqual(app.categories, &expect) {
|
||||
t.Fatalf("expected categories %#v, to equal %#v", app.categories, &expect)
|
||||
}
|
||||
|
||||
output := buf.String()
|
||||
|
@ -3,7 +3,7 @@ package cli
|
||||
type CommandCategories interface {
|
||||
// AddCommand adds a command to a category, creating a new category if necessary.
|
||||
AddCommand(category string, command *Command)
|
||||
// Categories returns a copy of the category slice
|
||||
// categories returns a copy of the category slice
|
||||
Categories() []CommandCategory
|
||||
}
|
||||
|
||||
|
@ -245,12 +245,12 @@ func (c *Command) startApp(ctx *Context) error {
|
||||
app.ExitErrHandler = ctx.App.ExitErrHandler
|
||||
app.UseShortOptionHandling = ctx.App.UseShortOptionHandling
|
||||
|
||||
app.Categories = newCommandCategories()
|
||||
app.categories = newCommandCategories()
|
||||
for _, command := range c.Subcommands {
|
||||
app.Categories.AddCommand(command.Category, command)
|
||||
app.categories.AddCommand(command.Category, command)
|
||||
}
|
||||
|
||||
sort.Sort(app.Categories.(*commandCategories))
|
||||
sort.Sort(app.categories.(*commandCategories))
|
||||
|
||||
// bash completion
|
||||
app.EnableBashCompletion = ctx.App.EnableBashCompletion
|
||||
|
Loading…
Reference in New Issue
Block a user