Skip to content

Commit

Permalink
shell: Add a configuration for not printing shell messages
Browse files Browse the repository at this point in the history
The shell currently prints out `: command not found` and
`Please specify a subcommand.` when invalid commands are
sent.

This can cause issues in certain situations, such as if a U-Boot
console in interactive mode is on the other end of the shell's
UART, where the U-Boot console will stop booting the device
if it receives any characters, and it will print out strings that
the shell then sees as commands. This causes the shell to send
out the messages above, preventing the device running
U-Boot on the other end from booting up.

I added the configurations
`CONFIG_SHELL_MSG_SPECIFY_SUBCOMMAND` and
`CONFIG_SHELL_MSG_CMD_NOT_FOUND` to allow disabling
these messages.

Signed-off-by: Brian Moran <brian.moran@sabantoag.com>
  • Loading branch information
Brianmm94 committed Feb 14, 2024
1 parent d936930 commit e621c90
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 5 deletions.
12 changes: 12 additions & 0 deletions subsys/shell/Kconfig
Original file line number Diff line number Diff line change
Expand Up @@ -120,6 +120,18 @@ config SHELL_WILDCARD
help
Enables using wildcards: * and ? in the shell.

config SHELL_MSG_CMD_NOT_FOUND
bool "': command not found' message in the shell"
default y
help
If enabled, the shell prints out the message.

config SHELL_MSG_SPECIFY_SUBCOMMAND
bool "'Please specify a subcommand.' message in the shell"
default y
help
If enabled, the shell prints out the message.

config SHELL_ECHO_STATUS
bool "Echo on shell"
default y
Expand Down
15 changes: 10 additions & 5 deletions subsys/shell/shell.c
Original file line number Diff line number Diff line change
Expand Up @@ -528,8 +528,10 @@ static int exec_cmd(const struct shell *sh, size_t argc, const char **argv,
shell_internal_help_print(sh);
return SHELL_CMD_HELP_PRINTED;
} else {
z_shell_fprintf(sh, SHELL_ERROR,
SHELL_MSG_SPECIFY_SUBCOMMAND);
if (IS_ENABLED(CONFIG_SHELL_MSG_SPECIFY_SUBCOMMAND)) {
z_shell_fprintf(sh, SHELL_ERROR,
SHELL_MSG_SPECIFY_SUBCOMMAND);
}
return -ENOEXEC;
}
}
Expand Down Expand Up @@ -692,8 +694,10 @@ static int execute(const struct shell *sh)
return SHELL_CMD_HELP_PRINTED;
}

z_shell_fprintf(sh, SHELL_ERROR,
SHELL_MSG_SPECIFY_SUBCOMMAND);
if (IS_ENABLED(CONFIG_SHELL_MSG_SPECIFY_SUBCOMMAND)) {
z_shell_fprintf(sh, SHELL_ERROR,
SHELL_MSG_SPECIFY_SUBCOMMAND);
}
return -ENOEXEC;
}

Expand Down Expand Up @@ -736,7 +740,8 @@ static int execute(const struct shell *sh)
&cmd_with_handler_lvl, &args_left);
parent = entry;
} else {
if (cmd_lvl == 0 &&
if (IS_ENABLED(CONFIG_SHELL_MSG_CMD_NOT_FOUND) &&
cmd_lvl == 0 &&
(!z_shell_in_select_mode(sh) ||
sh->ctx->selected_cmd->handler == NULL)) {
z_shell_fprintf(sh, SHELL_ERROR,
Expand Down

0 comments on commit e621c90

Please sign in to comment.