Class: Mercenary::Program
Instance Attribute Summary collapse
-
#config ⇒ Object
readonly
Returns the value of attribute config.
-
#optparse ⇒ Object
readonly
Returns the value of attribute optparse.
Attributes inherited from Command
#actions, #commands, #description, #map, #name, #options, #parent, #syntax, #trace
Instance Method Summary collapse
-
#go(argv) ⇒ Object
Public: Run the program.
-
#initialize(name) ⇒ Program
constructor
Public: Creates a new Program.
Methods inherited from Command
#action, #add_default_options, #alias, #command, #default_command, #execute, #full_name, #has_command?, #ident, #identity, #logger, #option, #process_options, #summarize, #to_s, #version
Constructor Details
#initialize(name) ⇒ Program
Public: Creates a new Program
name - the name of the program
Returns nothing
11 12 13 14 |
# File 'lib/mercenary/program.rb', line 11 def initialize(name) @config = {} super(name) end |
Instance Attribute Details
#config ⇒ Object (readonly)
Returns the value of attribute config.
4 5 6 |
# File 'lib/mercenary/program.rb', line 4 def config @config end |
#optparse ⇒ Object (readonly)
Returns the value of attribute optparse.
3 4 5 |
# File 'lib/mercenary/program.rb', line 3 def optparse @optparse end |
Instance Method Details
#go(argv) ⇒ Object
Public: Run the program
argv - an array of string args (usually ARGV)
Returns nothing
21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 |
# File 'lib/mercenary/program.rb', line 21 def go(argv) logger.debug("Using args passed in: #{argv.inspect}") cmd = nil @optparse = OptionParser.new do |opts| cmd = super(argv, opts, @config) end @optparse.parse!(argv) logger.debug("Parsed config: #{@config.inspect}") begin cmd.execute(argv, @config) rescue => e if cmd.trace raise e else logger.error e. abort end end end |