class PrimoCentralCounter::OptionParser
This class wraps the original OptionParser
to “repair” some bad behaviour.
Public Instance Methods
add_officious()
click to toggle source
Usually, OptionParser
adds default handlers for help, version, etc. This is a undocumented behavoir and some cases not intended, because the default handler also stops execution immediately. Thatswhy we remove some of them.
Calls superclass method
# File lib/primo_central_counter/option_parser.rb, line 9 def add_officious super base.long.reject! { |_key, _| _key == "help" || _key == "version" } end
parse!(argv)
click to toggle source
The original option parser stops processing if it sees any options it does not know. This implementation uses order!, which is a lower level OptionParser
method to get the requested behavior. Because parse uses parse!
internally, this automatically fixes parse.
# File lib/primo_central_counter/option_parser.rb, line 18 def parse!(argv) unprocessed_options = [] begin order!(argv) do |_non_option| unprocessed_options << _non_option end rescue InvalidOption => e unprocessed_options << e.args.first retry end .tap do argv.concat(unprocessed_options) end end