MINOR: cli: print parsed command when not found
It is useful because when we're passing data to runtime API, specially via code, we can mistakenly send newlines leading to some lines being wrongly interpretted as commands. This is analogous to how it's done in a shell, example bash: $ not_found arg1 bash: not_found: command not found... $ Real world example: Following the official docs to add a cert: $ echo -e "set ssl cert ./cert.pem <<\n$(cat ./cert.pem)\n" | socat stdio tcp4-connect:127.0.0.1:9999 Note, how the payload is sent via '<<\n$(cat ./cert.pem)\n'. If cert.pem contains a newline between various PEM blocks, which is valid, the above command would generate a flood of 'Unknown command' messages for every line sent after the first newline. As a new user, this detail is not clearly visible as socket API doesn't say what exactly what was 'unknown' about it. The cli interface should be obvious around guiding user on "what do do next". This commit changes that by printing the parsed cmd in output like 'Unknown command: "<cmd>"' so the user gets clear "next steps", like bash, regarding what indeed was the wrong command that HAproxy couldn't interpret. Previously: $ echo -e "show version\nhelpp"| socat ./haproxy.sock - | head -n4 2.7-dev6 Unknown command, but maybe one of the following ones is a better match: add map [@<ver>] <map> <key> <val> : add a map entry (payload supported instead of key/val) Now: $ echo -e "show version\nhelpp"| socat ./haproxy.sock - | head -n4 2.7-dev8-737bb7-156 Unknown command: 'helpp', but maybe one of the following ones is a better match: add map [@<ver>] <map> <key> <val> : add a map entry (payload supported instead of key/val)
This commit is contained in:
parent
814645f42f
commit
c8601507b2
15
src/cli.c
15
src/cli.c
@ -170,10 +170,17 @@ static char *cli_gen_usage_msg(struct appctx *appctx, char * const *args)
|
||||
chunk_reset(tmp);
|
||||
if (ishelp) // this is the help message.
|
||||
chunk_strcat(tmp, "The following commands are valid at this level:\n");
|
||||
else if (!length && (!args || !*args || !**args)) // no match
|
||||
chunk_strcat(tmp, "Unknown command. Please enter one of the following commands only:\n");
|
||||
else // partial match
|
||||
chunk_strcat(tmp, "Unknown command, but maybe one of the following ones is a better match:\n");
|
||||
else {
|
||||
chunk_strcat(tmp, "Unknown command: '");
|
||||
if (args && *args)
|
||||
chunk_strcat(tmp, *args);
|
||||
chunk_strcat(tmp, "'");
|
||||
|
||||
if (!length && (!args || !*args || !**args)) // no match
|
||||
chunk_strcat(tmp, ". Please enter one of the following commands only:\n");
|
||||
else // partial match
|
||||
chunk_strcat(tmp, ", but maybe one of the following ones is a better match:\n");
|
||||
}
|
||||
|
||||
for (idx = 0; idx < CLI_MAX_MATCHES; idx++) {
|
||||
matches[idx].kw = NULL;
|
||||
|
Loading…
x
Reference in New Issue
Block a user