module Nehm::CommandManager

The command manager contains information about all nehm commands It also find and run them

Constants

COMMANDS

Public Class Methods

command_instance(command_name) click to toggle source
# 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) click to toggle source
# 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) click to toggle source
# 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) click to toggle source

Run the command specified by ‘args’

# 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