From 450fd0876f83119fd7b8a30e5ceefc1f39031ef2 Mon Sep 17 00:00:00 2001 From: cgranleese-r7 Date: Thu, 8 Feb 2024 13:27:07 +0000 Subject: [PATCH] Improve unknown command handling --- lib/rex/ui/text/dispatcher_shell.rb | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/lib/rex/ui/text/dispatcher_shell.rb b/lib/rex/ui/text/dispatcher_shell.rb index 88b2e078f22f..ef8ca821fca1 100644 --- a/lib/rex/ui/text/dispatcher_shell.rb +++ b/lib/rex/ui/text/dispatcher_shell.rb @@ -588,7 +588,15 @@ def run_command(dispatcher, method, arguments) # If the command is unknown... # def unknown_command(method, line) - print_error("Unknown command: #{method}") + # Map each dispatchers commands to valid_commands + valid_commands = dispatcher_stack.flat_map { |dispatcher| dispatcher.commands.keys } + + message = "Unknown command: #{method}." + suggestion = DidYouMean::SpellChecker.new(dictionary: valid_commands).correct(method).first + message << " Did you mean %grn#{suggestion}%clr?" if suggestion + message << ' Run the %grnhelp%clr command for more details.' + + print_error(message) end #