Module: RakeCommander::Options::Error::ClassMethods
- Defined in:
- lib/rake-commander/options/error.rb
Instance Method Summary collapse
-
#parse_options(argv = ARGV, results: {}, leftovers: [], &block) ⇒ Object
Re-open method to add all the error handling.
Instance Method Details
#parse_options(argv = ARGV, results: {}, leftovers: [], &block) ⇒ Object
Re-open method to add all the error handling.
23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 |
# File 'lib/rake-commander/options/error.rb', line 23 def (argv = ARGV, results: {}, leftovers: [], &block) with_error_handling(argv, results, leftovers) do super.tap do check_on_leftovers(leftovers) check_required_presence(results) end rescue OptionParser::InvalidOption => e eklass = RakeCommander::Options::Error::InvalidOption raise eklass.new(e, from: self), nil, cause: nil rescue OptionParser::MissingArgument => e eklass = RakeCommander::Options::Error::MissingArgument opt = error_option(e, eklass) msg = e. msg = "missing required argument: #{opt.name_hyphen} (#{opt.short_hyphen})" if opt raise eklass.new(from: self, option: opt), msg, cause: nil rescue OptionParser::InvalidArgument => e eklass = RakeCommander::Options::Error::InvalidArgument src_e = nil msg = nil opt = error_option(e, eklass) if opt&.enum? msg = "argument in option #{opt.name_hyphen} (#{opt.short_hyphen}) " msg << "should be any of [#{opt.enum_options.join(' | ')}]" elsif opt&.argument_required? eklass = RakeCommander::Options::Error::MissingArgument msg = "missing required argument in option: #{opt.name_hyphen} (#{opt.short_hyphen})" else src_e = e end raise eklass.new(src_e, from: self, option: opt), msg, cause: nil end end |