Skip to content

Commit

Permalink
Improve unknown command handling
Browse files Browse the repository at this point in the history
  • Loading branch information
cgranleese-r7 committed Feb 12, 2024
1 parent 9caa2fa commit 450fd08
Showing 1 changed file with 9 additions and 1 deletion.
10 changes: 9 additions & 1 deletion lib/rex/ui/text/dispatcher_shell.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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

#
Expand Down

0 comments on commit 450fd08

Please sign in to comment.