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) ⇒ 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.
19 20 21 22 23 24 25 26 27 |
# File 'lib/choosy/base_command.rb', line 19 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.
17 18 19 |
# File 'lib/choosy/base_command.rb', line 17 def builder @builder end |
#listing ⇒ Object (readonly)
Returns the value of attribute listing.
17 18 19 |
# File 'lib/choosy/base_command.rb', line 17 def listing @listing end |
#name ⇒ Object
Returns the value of attribute name.
16 17 18 |
# File 'lib/choosy/base_command.rb', line 16 def name @name end |
#option_builders ⇒ Object (readonly)
Returns the value of attribute option_builders.
17 18 19 |
# File 'lib/choosy/base_command.rb', line 17 def option_builders @option_builders end |
#printer ⇒ Object
Returns the value of attribute printer.
16 17 18 |
# File 'lib/choosy/base_command.rb', line 16 def printer @printer end |
#summary ⇒ Object
Returns the value of attribute summary.
16 17 18 |
# File 'lib/choosy/base_command.rb', line 16 def summary @summary end |
Instance Method Details
#alter(&block) ⇒ Object
29 30 31 |
# File 'lib/choosy/base_command.rb', line 29 def alter(&block) @builder.evaluate!(&block) end |
#execute!(args) ⇒ Object
56 57 58 59 60 61 62 63 |
# File 'lib/choosy/base_command.rb', line 56 def execute!(args) begin execute(args) rescue Choosy::ClientExecutionError => e $stderr << "#{@name}: #{e.}\n" exit 1 end end |
#finalize! ⇒ Object
65 66 67 68 69 |
# File 'lib/choosy/base_command.rb', line 65 def finalize! if @printer.nil? builder.printer :standard end end |
#options ⇒ Object
33 34 35 |
# File 'lib/choosy/base_command.rb', line 33 def @option_builders.tsort.map {|key| @option_builders[key].entity } end |
#parse!(args, propagate = false) ⇒ Object
37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 |
# File 'lib/choosy/base_command.rb', line 37 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 |