Add captured alias declaration types

This commit is contained in:
2026-10-19 17:23:32 +00:00
parent 854426a0c9
commit 7a4efddab8
9 changed files with 297 additions and 21 deletions

17
app.go
View File

@@ -9,9 +9,10 @@ import (
// App owns one command registry and its application identity. Each App has an
// independent registry; command declarations may be reused across Apps.
type App struct {
identity Identity
commands map[string]*commandNode
snapshot *routingSnapshot
identity Identity
commands map[string]*commandNode
routingRules []RoutingRule
snapshot *routingSnapshot
}
type routingSnapshot struct {
@@ -23,18 +24,22 @@ type commandNode struct {
command Command
}
// New creates an application with the supplied identity and initial commands.
// New creates an application with the supplied identity and initial
// declarations.
// The identity name must not be empty. New installs its generated help and
// version commands and caller declarations as one batch; an invalid declaration
// returns an error without exposing an App. The root help and version names are
// reserved for generated commands.
func New(identity Identity, commands ...Command) (*App, error) {
func New(identity Identity, declarations ...Declaration) (*App, error) {
if identity.Name == "" {
return nil, fmt.Errorf("application identity name must not be empty")
}
app := &App{identity: identity, commands: make(map[string]*commandNode)}
all := append(app.builtinCommands(), commands...)
builtins := app.builtinCommands()
all := make([]Declaration, 0, len(builtins)+len(declarations))
all = append(all, builtins...)
all = append(all, declarations...)
if err := app.installBatch(all...); err != nil {
return nil, err
}