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

View File

@@ -5,13 +5,17 @@ import "fmt"
// Register adds a batch of root commands to the application. The batch is
// validated before the registry is changed.
func (a *App) Register(commands ...Command) error {
return a.installBatch(commands...)
}
func (a *App) installBatch(commands ...Command) error {
if a == nil {
return fmt.Errorf("cannot register commands on a nil app")
}
pending := make(map[string]*commandNode, len(commands))
for _, command := range commands {
if err := validateCommandDeclaration(command); err != nil {
if err := validateCommandPlacement(command); err != nil {
return err
}
if command.record.absent {