Support DidYouMean by AmbiguousOption too
This commit is contained in:
parent
b4d308b419
commit
e2b719bed6
@ -1768,10 +1768,11 @@ XXX
|
|||||||
if pat.empty?
|
if pat.empty?
|
||||||
search(typ, opt) {|sw| return [sw, opt]} # exact match or...
|
search(typ, opt) {|sw| return [sw, opt]} # exact match or...
|
||||||
end
|
end
|
||||||
raise AmbiguousOption, catch(:ambiguous) {
|
ambiguous = catch(:ambiguous) {
|
||||||
visit(:complete, typ, opt, icase, *pat) {|o, *sw| return sw}
|
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
|
end
|
||||||
private :complete
|
private :complete
|
||||||
|
|
||||||
|
@ -39,4 +39,10 @@ class TestOptionParser::DidYouMean < TestOptionParser
|
|||||||
@opt.permute!(%w"--baa")
|
@opt.permute!(%w"--baa")
|
||||||
end
|
end
|
||||||
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
|
end
|
||||||
|
Loading…
x
Reference in New Issue
Block a user