Module: Anvil::Task::Options
- Included in:
- Anvil::Task
- Defined in:
- lib/anvil/task/options.rb
Overview
Cli options parsing definition
Instance Attribute Summary collapse
-
#parser_block ⇒ Object
readonly
Returns the value of attribute parser_block.
Instance Method Summary collapse
- #build_parser(&block) ⇒ Object
- #configure_parser(parser, &block) ⇒ Object
- #help ⇒ Object
- #parse_options!(arguments) ⇒ Object
- #parser(&block) ⇒ Object
Instance Attribute Details
#parser_block ⇒ Object (readonly)
Returns the value of attribute parser_block.
9 10 11 |
# File 'lib/anvil/task/options.rb', line 9 def parser_block @parser_block end |
Instance Method Details
#build_parser(&block) ⇒ Object
20 21 22 23 24 25 |
# File 'lib/anvil/task/options.rb', line 20 def build_parser(&block) parser = Anvil::Parser.new parser.task = self configure_parser(parser, &block) parser end |
#configure_parser(parser, &block) ⇒ Object
27 28 29 30 31 32 33 34 35 36 37 38 39 |
# File 'lib/anvil/task/options.rb', line 27 def configure_parser(parser, &block) block ||= proc {} if description parser.separator '' parser.separator description end parser.separator '' parser.separator 'Available options: ' parser.instance_eval(&block) parser end |
#help ⇒ Object
11 12 13 |
# File 'lib/anvil/task/options.rb', line 11 def help parser.help end |
#parse_options!(arguments) ⇒ Object
41 42 43 44 |
# File 'lib/anvil/task/options.rb', line 41 def (arguments) parser.parse!(arguments) arguments << parser. end |
#parser(&block) ⇒ Object
15 16 17 18 |
# File 'lib/anvil/task/options.rb', line 15 def parser(&block) @parser_block = block @parser ||= build_parser(&block) end |