Capture immutable command declarations

This commit is contained in:
2026-10-11 01:15:13 +00:00
parent 476e98a463
commit de9bfdcc4c
16 changed files with 368 additions and 474 deletions

View File

@@ -14,13 +14,17 @@ func (a *App) Register(commands ...Command) error {
if err := validateCommandDeclaration(command); err != nil {
return err
}
if _, exists := a.commands[command.name]; exists {
return fmt.Errorf("command path %q is already registered", command.name)
if command.record.absent {
continue
}
if _, exists := pending[command.name]; exists {
return fmt.Errorf("command path %q is already registered", command.name)
name := command.record.name
if _, exists := a.commands[name]; exists {
return fmt.Errorf("command path %q is already registered", name)
}
pending[command.name] = &commandNode{command: cloneCommand(command)}
if _, exists := pending[name]; exists {
return fmt.Errorf("command path %q is already registered", name)
}
pending[name] = &commandNode{command: command}
}
if len(pending) == 0 {
return nil