summaryrefslogtreecommitdiff
path: root/lib/rubygems/unknown_command_spell_checker.rb
diff options
context:
space:
mode:
Diffstat (limited to 'lib/rubygems/unknown_command_spell_checker.rb')
-rw-r--r--lib/rubygems/unknown_command_spell_checker.rb21
1 files changed, 21 insertions, 0 deletions
diff --git a/lib/rubygems/unknown_command_spell_checker.rb b/lib/rubygems/unknown_command_spell_checker.rb
new file mode 100644
index 0000000000..ee5c2fbe04
--- /dev/null
+++ b/lib/rubygems/unknown_command_spell_checker.rb
@@ -0,0 +1,21 @@
+# frozen_string_literal: true
+
+class Gem::UnknownCommandSpellChecker
+ attr_reader :error
+
+ def initialize(error)
+ @error = error
+ end
+
+ def corrections
+ @corrections ||=
+ spell_checker.correct(error.unknown_command).map(&:inspect)
+ end
+
+ private
+
+ def spell_checker
+ dictionary = Gem::CommandManager.instance.command_names
+ DidYouMean::SpellChecker.new(dictionary: dictionary)
+ end
+end