shell: move help command to shell.c
The help command is needed to list all available commands when it is not possible to use the tab key. Previously when build-in commands were deactivated command help was not compiled as well. Signed-off-by: Jakub Rzeszutko <jakub.rzeszutko@nordicsemi.no>
This commit is contained in:
parent
de7e208d8d
commit
6e18a63f9b
|
@ -1555,3 +1555,51 @@ int shell_execute_cmd(const struct shell *shell, const char *cmd)
|
||||||
|
|
||||||
return ret_val;
|
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 <Tab> button to see all available "
|
||||||
|
"commands.");
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#if defined(CONFIG_SHELL_TAB_AUTOCOMPLETION)
|
||||||
|
shell_print(shell,
|
||||||
|
"You can also use the <Tab> 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);
|
||||||
|
|
|
@ -278,41 +278,6 @@ static int cmd_echo(const struct shell *shell, size_t argc, char **argv)
|
||||||
return 0;
|
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 <Tab> button to see all available commands.\n"
|
|
||||||
"You can also use the <Tab> 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)
|
static int cmd_history(const struct shell *shell, size_t argc, char **argv)
|
||||||
{
|
{
|
||||||
ARG_UNUSED(argc);
|
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_ARG_REGISTER(clear, NULL, SHELL_HELP_CLEAR, cmd_clear, 1, 0);
|
||||||
SHELL_CMD_REGISTER(shell, &m_sub_shell, SHELL_HELP_SHELL, NULL);
|
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_COND_CMD_ARG_REGISTER(CONFIG_SHELL_HISTORY, history, NULL,
|
||||||
SHELL_HELP_HISTORY, cmd_history, 1, 0);
|
SHELL_HELP_HISTORY, cmd_history, 1, 0);
|
||||||
SHELL_COND_CMD_ARG_REGISTER(CONFIG_SHELL_CMDS_RESIZE, resize, &m_sub_resize,
|
SHELL_COND_CMD_ARG_REGISTER(CONFIG_SHELL_CMDS_RESIZE, resize, &m_sub_resize,
|
||||||
|
|
Loading…
Reference in a new issue