]> git.ipfire.org Git - thirdparty/haproxy.git/commitdiff
MINOR: cli: alphanumerically sort the dump of supported commands
authorWilly Tarreau <w@1wt.eu>
Wed, 30 Mar 2022 10:02:35 +0000 (12:02 +0200)
committerWilly Tarreau <w@1wt.eu>
Wed, 30 Mar 2022 10:02:35 +0000 (12:02 +0200)
Like for previous keyword classes, we're sorting the output. But this
time as it's not trivial to do it with multiple words, instead we're
proceeding like the help command, we sort them on their usage message
when present, and fall back to the first word of the command when there
is no usage message (e.g. "help" command).

src/cli.c

index 9f4b8df5a14756db131bfcec3f6b0de17e40f0ee..25d28f14d1f54d07abd6a8408cc73dc2b4fe837a 100644 (file)
--- a/src/cli.c
+++ b/src/cli.c
@@ -372,24 +372,37 @@ void cli_register_kw(struct cli_kw_list *kw_list)
 void cli_list_keywords(void)
 {
        struct cli_kw_list *kw_list;
-       struct cli_kw *kw;
+       struct cli_kw *kwp, *kwn, *kw;
        int idx;
 
-       list_for_each_entry(kw_list, &cli_keywords.list, list) {
-               for (kw = &kw_list->kw[0]; kw->str_kw[0]; kw++) {
-                       for (idx = 0; kw->str_kw[idx]; idx++) {
-                               printf("%s ", kw->str_kw[idx]);
+       for (kwn = kwp = NULL;; kwp = kwn) {
+               list_for_each_entry(kw_list, &cli_keywords.list, list) {
+                       /* note: we sort based on the usage message when available,
+                        * otherwise we fall back to the first keyword.
+                        */
+                       for (kw = &kw_list->kw[0]; kw->str_kw[0]; kw++) {
+                               if (strordered(kwp ? kwp->usage ? kwp->usage : kwp->str_kw[0] : NULL,
+                                              kw->usage ? kw->usage : kw->str_kw[0],
+                                              kwn != kwp ? kwn->usage ? kwn->usage : kwn->str_kw[0] : NULL))
+                                       kwn = kw;
                        }
-                       if (kw->level & (ACCESS_MASTER_ONLY|ACCESS_MASTER))
-                               printf("[MASTER] ");
-                       if (!(kw->level & ACCESS_MASTER_ONLY))
-                               printf("[WORKER] ");
-                       if (kw->level & ACCESS_EXPERT)
-                               printf("[EXPERT] ");
-                       if (kw->level & ACCESS_EXPERIMENTAL)
-                               printf("[EXPERIM] ");
-                       printf("\n");
                }
+
+               if (kwn == kwp)
+                       break;
+
+               for (idx = 0; kwn->str_kw[idx]; idx++) {
+                       printf("%s ", kwn->str_kw[idx]);
+               }
+               if (kwn->level & (ACCESS_MASTER_ONLY|ACCESS_MASTER))
+                       printf("[MASTER] ");
+               if (!(kwn->level & ACCESS_MASTER_ONLY))
+                       printf("[WORKER] ");
+               if (kwn->level & ACCESS_EXPERT)
+                       printf("[EXPERT] ");
+               if (kwn->level & ACCESS_EXPERIMENTAL)
+                       printf("[EXPERIM] ");
+               printf("\n");
        }
 }