diff options
author | Nobuyoshi Nakada <[email protected]> | 2019-10-18 17:39:16 +0900 |
---|---|---|
committer | Nobuyoshi Nakada <[email protected]> | 2019-10-18 17:39:16 +0900 |
commit | b4d308b41939659fe8a4df28afc82eb5205709d1 () | |
tree | f72746f7a12d7515ffe6eb4925e1776eb7892bb1 /lib/optparse.rb | |
parent | e29e49abf018730d8419b4797ff17942e00d810b (diff) |
Defer adding additional info until getting the message of an error
-rw-r--r-- | lib/optparse.rb | 33 |
1 files changed, 20 insertions, 13 deletions
@@ -1770,21 +1770,25 @@ XXX end raise AmbiguousOption, catch(:ambiguous) { visit(:complete, typ, opt, icase, *pat) {|o, *sw| return sw} - if defined? DidYouMean::SpellChecker - all_candidates = [] - visit(:get_candidates, typ) do |candidates| - all_candidates.concat(candidates) - end - all_candidates.select! {|cand| cand.is_a?(String) } - suggestions = DidYouMean::SpellChecker.new(dictionary: all_candidates).correct(opt) - raise InvalidOption.new(opt, DidYouMean.formatter.message_for(suggestions)) - else - raise InvalidOption, opt - end } end private :complete def candidate(word) list = [] case word @@ -2011,13 +2015,16 @@ XXX # Reason which caused the error. Reason = 'parse error' - def initialize(*args) @args = args @reason = nil end attr_reader :args attr_writer :reason # # Pushes back erred argument(s) to +argv+. @@ -2062,7 +2069,7 @@ XXX # Default stringizing method to emit standard error message. # def message - reason + ': ' + args.join(" ").gsub(/\s+$/, "") end alias to_s message |