Class: WIP::Runner::Parser
- Inherits:
-
Object
- Object
- WIP::Runner::Parser
- Defined in:
- lib/wip/runner/parser.rb,
lib/wip/runner/parser/option_parser.rb
Defined Under Namespace
Classes: OptionParser
Instance Attribute Summary collapse
-
#config ⇒ Object
readonly
Returns the value of attribute config.
Instance Method Summary collapse
- #arguments ⇒ Object
- #help ⇒ Object
-
#initialize(ui, command) ⇒ Parser
constructor
A new instance of Parser.
- #options ⇒ Object
- #run(argv) ⇒ Object
Constructor Details
Instance Attribute Details
#config ⇒ Object (readonly)
Returns the value of attribute config.
6 7 8 |
# File 'lib/wip/runner/parser.rb', line 6 def config @config end |
Instance Method Details
#arguments ⇒ Object
66 67 68 |
# File 'lib/wip/runner/parser.rb', line 66 def arguments @command.arguments end |
#help ⇒ Object
37 38 39 40 41 |
# File 'lib/wip/runner/parser.rb', line 37 def help @ui.err { @ui.say(.help) } end |
#options ⇒ Object
43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 |
# File 'lib/wip/runner/parser.rb', line 43 def @options ||= OptionParser.new do |parser| @config.help = false @config.no_validate = false parser. = "Usage: #{WIP::Runner::CLI.signature} #{heading}" section(parser, 'Commands:', commands) section(parser, 'Arguments:', arguments) parser.separator '' parser.separator 'Options:' @command..each do |block| block.call(parser, @config) end parser.on_tail '-h', '--help', 'Prints help messages' do @config.help = true end end end |
#run(argv) ⇒ Object
14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 |
# File 'lib/wip/runner/parser.rb', line 14 def run(argv) unless commands.empty? command = argv.shift raise InvalidCommand if command.nil? yield(command, nil, nil) else remaining = .parse!(argv) @args = WIP::Runner::Options.new.tap do |opts| arguments.keys.each_with_index do |key, index| if arguments[key].multiple opts[key] = remaining[index..-1] break else opts[key] = remaining[index] end end end yield(nil, @args, @config) end end |