Skip to content

Commit dc1c0a1

Browse files
committed
MINOR: cli: add an 'echo' command
Add an echo command to write text over the CLI output.
1 parent 944a224 commit dc1c0a1

File tree

2 files changed

+31
-0
lines changed

2 files changed

+31
-0
lines changed

doc/management.txt

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2131,6 +2131,15 @@ dump stats-file
21312131
Generate a stats-file which can be used to preload haproxy counters values on
21322132
startup. See "Stats-file" section for more detail.
21332133

2134+
echo <text>
2135+
Print some text with the CLI. Can be useful to wrote commentaries between
2136+
commands when dumping the result of multiple commands.
2137+
2138+
Example:
2139+
2140+
echo "expert-mode on; echo FDs from fdtab; show fd; echo wild FDs; debug dev fd" | socat /var/run/haproxy.sock -
2141+
2142+
21342143
enable agent <backend>/<server>
21352144
Resume auxiliary agent check that was temporarily stopped.
21362145

src/cli.c

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2467,6 +2467,27 @@ static int cli_parse_simple(char **args, char *payload, struct appctx *appctx, v
24672467
return 1;
24682468
}
24692469

2470+
static int cli_parse_echo(char **args, char *payload, struct appctx *appctx, void *private)
2471+
{
2472+
int i = 1; /* starts after 'echo' */
2473+
2474+
chunk_reset(&trash);
2475+
2476+
while (*args[i]) {
2477+
/* add a space if there was a word before */
2478+
if (i == 1)
2479+
chunk_printf(&trash, "%s", args[i]);
2480+
else
2481+
chunk_appendf(&trash, " %s", args[i]);
2482+
i++;
2483+
}
2484+
chunk_appendf(&trash, "\n");
2485+
2486+
cli_msg(appctx, LOG_INFO, trash.area);
2487+
2488+
return 1;
2489+
}
2490+
24702491
static int _send_status(char **args, char *payload, struct appctx *appctx, void *private)
24712492
{
24722493
struct listener *mproxy_li;
@@ -3631,6 +3652,7 @@ static struct applet mcli_applet = {
36313652
/* register cli keywords */
36323653
static struct cli_kw_list cli_kws = {{ },{
36333654
{ { "help", NULL }, NULL, cli_parse_simple, NULL, NULL, NULL, ACCESS_MASTER },
3655+
{ { "echo", NULL }, "echo <text> : print text to the output", cli_parse_echo, NULL, NULL, NULL, ACCESS_MASTER },
36343656
{ { "prompt", NULL }, NULL, cli_parse_simple, NULL, NULL, NULL, ACCESS_MASTER },
36353657
{ { "quit", NULL }, NULL, cli_parse_simple, NULL, NULL, NULL, ACCESS_MASTER },
36363658
{ { "_getsocks", NULL }, NULL, _getsocks, NULL },

0 commit comments

Comments
 (0)