* Therefore we set the tcl return value only if we actually
* captured output.
*/
-static void command_log_capture_finish(struct log_capture_state *state)
+static void command_log_capture_finish(struct log_capture_state *state)
{
if (NULL == state)
return;
{
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;
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);
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++;
return -ENOMEM;
}
- if (++n >= 2)
- return ERROR_OK;
+ if (++n > 5) {
+ LOG_ERROR("command recursion exceeded");
+ return ERROR_FAIL;
+ }
return CALL_COMMAND_HANDLER(command_help_show_list,
c->children, n, show_help, match);
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
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];
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;
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)
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
}
LOG_INFO("%s is %s", label, *out ? "enabled" : "disabled");
break;
default:
- return ERROR_INVALID_ARGUMENTS;
+ return ERROR_COMMAND_SYNTAX_ERROR;
}
return ERROR_OK;
}