ruby-changes:58311
From: Nobuyoshi <ko1@a...>
Date: Fri, 18 Oct 2019 17:51:37 +0900 (JST)
Subject: [ruby-changes:58311] e2b719bed6 (master): Support DidYouMean by AmbiguousOption too
https://git.ruby-lang.org/ruby.git/commit/?id=e2b719bed6 From e2b719bed640d4813fd5f753c80d33d01c612078 Mon Sep 17 00:00:00 2001 From: Nobuyoshi Nakada <nobu@r...> Date: Fri, 18 Oct 2019 17:46:53 +0900 Subject: Support DidYouMean by AmbiguousOption too diff --git a/lib/optparse.rb b/lib/optparse.rb index 67beeb9..b028485 100644 --- a/lib/optparse.rb +++ b/lib/optparse.rb @@ -1768,10 +1768,11 @@ XXX https://github.com/ruby/ruby/blob/trunk/lib/optparse.rb#L1768 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 diff --git a/test/optparse/test_did_you_mean.rb b/test/optparse/test_did_you_mean.rb index 82a086a..19bb4b9 100644 --- a/test/optparse/test_did_you_mean.rb +++ b/test/optparse/test_did_you_mean.rb @@ -39,4 +39,10 @@ class TestOptionParser::DidYouMean < TestOptionParser https://github.com/ruby/ruby/blob/trunk/test/optparse/test_did_you_mean.rb#L39 @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 -- cgit v0.10.2 -- ML: ruby-changes@q... Info: http://www.atdot.net/~ko1/quickml/