Class: Cuprum::Cli::Registry
- Inherits:
-
Object
- Object
- Cuprum::Cli::Registry
- Defined in:
- lib/cuprum/cli/registry.rb
Overview
Registers CLI commands by name.
Direct Known Subclasses
Instance Method Summary collapse
-
#[](name) ⇒ Class?
The command registered with the given name, if any.
-
#commands ⇒ Hash{String => Class}
Returns a copy of the commands registered with the registry.
-
#register(command, **config) ⇒ self
(also: #add)
Registers the command with the registry.
Instance Method Details
#[](name) ⇒ Class?
Returns the command registered with the given name, if any.
9 10 11 12 13 |
# File 'lib/cuprum/cli/registry.rb', line 9 def [](name) tools.assertions.validate_name(name, as: 'full_name') registered_commands[name] end |
#commands ⇒ Hash{String => Class}
Returns a copy of the commands registered with the registry.
18 19 20 |
# File 'lib/cuprum/cli/registry.rb', line 18 def commands registered_commands.dup.freeze end |
#register(command, **config) ⇒ self Also known as: add
Registers the command with the registry.
40 41 42 43 44 45 46 47 48 49 50 51 52 |
# File 'lib/cuprum/cli/registry.rb', line 40 def register(command, **config) validate_command(command) name = config.fetch(:full_name, command.full_name) validate_name(name) command = build_command(command, **config) if any_present?(config) registered_commands[name] = command self end |