From: Willy Tarreau Date: Mon, 28 Apr 2025 16:51:47 +0000 (+0200) Subject: MEDIUM: mcli: make the prompt mode configurable between i/p X-Git-Tag: v3.2-dev13~55 X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=c347cb73fa77392802130716664962fbb116e62f;p=thirdparty%2Fhaproxy.git MEDIUM: mcli: make the prompt mode configurable between i/p Support the same syntax in master mode as in worker mode in order to configure the prompt. The only thing is that for now the master doesn't have a non-interactive mode and it doesn't seem necessary to implement it, so we only support the interactive and prompt modes. However the code was written in a way that makes it easy to change this later if desired. --- diff --git a/doc/management.txt b/doc/management.txt index 3ceea6b5f..52d3c61c4 100644 --- a/doc/management.txt +++ b/doc/management.txt @@ -2406,6 +2406,7 @@ prompt [help | n | i | p | timed]* The prompt mode is more suited to human users, the interactive mode to advanced scripts, and the non-interactive mode (default) to basic scripts. + Note that the non-interactive mode is not available for the master socket. quit Close the connection when in interactive mode. diff --git a/src/cli.c b/src/cli.c index 964ad8cf2..954087140 100644 --- a/src/cli.c +++ b/src/cli.c @@ -2865,12 +2865,51 @@ int pcli_find_and_exec_kw(struct stream *s, char **args, int argl, char **errmsg *next_pid = target_pid; return 1; } else if (strcmp("prompt", args[0]) == 0) { - if (argl >= 2 && strcmp(args[1], "timed") == 0) { - s->pcli_flags |= PCLI_F_PROMPT; + int mode = 0; // 0=default, 1="n" (not in master), 2="i", 3="p" + int timed = 0; // non-zero = "timed" present + int arg; + + const char *usage = + "Usage: prompt [help | i | p | timed]*\n" + "Changes the default prompt and interactive mode. Available options:\n" + " help display this help\n" + " i set to interactive mode only (no prompt, multi-command)\n" + " p set to prompt+interactive mode (prompt + multi-command)\n" + " timed toggle displaying the current date in the prompt\n" + "Without any argument, toggles between i<->p.\n" + ; + + for (arg = 1; arg < argl; arg++) { + if (strcmp(args[arg], "i") == 0) + mode = 2; + else if (strcmp(args[arg], "p") == 0) + mode = 3; + else if (strcmp(args[arg], "timed") == 0) + timed = 1; + else { + memprintf(errmsg, "%s", usage); + return -1; + } + } + + /* In timed mode, the default is to enable prompt+inter and toggle timed. + * In other mode, the default is to toggle prompt+inter (n/i->p, p->n). + */ + if (timed) { s->pcli_flags ^= PCLI_F_TIMED; + mode = mode ? mode : 3; // p by default } + + if (mode) { + /* force mode (i,p) */ + s->pcli_flags &= ~PCLI_F_PROMPT; + s->pcli_flags |= (mode >= 3) ? PCLI_F_PROMPT : 0; + } + else if (~s->pcli_flags & PCLI_F_PROMPT) + s->pcli_flags |= PCLI_F_PROMPT; // p else - s->pcli_flags ^= PCLI_F_PROMPT; + s->pcli_flags &= ~PCLI_F_PROMPT; // i + return argl; /* return the number of elements in the array */ } else if (strcmp("quit", args[0]) == 0) { sc_schedule_abort(s->scf);