Class: Choosy::BaseCommand
- Inherits:
-
Object
- Object
- Choosy::BaseCommand
- Defined in:
- lib/choosy/base_command.rb
Direct Known Subclasses
Instance Attribute Summary collapse
-
#builder ⇒ Object
readonly
Returns the value of attribute builder.
-
#listing ⇒ Object
readonly
Returns the value of attribute listing.
-
#name ⇒ Object
Returns the value of attribute name.
-
#option_builders ⇒ Object
readonly
Returns the value of attribute option_builders.
-
#printer ⇒ Object
Returns the value of attribute printer.
-
#summary ⇒ Object
Returns the value of attribute summary.
Instance Method Summary collapse
- #alter(&block) ⇒ Object
- #execute!(args, propagate = false) ⇒ Object
- #finalize! ⇒ Object
-
#initialize(name, &block) ⇒ BaseCommand
constructor
A new instance of BaseCommand.
- #options ⇒ Object
- #parse!(args, propagate = false) ⇒ Object
Constructor Details
#initialize(name, &block) ⇒ BaseCommand
Returns a new instance of BaseCommand.
16 17 18 19 20 21 22 23 24 |
# File 'lib/choosy/base_command.rb', line 16 def initialize(name, &block) @name = name @listing = [] @option_builders = OptionBuilderHash.new @printer = nil @builder = create_builder @builder.evaluate!(&block) end |
Instance Attribute Details
#builder ⇒ Object (readonly)
Returns the value of attribute builder.
14 15 16 |
# File 'lib/choosy/base_command.rb', line 14 def builder @builder end |
#listing ⇒ Object (readonly)
Returns the value of attribute listing.
14 15 16 |
# File 'lib/choosy/base_command.rb', line 14 def listing @listing end |
#name ⇒ Object
Returns the value of attribute name.
13 14 15 |
# File 'lib/choosy/base_command.rb', line 13 def name @name end |
#option_builders ⇒ Object (readonly)
Returns the value of attribute option_builders.
14 15 16 |
# File 'lib/choosy/base_command.rb', line 14 def option_builders @option_builders end |
#printer ⇒ Object
Returns the value of attribute printer.
13 14 15 |
# File 'lib/choosy/base_command.rb', line 13 def printer @printer end |
#summary ⇒ Object
Returns the value of attribute summary.
13 14 15 |
# File 'lib/choosy/base_command.rb', line 13 def summary @summary end |
Instance Method Details
#alter(&block) ⇒ Object
26 27 28 |
# File 'lib/choosy/base_command.rb', line 26 def alter(&block) @builder.evaluate!(&block) end |
#execute!(args, propagate = false) ⇒ Object
53 54 55 56 57 58 59 60 61 62 63 64 |
# File 'lib/choosy/base_command.rb', line 53 def execute!(args, propagate=false) if propagate execute(args) else begin execute(args) rescue Choosy::ClientExecutionError => e $stderr << "#{@name}: #{e.}\n" exit 1 end end end |
#finalize! ⇒ Object
66 67 68 69 70 |
# File 'lib/choosy/base_command.rb', line 66 def finalize! if @printer.nil? builder.printer :standard end end |
#options ⇒ Object
30 31 32 |
# File 'lib/choosy/base_command.rb', line 30 def @option_builders.tsort.map {|key| @option_builders[key].entity } end |
#parse!(args, propagate = false) ⇒ Object
34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 |
# File 'lib/choosy/base_command.rb', line 34 def parse!(args, propagate=false) if propagate return parse(args) else begin return parse(args) rescue Choosy::ValidationError, Choosy::ConversionError, Choosy::ParseError, Choosy::SuperParseError => e $stderr << "#{@name}: #{e.}\n" exit 1 rescue Choosy::HelpCalled => e handle_help(e) exit 0 rescue Choosy::VersionCalled => e $stdout << "#{e.}\n" exit 0 end end end |