From a9910997419f36afb6ef724e6024c0673f435719 Mon Sep 17 00:00:00 2001 From: "FUJI Goro (gfx)" Date: Tue, 20 Mar 2018 16:51:09 +0900 Subject: [PATCH] support did_you_mean >= v1.2.0 which has a breaking change on formatters --- lib/rake/task_manager.rb | 16 +++++++++++----- 1 file changed, 11 insertions(+), 5 deletions(-) diff --git a/lib/rake/task_manager.rb b/lib/rake/task_manager.rb index e2531c8ef..1d1f7b4ce 100644 --- a/lib/rake/task_manager.rb +++ b/lib/rake/task_manager.rb @@ -61,16 +61,22 @@ def [](task_name, scopes=nil) def generate_message_for_undefined_task(task_name) message = "Don't know how to build task '#{task_name}' (see --tasks)" + message + generate_did_you_mean_suggestions(task_name) + end - suggestion_message = \ - if defined?(::DidYouMean::SpellChecker) && defined?(::DidYouMean::Formatter) - suggestions = ::DidYouMean::SpellChecker.new(dictionary: @tasks.keys).correct(task_name.to_s) + def generate_did_you_mean_suggestions(task_name) + if defined?(::DidYouMean::SpellChecker) + suggestions = ::DidYouMean::SpellChecker.new(dictionary: @tasks.keys).correct(task_name.to_s) + if ::DidYouMean.respond_to?(:formatter)# did_you_mean v1.2.0 or later + ::DidYouMean.formatter.message_for(suggestions) + elsif defined?(::DidYouMean::Formatter) # before did_you_mean v1.2.0 ::DidYouMean::Formatter.new(suggestions).to_s else "" end - - message + suggestion_message + else + "" + end end def synthesize_file_task(task_name) # :nodoc: