mirror of
https://github.com/ruby/ruby.git
synced 2022-11-09 12:17:21 -05:00
[ruby/optparse] Fixed error message of unparsed non-option
Close https://github.com/ruby/optparse/issues/3 https://github.com/ruby/optparse/commit/94c5cf4032
This commit is contained in:
parent
2bbae0e91a
commit
e8317d90b0
2 changed files with 13 additions and 0 deletions
|
@ -1646,7 +1646,12 @@ XXX
|
|||
end
|
||||
begin
|
||||
opt, cb, val = sw.parse(val, argv) {|*exc| raise(*exc) if eq}
|
||||
rescue ParseError
|
||||
raise $!.set_option(arg, arg.length > 2)
|
||||
else
|
||||
raise InvalidOption, arg if has_arg and !eq and arg == "-#{opt}"
|
||||
end
|
||||
begin
|
||||
argv.unshift(opt) if opt and (!rest or (opt = opt.sub(/\A-*/, '-')) != '-')
|
||||
val = cb.call(val) if cb
|
||||
setter.call(sw.switch_name, val) if setter
|
||||
|
|
|
@ -97,4 +97,12 @@ class TestOptionParser < Test::Unit::TestCase
|
|||
assert_raise(OptionParser::InvalidOption) {@opt.parse(%w(-zr foo))}
|
||||
assert_raise(OptionParser::InvalidOption) {@opt.parse(%w(-z foo))}
|
||||
end
|
||||
|
||||
def test_nonopt_pattern
|
||||
@opt.def_option(/^[^-]/) do |arg|
|
||||
assert(false, "Never gets called")
|
||||
end
|
||||
e = assert_raise(OptionParser::InvalidOption) {@opt.parse(%w(-t))}
|
||||
assert_equal(["-t"], e.args)
|
||||
end
|
||||
end
|
||||
|
|
Loading…
Add table
Reference in a new issue