command: on syntax error, run 'usage' inside the same cmd_ctx

We want the output of the 'usage' command to become the output of
the current command that has triggered the syntax error.

Don't use command_run_linef(), as it will first print the message,
then pass it to the current command that will use it again.
Replace command_run_linef() with Jim_Eval..().

Change-Id: Icefa87746156e6e8758026c0fdc5e02b440b3aaa
Signed-off-by: Antonio Borneo <borneo.antonio@gmail.com>
Reviewed-on: https://review.openocd.org/c/openocd/+/9185
Tested-by: jenkins
Reviewed-by: Evgeniy Naydanov <eugnay@gmail.com>
This commit is contained in:
Antonio Borneo
2025-10-24 10:07:10 +02:00
parent 586c8981b1
commit fcce5d52d9

View File

@@ -444,8 +444,8 @@ static int jim_exec_command(Jim_Interp *interp, struct command_context *context,
int retval = c->handler(&cmd);
if (retval == ERROR_COMMAND_SYNTAX_ERROR) {
/* Print help for command */
command_run_linef(context, "usage %s", words[0]);
// Print command syntax
Jim_EvalObjPrefix(context->interp, Jim_NewStringObj(context->interp, "usage", -1), 1, argv);
} else if (retval == ERROR_COMMAND_CLOSE_CONNECTION) {
/* just fall through for a shutdown request */
} else {