Module: Vnehm::CommandManager
- Defined in:
- lib/vnehm/command_manager.rb
Overview
The command manager contains information about all vnehm commands It also find and run them
Constant Summary collapse
- COMMANDS =
[ :authorize, :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
48 49 50 51 52 53 54 |
# File 'lib/vnehm/command_manager.rb', line 48 def self.command_instance(command_name) command_name = command_name.to_s const_name = command_name.capitalize << 'Command' require "vnehm/commands/#{command_name}_command" Vnehm.const_get(const_name).new end |
.find_command(cmd_name) ⇒ Object
31 32 33 34 35 36 37 38 39 40 41 |
# File 'lib/vnehm/command_manager.rb', line 31 def self.find_command(cmd_name) possibilities = find_command_possibilities(cmd_name) if possibilities.size > 1 UI.term "Неоднозначная команда #{cmd_name} соответствует [#{possibilities.join(', ')}]" elsif possibilities.empty? UI.term "Команда #{cmd_name} неизвестна" end command_instance(possibilities.first) end |
.find_command_possibilities(cmd_name) ⇒ Object
43 44 45 46 |
# File 'lib/vnehm/command_manager.rb', line 43 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’
25 26 27 28 29 |
# File 'lib/vnehm/command_manager.rb', line 25 def self.run(args) cmd_name = args.shift.downcase cmd = find_command(cmd_name) cmd.invoke(args) end |