Install command batches through one path
This commit is contained in:
30
app.go
30
app.go
@@ -8,15 +8,13 @@ import (
|
||||
|
||||
// App owns one command registry and its application identity.
|
||||
type App struct {
|
||||
identity Identity
|
||||
commands map[string]*commandNode
|
||||
commandTree *internalcobra.Command
|
||||
configRegistered bool
|
||||
identity Identity
|
||||
commands map[string]*commandNode
|
||||
commandTree *internalcobra.Command
|
||||
}
|
||||
|
||||
type commandNode struct {
|
||||
command Command
|
||||
reserved bool
|
||||
command Command
|
||||
}
|
||||
|
||||
// New creates an application with the supplied identity and initial commands.
|
||||
@@ -27,23 +25,9 @@ func New(identity Identity, commands ...Command) (*App, error) {
|
||||
return nil, fmt.Errorf("application identity name must not be empty")
|
||||
}
|
||||
|
||||
app := &App{
|
||||
identity: identity,
|
||||
commands: map[string]*commandNode{
|
||||
"help": {
|
||||
command: Command{record: &commandRecord{name: "help", summary: "Show help for commands."}},
|
||||
reserved: true,
|
||||
},
|
||||
"version": {
|
||||
command: Command{record: &commandRecord{name: "version", summary: "Show application version."}},
|
||||
reserved: true,
|
||||
},
|
||||
},
|
||||
}
|
||||
if err := app.installBuiltins(); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
if err := app.Register(commands...); err != nil {
|
||||
app := &App{identity: identity, commands: make(map[string]*commandNode)}
|
||||
all := append(app.builtinCommands(), commands...)
|
||||
if err := app.installBatch(all...); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return app, nil
|
||||
|
||||
Reference in New Issue
Block a user