Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

shell: Add a configuration for not printing shell errors #69002

Merged
merged 1 commit into from
Feb 26, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
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 this message.

config SHELL_MSG_SPECIFY_SUBCOMMAND
bool "'Please specify a subcommand.' message in the shell"
default y
help
If enabled, the shell prints out this 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