Module: Nehm::CommandManager
- Defined in:
- lib/nehm/command_manager.rb
Overview
The command manager contains information about all nehm commands It also find and run them
Constant Summary collapse
- COMMANDS =
[ :configure, :dl, :get, :help, :list, :search, :version ]
Class Method Summary collapse
- .command_instance(command_name) ⇒ Object
- .find_command(cmd_name) ⇒ Object
- .find_command_possibilities(cmd_name) ⇒ Object
-
.run(args) ⇒ Object
Run the command specified by ‘args’.
Class Method Details
.command_instance(command_name) ⇒ Object
47 48 49 50 51 52 53 |
# File 'lib/nehm/command_manager.rb', line 47 def self.command_instance(command_name) command_name = command_name.to_s const_name = command_name.capitalize << 'Command' require "nehm/commands/#{command_name}_command" Nehm.const_get(const_name).new end |
.find_command(cmd_name) ⇒ Object
30 31 32 33 34 35 36 37 38 39 40 |
# File 'lib/nehm/command_manager.rb', line 30 def self.find_command(cmd_name) possibilities = find_command_possibilities(cmd_name) if possibilities.size > 1 UI.term "Ambiguous command #{cmd_name} matches [#{possibilities.join(', ')}]" elsif possibilities.empty? UI.term "Unknown command #{cmd_name}" end command_instance(possibilities.first) end |
.find_command_possibilities(cmd_name) ⇒ Object
42 43 44 45 |
# File 'lib/nehm/command_manager.rb', line 42 def self.find_command_possibilities(cmd_name) len = cmd_name.length COMMANDS.select { |command| command[0, len] == cmd_name } end |
.run(args) ⇒ Object
Run the command specified by ‘args’
24 25 26 27 28 |
# File 'lib/nehm/command_manager.rb', line 24 def self.run(args) cmd_name = args.shift.downcase cmd = find_command(cmd_name) cmd.invoke(args) end |