]> git.ipfire.org Git - thirdparty/haproxy.git/commitdiff
MINOR: cli: add an 'echo' command
authorWilliam Lallemand <wlallemand@haproxy.com>
Thu, 24 Oct 2024 15:20:57 +0000 (17:20 +0200)
committerWilliam Lallemand <wlallemand@haproxy.com>
Thu, 24 Oct 2024 15:20:57 +0000 (17:20 +0200)
Add an echo command to write text over the CLI output.

doc/management.txt
src/cli.c

index c37dc536c614a9d3f0eb234733ecb22b28a1224f..f716cbad851b485aaa10fc8065ee55acd9a2e9cd 100644 (file)
@@ -2131,6 +2131,15 @@ dump stats-file
   Generate a stats-file which can be used to preload haproxy counters values on
   startup. See "Stats-file" section for more detail.
 
+echo <text>
+  Print some text with the CLI. Can be useful to wrote commentaries between
+  commands when dumping the result of multiple commands.
+
+  Example:
+
+    echo "expert-mode on; echo FDs from fdtab; show fd; echo wild FDs; debug dev fd" | socat /var/run/haproxy.sock -
+
+
 enable agent <backend>/<server>
   Resume auxiliary agent check that was temporarily stopped.
 
index 10456382d167cf0e756fcf3bedd8030ecfedb3a8..0d71280c28cdf4aba30a3c4d70c49fe732622ac8 100644 (file)
--- a/src/cli.c
+++ b/src/cli.c
@@ -2467,6 +2467,27 @@ static int cli_parse_simple(char **args, char *payload, struct appctx *appctx, v
        return 1;
 }
 
+static int cli_parse_echo(char **args, char *payload, struct appctx *appctx, void *private)
+{
+       int i = 1; /* starts after 'echo' */
+
+       chunk_reset(&trash);
+
+       while (*args[i]) {
+               /* add a space if there was a word before */
+               if (i == 1)
+                       chunk_printf(&trash, "%s", args[i]);
+               else
+                       chunk_appendf(&trash, " %s", args[i]);
+               i++;
+       }
+       chunk_appendf(&trash, "\n");
+
+       cli_msg(appctx, LOG_INFO, trash.area);
+
+       return 1;
+}
+
 static int _send_status(char **args, char *payload, struct appctx *appctx, void *private)
 {
        struct listener *mproxy_li;
@@ -3631,6 +3652,7 @@ static struct applet mcli_applet = {
 /* register cli keywords */
 static struct cli_kw_list cli_kws = {{ },{
        { { "help", NULL },                      NULL,                                                                                                cli_parse_simple, NULL, NULL, NULL, ACCESS_MASTER },
+       { { "echo", NULL },                      "echo <text>                             : print text to the output",                                cli_parse_echo,   NULL, NULL, NULL, ACCESS_MASTER },
        { { "prompt", NULL },                    NULL,                                                                                                cli_parse_simple, NULL, NULL, NULL, ACCESS_MASTER },
        { { "quit", NULL },                      NULL,                                                                                                cli_parse_simple, NULL, NULL, NULL, ACCESS_MASTER },
        { { "_getsocks", NULL },                 NULL,                                                                                                _getsocks, NULL },