1
0
Fork 0
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:
Nobuyoshi Nakada 2019-10-18 17:46:53 +09:00
parent b4d308b419
commit e2b719bed6
No known key found for this signature in database
GPG key ID: 4BC7D6DF58D8DF60
2 changed files with 9 additions and 2 deletions

View file

@ -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

View file

@ -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