From: Vsevolod Stakhov Date: Fri, 25 May 2018 15:42:38 +0000 (+0100) Subject: [Minor] Suggest command if not found X-Git-Tag: 1.7.6~99 X-Git-Url: https://source.dussan.org/?a=commitdiff_plain;h=3d80b31e028916b325c7884b9ed89bf47e9a1ece;p=rspamd.git [Minor] Suggest command if not found --- diff --git a/src/rspamadm/rspamadm.c b/src/rspamadm/rspamadm.c index e20f9ee83..df68f6139 100644 --- a/src/rspamadm/rspamadm.c +++ b/src/rspamadm/rspamadm.c @@ -384,7 +384,16 @@ main (gint argc, gchar **argv, gchar **env) cmd = rspamadm_search_command (cmd_name, all_commands); if (cmd == NULL) { - fprintf (stderr, "Invalid command name: %s\n", cmd_name); + rspamd_fprintf (stderr, "Invalid command name: %s\n", cmd_name); + + /* Try fuzz search */ + rspamd_fprintf (stderr, "Suggested commands:\n"); + PTR_ARRAY_FOREACH (all_commands, i, cmd) { + if (rspamd_strings_levenshtein_distance (cmd->name, 0, cmd_name, 0, 1) == 1) { + rspamd_fprintf (stderr, "%s\n", cmd->name); + } + } + exit (EXIT_FAILURE); }