Class: Command
- Inherits:
-
Object
- Object
- Command
- Defined in:
- lib/core/command.rb
Direct Known Subclasses
CompileCommand, DebugCommand, DefaultCommand, EditCommand, GenerateCommand, HelpCommand, InstallCommand, ListCommand, UninstallCommand, VersionCommand
Instance Attribute Summary collapse
-
#description ⇒ Object
readonly
Returns the value of attribute description.
Class Method Summary collapse
- .default_cmd ⇒ Object
- .describe ⇒ Object
- .description(d) ⇒ Object
- .get_allowed_commands ⇒ Object
- .load(command) ⇒ Object
-
.load_all ⇒ Object
CLASS METHODS #####.
- .show_use ⇒ Object
- .usage(u) ⇒ Object
Instance Method Summary collapse
- #after_init ⇒ Object
-
#before_init ⇒ Object
should be over-ridden in Command classes.
- #help ⇒ Object
-
#initialize ⇒ Command
constructor
A new instance of Command.
- #main ⇒ Object
- #run(params = {}) ⇒ Object
Constructor Details
#initialize ⇒ Command
Returns a new instance of Command.
12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 |
# File 'lib/core/command.rb', line 12 def initialize before_init @params = {} @options = nil # if Rcli.script_config['global']['mode'] == 'multi' # @@description = "Current action not described. Please use \"description '...'\" in " + self.class.to_s + " to correct." # @@usage = "Usage:\n #{Rcli.script_config['global']['script_name']} <command> [--flags,-f] arg1 arg2 arg3 " # else # @@description = Rcli.script_config['global']['description'] # @@usage = "Usage:\n #{Rcli.script_config['global']['script_name']} [--flags,-f] arg1 arg2 arg3 " # end after_init end |
Instance Attribute Details
#description ⇒ Object (readonly)
Returns the value of attribute description.
3 4 5 |
# File 'lib/core/command.rb', line 3 def description @description end |
Class Method Details
.default_cmd ⇒ Object
28 |
# File 'lib/core/command.rb', line 28 def self.default_cmd; Rcli.script_config['global']['default_command']; end |
.describe ⇒ Object
8 |
# File 'lib/core/command.rb', line 8 def describe; @description; end |
.description(d) ⇒ Object
6 |
# File 'lib/core/command.rb', line 6 def description(d); @description = d; end |
.get_allowed_commands ⇒ Object
99 100 101 102 103 104 105 106 |
# File 'lib/core/command.rb', line 99 def self.get_allowed_commands results = Array.new glob = Rcli.script_root + DS + 'lib' + DS + 'commands' + DS + '*' Dir[glob].each{ |c| results << File.basename(c,'.rb')} results end |
.load(command) ⇒ Object
83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 |
# File 'lib/core/command.rb', line 83 def self.load(command) commands = {} if Command.get_allowed_commands.include?(command) require Rcli.script_root + DS + 'lib' + DS + 'commands' + DS + command if File.exist?(Rcli.script_root + DS + 'lib' + DS + 'commands' + DS + command + '.rb') Object.const_get("#{camelize(command)}Command").description "Current action not described. Please use \"description '...'\" in #{camelize(command)}Command to correct." if not Object.const_get("#{camelize(command)}Command").describe Object.const_get("#{camelize(command)}Command").usage "#{Rcli.script_config['global']['script_name']} <command> [--flags,-f] arg1 arg2 arg3 " if not Object.const_get("#{camelize(command)}Command").show_use commands[command] = { # :instance => TraceableFactory.createTraceableObject("#{camelize(command)}Command") :instance => Object.const_get("#{camelize(command)}Command").new } end commands end |
.load_all ⇒ Object
CLASS METHODS #####
53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 |
# File 'lib/core/command.rb', line 53 def self.load_all commands = {} require Rcli::GEM_LIB + DS + 'commands' + DS + 'debug' require Rcli::GEM_LIB + DS + 'commands' + DS + 'help' commands['debug'] = { :instance => DebugCommand.new } commands['help'] = { :instance => HelpCommand.new } HelpCommand.description "Current action not described. Please use \"description '...'\" in HelpCommand to correct." if not HelpCommand.describe HelpCommand.usage "#{Rcli.script_config['global']['script_name']} <command> [--flags,-f] arg1 arg2 arg3 " if not HelpCommand.show_use DebugCommand.description "Current action not described. Please use \"description '...'\" in DebugCommand to correct." if not DebugCommand.describe DebugCommand.usage "#{Rcli.script_config['global']['script_name']} <command> [--flags,-f] arg1 arg2 arg3 " if not DebugCommand.show_use Command.get_allowed_commands.each do |c| require Rcli.script_root + DS + 'lib' + DS + 'commands' + DS + c if File.exist?(Rcli.script_root + DS + 'lib' + DS + 'commands' + DS + c + '.rb') Object.const_get("#{camelize(c)}Command").description "Current action not described. Please use \"description '...'\" in #{camelize(c)}Command to correct." if not Object.const_get("#{camelize(c)}Command").describe Object.const_get("#{camelize(c)}Command").usage "#{Rcli.script_config['global']['script_name']} <command> [--flags,-f] arg1 arg2 arg3 " if not Object.const_get("#{camelize(c)}Command").show_use # usage "#{Rcli.script_config['global']['script_name']} <command> [--flags,-f] arg1 arg2 arg3 " if c != 'debug' && c != 'help' commands[c] = { # :instance => TraceableFactory.createTraceableObject(camelize(c) + "Command") :instance => Object.const_get("#{camelize(c)}Command").new } end end commands end |
.show_use ⇒ Object
9 |
# File 'lib/core/command.rb', line 9 def show_use; @usage; end |
.usage(u) ⇒ Object
7 |
# File 'lib/core/command.rb', line 7 def usage(u); @usage = u; end |
Instance Method Details
#after_init ⇒ Object
49 |
# File 'lib/core/command.rb', line 49 def after_init; end |
#before_init ⇒ Object
should be over-ridden in Command classes.
48 |
# File 'lib/core/command.rb', line 48 def before_init; end |
#help ⇒ Object
41 42 43 44 45 |
# File 'lib/core/command.rb', line 41 def help ARGV.push('-h') opts = parse_parameters puts end |
#main ⇒ Object
37 38 39 |
# File 'lib/core/command.rb', line 37 def main puts "ERROR: main() method not defined for this command. Please define " + self.class.to_s + "#main() to continue." end |
#run(params = {}) ⇒ Object
30 31 32 33 34 35 |
# File 'lib/core/command.rb', line 30 def run(params = {}) @params = params @options = parse_parameters $verbose= @options.verbose main end |