shell: Refactor command getters

Refactor and simplified fetching commands from the tree
of commands.

Signed-off-by: Krzysztof Chruscinski <krzysztof.chruscinski@nordicsemi.no>
This commit is contained in:
Krzysztof Chruscinski 2020-04-08 15:42:06 +02:00 committed by Carles Cufí
commit 53b5bae41b
7 changed files with 108 additions and 195 deletions

View file

@ -380,6 +380,11 @@ static int cmd_resize(const struct shell *shell, size_t argc, char **argv)
return 0;
}
static bool no_args(const struct shell_static_entry *entry)
{
return (entry->args.mandatory == 1) && (entry->args.optional == 0);
}
static int cmd_select(const struct shell *shell, size_t argc, char **argv)
{
const struct shell_static_entry *candidate = NULL;
@ -391,7 +396,8 @@ static int cmd_select(const struct shell *shell, size_t argc, char **argv)
candidate = shell_get_last_command(shell, argc, argv, &matching_argc,
&entry, true);
if ((candidate != NULL) && (argc == matching_argc)) {
if ((candidate != NULL) && !no_args(candidate)
&& (argc == matching_argc)) {
shell->ctx->selected_cmd = candidate;
return 0;
}