diff --git a/subsys/shell/shell.c b/subsys/shell/shell.c index 01a237f0631..a6a738e5c26 100644 --- a/subsys/shell/shell.c +++ b/subsys/shell/shell.c @@ -1555,3 +1555,51 @@ int shell_execute_cmd(const struct shell *shell, const char *cmd) return ret_val; } + +static int cmd_help(const struct shell *shell, size_t argc, char **argv) +{ + ARG_UNUSED(argc); + ARG_UNUSED(argv); + +#if defined(CONFIG_SHELL_TAB) + shell_print(shell, "Please press the button to see all available " + "commands."); +#endif + +#if defined(CONFIG_SHELL_TAB_AUTOCOMPLETION) + shell_print(shell, + "You can also use the button to prompt or auto-complete" + " all commands or its subcommands."); +#endif + +#if defined(CONFIG_SHELL_HELP) + shell_print(shell, + "You can try to call commands with <-h> or <--help> parameter" + " for more information."); +#endif + +#if defined(CONFIG_SHELL_METAKEYS) + shell_print(shell, + "\nShell supports following meta-keys:\n" + " Ctrl + (a key from: abcdefklnpuw)\n" + " Alt + (a key from: bf)\n" + "Please refer to shell documentation for more details."); +#endif + + if (IS_ENABLED(CONFIG_SHELL_HELP)) { + /* For NULL argument function will print all root commands */ + shell_help_subcmd_print(shell, NULL, "\nAvailable commands:\n"); + } else { + const struct shell_static_entry *entry; + size_t idx = 0; + + shell_print(shell, "\nAvailable commands:"); + while ((entry = shell_cmd_get(NULL, idx++, NULL)) != NULL) { + shell_print(shell, " %s", entry->syntax); + } + } + + return 0; +} + +SHELL_CMD_ARG_REGISTER(help, NULL, "Prints the help message.", cmd_help, 1, 0); diff --git a/subsys/shell/shell_cmds.c b/subsys/shell/shell_cmds.c index e022fa78393..2a7f1f6963b 100644 --- a/subsys/shell/shell_cmds.c +++ b/subsys/shell/shell_cmds.c @@ -278,41 +278,6 @@ static int cmd_echo(const struct shell *shell, size_t argc, char **argv) return 0; } -static int cmd_help(const struct shell *shell, size_t argc, char **argv) -{ - ARG_UNUSED(argc); - ARG_UNUSED(argv); - - shell_print(shell, - "Please press the button to see all available commands.\n" - "You can also use the button to prompt or auto-complete" - " all commands or its subcommands.\n" - "You can try to call commands with <-h> or <--help> parameter" - " for more information."); -#if defined(CONFIG_SHELL_METAKEYS) - shell_print(shell, - "\nShell supports following meta-keys:\n" - "Ctrl+a, Ctrl+b, Ctrl+c, Ctrl+d, Ctrl+e, Ctrl+f, Ctrl+k," - " Ctrl+l, Ctrl+n, Ctrl+p, Ctrl+u, Ctrl+w\nAlt+b, Alt+f.\n" - "Please refer to shell documentation for more details."); -#endif - - if (IS_ENABLED(CONFIG_SHELL_HELP)) { - /* For NULL argument function will print all root commands */ - shell_help_subcmd_print(shell, NULL, "\nAvailable commands:\n"); - } else { - const struct shell_static_entry *entry; - size_t idx = 0; - - shell_print(shell, "\nAvailable commands:"); - while ((entry = shell_cmd_get(NULL, idx++, NULL)) != NULL) { - shell_print(shell, " %s", entry->syntax); - } - } - - return 0; -} - static int cmd_history(const struct shell *shell, size_t argc, char **argv) { ARG_UNUSED(argc); @@ -472,7 +437,6 @@ SHELL_STATIC_SUBCMD_SET_CREATE(m_sub_resize, SHELL_CMD_ARG_REGISTER(clear, NULL, SHELL_HELP_CLEAR, cmd_clear, 1, 0); SHELL_CMD_REGISTER(shell, &m_sub_shell, SHELL_HELP_SHELL, NULL); -SHELL_CMD_ARG_REGISTER(help, NULL, SHELL_HELP_HELP, cmd_help, 1, 0); SHELL_COND_CMD_ARG_REGISTER(CONFIG_SHELL_HISTORY, history, NULL, SHELL_HELP_HISTORY, cmd_history, 1, 0); SHELL_COND_CMD_ARG_REGISTER(CONFIG_SHELL_CMDS_RESIZE, resize, &m_sub_resize,