Class: MCLI::CommandGroup

Inherits:
Object
  • Object
show all
Defined in:
lib/mcli/command_group.rb

Class Method Summary collapse

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

.clearObject



15
16
17
# File 'lib/mcli/command_group.rb', line 15

def clear
  @commands = {}
end

.commandsObject



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_commandObject



19
20
21
# File 'lib/mcli/command_group.rb', line 19

def root_command
  @root_command
end