Class: OptparseLite::OptParserAggregate

Inherits:
Object
  • Object
show all
Defined in:
lib/optparse-lite.rb

Overview

we take this opportunity to discover our interface for parsers: parse()

Instance Method Summary collapse

Constructor Details

#initialize(parsers) ⇒ OptParserAggregate

Returns a new instance of OptParserAggregate.



853
854
855
# File 'lib/optparse-lite.rb', line 853

def initialize parsers
  @parsers = parsers
end

Instance Method Details

#parse(args) ⇒ Object



856
857
858
859
860
861
862
863
864
# File 'lib/optparse-lite.rb', line 856

def parse args
  errors, opts = @parsers.first.parse(args)
  @parsers[1..-1].each do |parser|
    unparsed = errors.delete(:unparsed_parameters) || {}
    errors.concat parser.validate_and_populate(unparsed)
    opts.merge! unparsed
  end
  [errors, opts]
end