]> source.dussan.org Git - rspamd.git/commitdiff
[Minor] Suggest command if not found
authorVsevolod Stakhov <vsevolod@highsecure.ru>
Fri, 25 May 2018 15:42:38 +0000 (16:42 +0100)
committerVsevolod Stakhov <vsevolod@highsecure.ru>
Fri, 25 May 2018 15:42:38 +0000 (16:42 +0100)
src/rspamadm/rspamadm.c

index e20f9ee83177f0a0d792e888bedb042931572e47..df68f61392942d6beb848bfa0127544111b4f66d 100644 (file)
@@ -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);
        }