target: rewrite command 'target current' as COMMAND_HANDLER

While there add the mandatory 'usage' field.

Change-Id: I3e5b826ca58f7ade30a443ada0cb4a9cd9ea35c2
Signed-off-by: Antonio Borneo <borneo.antonio@gmail.com>
Reviewed-on: https://review.openocd.org/c/openocd/+/7508
Tested-by: jenkins
This commit is contained in:
Antonio Borneo 2022-12-19 23:50:23 +01:00
parent 583efa68f7
commit 26f457896c
1 changed files with 9 additions and 11 deletions

View File

@ -6365,19 +6365,16 @@ static int target_create(struct jim_getopt_info *goi)
return JIM_OK; return JIM_OK;
} }
static int jim_target_current(Jim_Interp *interp, int argc, Jim_Obj *const *argv) COMMAND_HANDLER(handle_target_current)
{ {
if (argc != 1) { if (CMD_ARGC != 0)
Jim_WrongNumArgs(interp, 1, argv, "Too many parameters"); return ERROR_COMMAND_SYNTAX_ERROR;
return JIM_ERR;
}
struct command_context *cmd_ctx = current_command_context(interp);
assert(cmd_ctx);
struct target *target = get_current_target_or_null(cmd_ctx); struct target *target = get_current_target_or_null(CMD_CTX);
if (target) if (target)
Jim_SetResultString(interp, target_name(target), -1); command_print(CMD, "%s", target_name(target));
return JIM_OK;
return ERROR_OK;
} }
static int jim_target_types(Jim_Interp *interp, int argc, Jim_Obj *const *argv) static int jim_target_types(Jim_Interp *interp, int argc, Jim_Obj *const *argv)
@ -6522,8 +6519,9 @@ static const struct command_registration target_subcommand_handlers[] = {
{ {
.name = "current", .name = "current",
.mode = COMMAND_ANY, .mode = COMMAND_ANY,
.jim_handler = jim_target_current, .handler = handle_target_current,
.help = "Returns the currently selected target", .help = "Returns the currently selected target",
.usage = "",
}, },
{ {
.name = "types", .name = "types",