mirror of
https://github.com/ruby/ruby.git
synced 2022-11-09 12:17:21 -05:00
Support DidYouMean by AmbiguousOption too
This commit is contained in:
parent
b4d308b419
commit
e2b719bed6
2 changed files with 9 additions and 2 deletions
|
@ -1768,10 +1768,11 @@ XXX
|
|||
if pat.empty?
|
||||
search(typ, opt) {|sw| return [sw, opt]} # exact match or...
|
||||
end
|
||||
raise AmbiguousOption, catch(:ambiguous) {
|
||||
ambiguous = catch(:ambiguous) {
|
||||
visit(:complete, typ, opt, icase, *pat) {|o, *sw| return sw}
|
||||
raise InvalidOption.new(opt, additional: self.:additional_message.curry[typ])
|
||||
}
|
||||
exc = ambiguous ? AmbiguousOption : InvalidOption
|
||||
raise exc.new(opt, additional: self.:additional_message.curry[typ])
|
||||
end
|
||||
private :complete
|
||||
|
||||
|
|
|
@ -39,4 +39,10 @@ class TestOptionParser::DidYouMean < TestOptionParser
|
|||
@opt.permute!(%w"--baa")
|
||||
end
|
||||
end
|
||||
|
||||
def test_ambiguos
|
||||
assert_raise_with_message(OptionParser::AmbiguousOption, /ambiguous option: --ba\nDid you mean\?\s+baz\s+bar\Z/) do
|
||||
@opt.permute!(%w"--ba")
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
Loading…
Reference in a new issue