Install command batches through one path

This commit is contained in:
2026-10-11 01:22:47 +00:00
parent 74f6bdeade
commit 24e8cd8629
8 changed files with 87 additions and 46 deletions

30
app.go
View File

@@ -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