module Golem::Command
Namespace for commands.
Constants
- ALIASES
Hash of aliases.
- COMMANDS
List of command names as symbols.
Public Class Methods
find(cmd)
click to toggle source
Find command class by name. @raise [NameError] if class (constant) not found. @param [Symbol, String] cmd command name to search for. @return [Class] command class.
# File lib/golem/command.rb, line 47 def self.find(cmd) cmd = ALIASES.find {|key, a| a.include?(cmd.to_s)}.first if ALIASES.any? {|key, aliases| aliases.include?(cmd.to_s)} abort "Command not understood." unless COMMANDS.include?(cmd.to_sym) const_get cmd.to_s.split("_").collect {|p| p.capitalize}.join.to_sym end
run(cmd, opts = {:verbose => true}, *args)
click to toggle source
Run a command. @param [Symbol, String] cmd command name to run, @param [Hash] opts options, see {Base#initialize}, @param *args arguments for the command.
# File lib/golem/command.rb, line 31 def self.run(cmd, opts = {:verbose => true}, *args) find(cmd).new(opts).run(*args) end
usage(cmd)
click to toggle source
Get command usage to display in help message. @param [Symbol, String] cmd command name. @return [String] usage text or empty string.
# File lib/golem/command.rb, line 38 def self.usage(cmd) cmd = find(cmd) cmd.const_defined?(:USAGE) ? cmd::USAGE : "" end