]> git.ipfire.org Git - thirdparty/haproxy.git/commitdiff
MINOR: cli: split APPCTX_CLI_ST1_PROMPT into two distinct flags
authorWilly Tarreau <w@1wt.eu>
Mon, 28 Apr 2025 15:42:03 +0000 (17:42 +0200)
committerWilly Tarreau <w@1wt.eu>
Mon, 28 Apr 2025 18:21:06 +0000 (20:21 +0200)
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.

include/haproxy/cli-t.h
src/cli.c

index f3b931f9b7b5bfdab3268aba461e949104087911..45eed35bc8e677e8dc363ac4117af10d9b07d76a 100644 (file)
 #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
index 5791a89ce613bc4b80afe9bb556776bb90d0d8b5..663bdad696fe7444983889645fcd80902bb0af78 100644 (file)
--- a/src/cli.c
+++ b/src/cli.c
@@ -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);