@@ -1770,21 +1770,25 @@ def complete(typ, opt, icase = false, *pat)
1770
1770
end
1771
1771
raise AmbiguousOption , catch ( :ambiguous ) {
1772
1772
visit ( :complete , typ , opt , icase , *pat ) { |o , *sw | return sw }
1773
- if defined? DidYouMean ::SpellChecker
1774
- all_candidates = [ ]
1775
- visit ( :get_candidates , typ ) do |candidates |
1776
- all_candidates . concat ( candidates )
1777
- end
1778
- all_candidates . select! { |cand | cand . is_a? ( String ) }
1779
- suggestions = DidYouMean ::SpellChecker . new ( dictionary : all_candidates ) . correct ( opt )
1780
- raise InvalidOption . new ( opt , DidYouMean . formatter . message_for ( suggestions ) )
1781
- else
1782
- raise InvalidOption , opt
1783
- end
1773
+ raise InvalidOption . new ( opt , additional : self . :additional_message . curry [ typ ] )
1784
1774
}
1785
1775
end
1786
1776
private :complete
1787
1777
1778
+ #
1779
+ # Returns additional info.
1780
+ #
1781
+ def additional_message ( typ , opt )
1782
+ return unless typ and opt and defined? ( DidYouMean ::SpellChecker )
1783
+ all_candidates = [ ]
1784
+ visit ( :get_candidates , typ ) do |candidates |
1785
+ all_candidates . concat ( candidates )
1786
+ end
1787
+ all_candidates . select! { |cand | cand . is_a? ( String ) }
1788
+ checker = DidYouMean ::SpellChecker . new ( dictionary : all_candidates )
1789
+ DidYouMean . formatter . message_for ( checker . correct ( opt ) )
1790
+ end
1791
+
1788
1792
def candidate ( word )
1789
1793
list = [ ]
1790
1794
case word
@@ -2011,13 +2015,16 @@ class ParseError < RuntimeError
2011
2015
# Reason which caused the error.
2012
2016
Reason = 'parse error'
2013
2017
2014
- def initialize ( *args )
2018
+ def initialize ( *args , additional : nil )
2019
+ @additional = additional
2020
+ @arg0 , = args
2015
2021
@args = args
2016
2022
@reason = nil
2017
2023
end
2018
2024
2019
2025
attr_reader :args
2020
2026
attr_writer :reason
2027
+ attr_accessor :additional
2021
2028
2022
2029
#
2023
2030
# Pushes back erred argument(s) to +argv+.
@@ -2062,7 +2069,7 @@ def inspect
2062
2069
# Default stringizing method to emit standard error message.
2063
2070
#
2064
2071
def message
2065
- reason + ': ' + args . join ( " " ) . gsub ( / \s +$/ , "" )
2072
+ " #{ reason } : #{ args . join ( ' ' ) } #{ additional [ @arg0 ] if additional } "
2066
2073
end
2067
2074
2068
2075
alias to_s message
0 commit comments