Class: MCLI::CommandGroup
- Inherits:
-
Object
- Object
- MCLI::CommandGroup
- Defined in:
- lib/mcli/command_group.rb
Class Method Summary collapse
- .call(args) ⇒ Object
- .clear ⇒ Object
- .commands ⇒ Object
- .register(command_name, command_klass) ⇒ Object
- .register_root(command_klass) ⇒ Object
- .root_command ⇒ Object
Class Method Details
.call(args) ⇒ Object
23 24 25 26 27 28 29 30 |
# File 'lib/mcli/command_group.rb', line 23 def call(args) command = args.shift commands.fetch(command.to_s.to_sym) do |command| args.unshift(command) root_command || MCLI::NullCommand end.call(args) end |
.clear ⇒ Object
15 16 17 |
# File 'lib/mcli/command_group.rb', line 15 def clear @commands = {} end |
.commands ⇒ Object
11 12 13 |
# File 'lib/mcli/command_group.rb', line 11 def commands @commands ||= {} end |
.register(command_name, command_klass) ⇒ Object
3 4 5 |
# File 'lib/mcli/command_group.rb', line 3 def register(command_name, command_klass) commands[command_name] = command_klass end |
.register_root(command_klass) ⇒ Object
7 8 9 |
# File 'lib/mcli/command_group.rb', line 7 def register_root(command_klass) @root_command = command_klass end |
.root_command ⇒ Object
19 20 21 |
# File 'lib/mcli/command_group.rb', line 19 def root_command @root_command end |