]> git.ipfire.org Git - thirdparty/haproxy.git/commitdiff
MINOR: cli: make "help" support a command in argument
authorWilly Tarreau <w@1wt.eu>
Sun, 9 May 2021 18:59:23 +0000 (20:59 +0200)
committerWilly Tarreau <w@1wt.eu>
Sun, 9 May 2021 18:59:23 +0000 (20:59 +0200)
With ~100 commands on the CLI, it's particularly difficult to find a
specific one in the "help" output. The function used to display the
help already supports filtering on certain commands, so in the end it's
just needed to pass the argument of the help command to enable the
automatic filtering. That's what this patch does so that "help clear"
only lists commands starting with "clear" and that "help map" lists
commands containing "map" in them.

doc/management.txt
src/cli.c

index fd96272775be397209b8fca61108c0a06e3ef9e7..3770c89d676a094c50a07986c85fc1d615b6fc64 100644 (file)
@@ -1840,9 +1840,10 @@ get weight <backend>/<server>
   may be specified either by their name or by their numeric ID, prefixed with a
   sharp ('#').
 
-help
-  Print the list of known keywords and their basic usage. The same help screen
-  is also displayed for unknown commands.
+help [<command>]
+  Print the list of known keywords and their basic usage, or commands matching
+  the requested one. The same help screen is also displayed for unknown
+  commands.
 
 new ssl cert <filename>
   Create a new empty SSL certificate store to be filled with a certificate and
index c5009a3bccd1d091f1033e55ae48d7b2e313d738..9a979a13f50d95ce40847bce9957d5b4d4427cb7 100644 (file)
--- a/src/cli.c
+++ b/src/cli.c
@@ -96,10 +96,16 @@ static char *cli_gen_usage_msg(struct appctx *appctx, char * const *args)
        struct buffer out;
        struct { struct cli_kw *kw; int dist; } matches[CLI_MAX_MATCHES], swp;
        int idx;
+       int ishelp = 0;
        int length = 0;
 
        ha_free(&dynamic_usage_msg);
 
+       if (args && *args && strcmp(*args, "help") == 0) {
+               args++;
+               ishelp = 1;
+       }
+
        /* first, let's measure the longest match */
        list_for_each_entry(kw_list, &cli_keywords.list, list) {
                for (kw = &kw_list->kw[0]; kw->str_kw[0]; kw++) {
@@ -125,7 +131,7 @@ static char *cli_gen_usage_msg(struct appctx *appctx, char * const *args)
 
        /* now <length> equals the number of exactly matching words */
        chunk_reset(tmp);
-       if (!args) // this is the help message.
+       if (ishelp) // this is the help message.
                chunk_strcat(tmp, "The following commands are valid at this level:\n");
        else if (!length && (!*args || !**args)) // no match
                chunk_strcat(tmp, "Unknown command. Please enter one of the following commands only:\n");
@@ -254,7 +260,7 @@ static char *cli_gen_usage_msg(struct appctx *appctx, char * const *args)
 
        /* always show the prompt/help/quit commands */
        chunk_strcat(tmp,
-                    "  help                                    : full commands list\n"
+                    "  help [<command>]                        : list matching or all commands\n"
                     "  prompt                                  : toggle interactive mode with prompt\n"
                     "  quit                                    : disconnect\n");
 
@@ -2040,7 +2046,7 @@ static int cli_parse_simple(char **args, char *payload, struct appctx *appctx, v
 {
        if (*args[0] == 'h')
                /* help */
-               cli_gen_usage_msg(appctx, NULL);
+               cli_gen_usage_msg(appctx, args);
        else if (*args[0] == 'p')
                /* prompt */
                appctx->st1 ^= APPCTX_CLI_ST1_PROMPT;