[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
@ -1646,7 +1646,12 @@ XXX
|
|||||||
end
|
end
|
||||||
begin
|
begin
|
||||||
opt, cb, val = sw.parse(val, argv) {|*exc| raise(*exc) if eq}
|
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}"
|
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-*/, '-')) != '-')
|
argv.unshift(opt) if opt and (!rest or (opt = opt.sub(/\A-*/, '-')) != '-')
|
||||||
val = cb.call(val) if cb
|
val = cb.call(val) if cb
|
||||||
setter.call(sw.switch_name, val) if setter
|
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(-zr foo))}
|
||||||
assert_raise(OptionParser::InvalidOption) {@opt.parse(%w(-z foo))}
|
assert_raise(OptionParser::InvalidOption) {@opt.parse(%w(-z foo))}
|
||||||
end
|
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
|
end
|
||||||
|
Loading…
x
Reference in New Issue
Block a user