diff --git a/include/shell/shell.h b/include/shell/shell.h index d7316b283b4..891e7ed1973 100644 --- a/include/shell/shell.h +++ b/include/shell/shell.h @@ -110,7 +110,7 @@ struct shell_static_entry { const char *help; /*!< Command help string. */ const struct shell_cmd_entry *subcmd; /*!< Pointer to subcommand. */ shell_cmd_handler handler; /*!< Command handler. */ - const struct shell_static_args *args; /*!< Command arguments. */ + struct shell_static_args args; /*!< Command arguments. */ }; /** @@ -213,8 +213,7 @@ struct shell_static_entry { .subcmd = _subcmd, \ .help = (const char *)_help, \ .handler = _handler, \ - .args = _mandatory ? \ - (&(struct shell_static_args) SHELL_ARG(_mandatory, _optional)) : NULL \ + .args = SHELL_ARG(_mandatory, _optional) \ } /** diff --git a/subsys/shell/shell.c b/subsys/shell/shell.c index cccae2e69e3..7fdf46a07db 100644 --- a/subsys/shell/shell.c +++ b/subsys/shell/shell.c @@ -535,23 +535,13 @@ static int exec_cmd(const struct shell *shell, size_t argc, char **argv, } } - if (shell->ctx->active_cmd.args) { - const struct shell_static_args *args; + if (shell->ctx->active_cmd.args.mandatory) { + u8_t mand = shell->ctx->active_cmd.args.mandatory; + u8_t opt = shell->ctx->active_cmd.args.optional; + bool in_range = (argc >= mand) && (argc <= (mand + opt)); - args = shell->ctx->active_cmd.args; - - if (args->optional > 0) { - /* Check if argc is within allowed range */ - ret_val = cmd_precheck(shell, - ((argc >= args->mandatory) - && - (argc <= args->mandatory + - args->optional))); - } else { - /* Perform exact match if there are no optional args */ - ret_val = cmd_precheck(shell, - (args->mandatory == argc)); - } + /* Check if argc is within allowed range */ + ret_val = cmd_precheck(shell, in_range); } if (!ret_val) {