From dc1c0a169c53cd941c340f9bfc690c18333ff607 Mon Sep 17 00:00:00 2001 From: William Lallemand Date: Thu, 24 Oct 2024 17:20:57 +0200 Subject: [PATCH] MINOR: cli: add an 'echo' command Add an echo command to write text over the CLI output. --- doc/management.txt | 9 +++++++++ src/cli.c | 22 ++++++++++++++++++++++ 2 files changed, 31 insertions(+) diff --git a/doc/management.txt b/doc/management.txt index c37dc536c6..f716cbad85 100644 --- a/doc/management.txt +++ b/doc/management.txt @@ -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 + 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 / Resume auxiliary agent check that was temporarily stopped. diff --git a/src/cli.c b/src/cli.c index 10456382d1..0d71280c28 100644 --- 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 : 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 },