Skip to content

Commit

Permalink
MINOR: cli: add an 'echo' command
Browse files Browse the repository at this point in the history
Add an echo command to write text over the CLI output.
  • Loading branch information
wlallemand committed Oct 24, 2024
1 parent 944a224 commit dc1c0a1
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 0 deletions.
9 changes: 9 additions & 0 deletions doc/management.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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.

Expand Down
22 changes: 22 additions & 0 deletions src/cli.c
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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 },
Expand Down

0 comments on commit dc1c0a1

Please sign in to comment.