Class: SwarmCLI::CommandRegistry

Inherits:
Object
  • Object
show all
Defined in:
lib/swarm_cli/command_registry.rb

Overview

Registry for CLI command extensions

Allows gems (like swarm_memory) to register additional CLI commands that integrate seamlessly with the main swarm CLI.

Examples:

# In swarm_memory gem
SwarmCLI::CommandRegistry.register(:memory, MyMemoryCommand)

# User runs:
swarm memory status

# SwarmCLI routes to MyMemoryCommand.execute(["status"])

Class Method Summary collapse

Class Method Details

.commandsArray<String>

Get all registered command names

Returns:

  • (Array<String>)

    Command names



55
56
57
58
# File 'lib/swarm_cli/command_registry.rb', line 55

def commands
  @extensions ||= {}
  @extensions.keys
end

.get(command_name) ⇒ Class?

Get command class by name

Parameters:

  • command_name (String)

    Command name

Returns:

  • (Class, nil)

    Command class or nil if not found



38
39
40
41
# File 'lib/swarm_cli/command_registry.rb', line 38

def get(command_name)
  @extensions ||= {}
  @extensions[command_name.to_s]
end

.register(command_name, command_class) ⇒ void

This method returns an undefined value.

Register a command extension

Examples:

CommandRegistry.register(:memory, SwarmMemory::CLI::Commands)

Parameters:

  • command_name (Symbol, String)

    Command name (e.g., :memory)

  • command_class (Class)

    Command class with execute(args) method



29
30
31
32
# File 'lib/swarm_cli/command_registry.rb', line 29

def register(command_name, command_class)
  @extensions ||= {}
  @extensions[command_name.to_s] = command_class
end

.registered?(command_name) ⇒ Boolean

Check if a command is registered

Parameters:

  • command_name (String)

    Command name

Returns:

  • (Boolean)

    True if command exists



47
48
49
50
# File 'lib/swarm_cli/command_registry.rb', line 47

def registered?(command_name)
  @extensions ||= {}
  @extensions.key?(command_name.to_s)
end