X-Git-Url: https://git.gag.com/?a=blobdiff_plain;f=src%2Fhelper%2Fcommand.c;h=3ed8dc87d8d55fecfe2416ca4c3360211f67c4f7;hb=ad0847ca38e4c9d7ea0051ac7718afd3aa61868e;hp=552031df063d1614e53e143bb910ac18f57388a3;hpb=4c1190624124b182a8502aa011354a1b9676aa8a;p=fw%2Fopenocd diff --git a/src/helper/command.c b/src/helper/command.c index 552031df0..3ed8dc87d 100644 --- a/src/helper/command.c +++ b/src/helper/command.c @@ -323,6 +323,22 @@ static struct command *command_new(struct command_context *cmd_ctx, { assert(cr->name); + /* + If it is a non-jim command with no .usage specified, + log an error. + + strlen(.usage) == 0 means that the command takes no + arguments. + */ + if ((cr->jim_handler == NULL) && + (cr->usage == NULL)) { + LOG_DEBUG("BUG: command '%s%s%s' does not have the " + "'.usage' field filled out", + parent && parent->name ? parent->name : "", + parent && parent->name ? " " : "", + cr->name); + } + struct command *c = calloc(1, sizeof(struct command)); if (NULL == c) return NULL; @@ -478,7 +494,7 @@ int unregister_command(struct command_context *context, struct command *parent, const char *name) { if ((!context) || (!name)) - return ERROR_INVALID_ARGUMENTS; + return ERROR_COMMAND_SYNTAX_ERROR; struct command *p = NULL; struct command **head = command_list_for_parent(context, parent); @@ -816,12 +832,12 @@ static COMMAND_HELPER(command_help_find, struct command *head, struct command **out) { if (0 == CMD_ARGC) - return ERROR_INVALID_ARGUMENTS; + return ERROR_COMMAND_SYNTAX_ERROR; *out = command_find(head, CMD_ARGV[0]); if (NULL == *out && strncmp(CMD_ARGV[0], "ocd_", 4) == 0) *out = command_find(head, CMD_ARGV[0] + 4); if (NULL == *out) - return ERROR_INVALID_ARGUMENTS; + return ERROR_COMMAND_SYNTAX_ERROR; if (--CMD_ARGC == 0) return ERROR_OK; CMD_ARGV++; @@ -1164,7 +1180,7 @@ COMMAND_HANDLER(handle_help_add_command) if (CMD_ARGC < 2) { LOG_ERROR("%s: insufficient arguments", CMD_NAME); - return ERROR_INVALID_ARGUMENTS; + return ERROR_COMMAND_SYNTAX_ERROR; } // save help text and remove it from argument list @@ -1174,7 +1190,7 @@ COMMAND_HANDLER(handle_help_add_command) if (!help && !usage) { LOG_ERROR("command name '%s' is unknown", CMD_NAME); - return ERROR_INVALID_ARGUMENTS; + return ERROR_COMMAND_SYNTAX_ERROR; } // likewise for the leaf command name const char *cmd_name = CMD_ARGV[--CMD_ARGC]; @@ -1383,7 +1399,7 @@ struct command_context* command_init(const char *startup_tcl, Jim_Interp *interp int command_context_mode(struct command_context *cmd_ctx, enum command_mode mode) { if (!cmd_ctx) - return ERROR_INVALID_ARGUMENTS; + return ERROR_COMMAND_SYNTAX_ERROR; cmd_ctx->mode = mode; return ERROR_OK; @@ -1487,7 +1503,7 @@ int command_parse_bool_arg(const char *in, bool *out) return ERROR_OK; if (command_parse_bool(in, out, "1", "0") == ERROR_OK) return ERROR_OK; - return ERROR_INVALID_ARGUMENTS; + return ERROR_COMMAND_SYNTAX_ERROR; } COMMAND_HELPER(handle_command_parse_bool, bool *out, const char *label) @@ -1498,7 +1514,7 @@ COMMAND_HELPER(handle_command_parse_bool, bool *out, const char *label) if (command_parse_bool_arg(in, out) != ERROR_OK) { LOG_ERROR("%s: argument '%s' is not valid", CMD_NAME, in); - return ERROR_INVALID_ARGUMENTS; + return ERROR_COMMAND_SYNTAX_ERROR; } // fall through } @@ -1506,7 +1522,7 @@ COMMAND_HELPER(handle_command_parse_bool, bool *out, const char *label) LOG_INFO("%s is %s", label, *out ? "enabled" : "disabled"); break; default: - return ERROR_INVALID_ARGUMENTS; + return ERROR_COMMAND_SYNTAX_ERROR; } return ERROR_OK; }