]> git.ipfire.org Git - thirdparty/haproxy.git/commitdiff
MINOR: cli: sort the suggestions by order of relevance
authorWilly Tarreau <w@1wt.eu>
Mon, 15 Mar 2021 09:35:04 +0000 (10:35 +0100)
committerWilly Tarreau <w@1wt.eu>
Mon, 15 Mar 2021 09:39:45 +0000 (10:39 +0100)
Now the suggested keywords are sorted with the most relevant ones first
instead of scanning them all in registration order and only dumping the
proposed ones:

- "tra"
   trace <module> [cmd [args...]] : manage live tracing
   operator       : lower the level of the current CLI session to operator
   user           : lower the level of the current CLI session to user
   show trace [<module>] : show live tracing state

- "pool"
   show pools     : report information about the memory pools usage
   add acl        : add acl entry
   del map        : delete map entry
   user           : lower the level of the current CLI session to user
   del acl        : delete acl entry

- "sh ta"
   show stat      : report counters for each proxy and server [desc|json|no-maint|typed|up]*
   show tasks     : show running tasks
   set table [id] : update or create a table entry's data
   show table [id]: report table usage stats or dump this table's contents
   trace <module> [cmd [args...]] : manage live tracing

- "sh state"
   show stat      : report counters for each proxy and server [desc|json|no-maint|typed|up]*
   set table [id] : update or create a table entry's data
   show table [id]: report table usage stats or dump this table's contents
   show servers state [id]: dump volatile server information (for backend <id>)
   show sess [id] : report the list of current sessions or dump this session

src/cli.c

index 010655ac67ed54573f0e86e19d05f7333b02a14c..c2874443337582d6a470d23975722b60b957c30a 100644 (file)
--- a/src/cli.c
+++ b/src/cli.c
@@ -203,7 +203,26 @@ static char *cli_gen_usage_msg(struct appctx *appctx, char * const *args)
                }
        }
 
+       if (matches[0].kw) {
+               /* we have fuzzy matches, let's propose them */
+               for (idx = 0; idx < CLI_MAX_MATCHES; idx++) {
+                       kw = matches[idx].kw;
+                       if (!kw)
+                               break;
+
+                       /* stop the dump if some words look very unlikely candidates */
+                       if (matches[idx].dist > 5*matches[0].dist/2)
+                               break;
+
+                       chunk_appendf(tmp, "  %s\n", kw->usage);
+               }
+       }
+
        list_for_each_entry(kw_list, &cli_keywords.list, list) {
+               /* no full dump if we've already found nice candidates */
+               if (matches[0].kw)
+                       break;
+
                for (kw = &kw_list->kw[0]; kw->str_kw[0]; kw++) {
 
                        /* in a worker or normal process, don't display master-only commands
@@ -228,19 +247,8 @@ static char *cli_gen_usage_msg(struct appctx *appctx, char * const *args)
                                        break;
                        }
 
-                       if (kw->usage && idx == length) {
-                               /* if we've filled some fuzzy matches, let's compare them. We'll
-                                * just set the idx to their position if they're found and are no
-                                * further than twice the distance of the best match, otherwise
-                                * idx will be CLI_MAX_MATCHES, indicating "not found".
-                                */
-                               for (idx = 0; matches[0].kw && idx < CLI_MAX_MATCHES; idx++)
-                                       if (kw == matches[idx].kw && matches[idx].dist <= 5*matches[0].dist/2)
-                                               break;
-
-                               if (idx < CLI_MAX_MATCHES)
-                                       chunk_appendf(tmp, "  %s\n", kw->usage);
-                       }
+                       if (kw->usage && idx == length)
+                               chunk_appendf(tmp, "  %s\n", kw->usage);
                }
        }