MINOR: cli: split APPCTX_CLI_ST1_PROMPT into two distinct flags

The CLI's "prompt" command toggles two distinct things:
  - displaying or hiding the prompt at the beginning of the line
  - single-command vs interactive mode

These are two independent concepts and the prompt mode doesn't
always cope well with tools that would like to upload data without
having to read the prompt on return. Also, the master command line
works in interactive mode by default with no prompt, which is not
consistent (and not convenient for tools). So let's start by splitting
the bit in two, and have a new APPCTX_CLI_ST1_INTER flag dedicated
to the interactive mode. For now the "prompt" command alone continues
to toggle the two at once.
This commit is contained in:
Willy Tarreau 2025-04-28 17:42:03 +02:00
parent 5ac280f2a7
commit f25b4abc9b
2 changed files with 9 additions and 8 deletions

View File

@ -41,11 +41,12 @@
#define ACCESS_MCLI_SEVERITY_STR 0x0200 /* 'set severity-output string' on master CLI */
/* flags for appctx->st1 */
#define APPCTX_CLI_ST1_PROMPT (1 << 0)
#define APPCTX_CLI_ST1_PAYLOAD (1 << 1)
#define APPCTX_CLI_ST1_NOLF (1 << 2)
#define APPCTX_CLI_ST1_TIMED (1 << 3)
#define APPCTX_CLI_ST1_LASTCMD (1 << 4)
#define APPCTX_CLI_ST1_PAYLOAD (1 << 0)
#define APPCTX_CLI_ST1_NOLF (1 << 1)
#define APPCTX_CLI_ST1_LASTCMD (1 << 2)
#define APPCTX_CLI_ST1_INTER (1 << 3) /* interactive mode (i.e. don't close after 1st cmd) */
#define APPCTX_CLI_ST1_PROMPT (1 << 4) /* display prompt */
#define APPCTX_CLI_ST1_TIMED (1 << 5) /* display timer in prompt */
#define CLI_PREFIX_KW_NB 5
#define CLI_MAX_MATCHES 5

View File

@ -1260,7 +1260,7 @@ void cli_io_handler(struct appctx *appctx)
appctx->cli_ctx.payload = NULL;
appctx->cli_ctx.cmdline = NULL;
appctx->st1 &= ~APPCTX_CLI_ST1_LASTCMD;
if (appctx->st1 & APPCTX_CLI_ST1_PROMPT) {
if (appctx->st1 & APPCTX_CLI_ST1_INTER) {
appctx->st0 = CLI_ST_PARSE_CMDLINE;
applet_will_consume(appctx);
applet_expect_data(appctx);
@ -2497,11 +2497,11 @@ static int cli_parse_simple(char **args, char *payload, struct appctx *appctx, v
else if (*args[0] == 'p')
/* prompt */
if (strcmp(args[1], "timed") == 0) {
appctx->st1 |= APPCTX_CLI_ST1_PROMPT;
appctx->st1 |= APPCTX_CLI_ST1_PROMPT | APPCTX_CLI_ST1_INTER;
appctx->st1 ^= APPCTX_CLI_ST1_TIMED;
}
else
appctx->st1 ^= APPCTX_CLI_ST1_PROMPT;
appctx->st1 ^= APPCTX_CLI_ST1_PROMPT | APPCTX_CLI_ST1_INTER;
else if (*args[0] == 'q') {
/* quit */
applet_set_eoi(appctx);