Capture immutable command declarations
This commit is contained in:
14
registry.go
14
registry.go
@@ -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
|
||||
|
||||
Reference in New Issue
Block a user