Skip to content

Commit 6e18a63

Browse files
Jakub RzeszutkoMaureenHelm
authored andcommitted
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 <[email protected]>
1 parent de7e208 commit 6e18a63

File tree

2 files changed

+48
-36
lines changed

2 files changed

+48
-36
lines changed

subsys/shell/shell.c

Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1555,3 +1555,51 @@ int shell_execute_cmd(const struct shell *shell, const char *cmd)
15551555

15561556
return ret_val;
15571557
}
1558+
1559+
static int cmd_help(const struct shell *shell, size_t argc, char **argv)
1560+
{
1561+
ARG_UNUSED(argc);
1562+
ARG_UNUSED(argv);
1563+
1564+
#if defined(CONFIG_SHELL_TAB)
1565+
shell_print(shell, "Please press the <Tab> button to see all available "
1566+
"commands.");
1567+
#endif
1568+
1569+
#if defined(CONFIG_SHELL_TAB_AUTOCOMPLETION)
1570+
shell_print(shell,
1571+
"You can also use the <Tab> button to prompt or auto-complete"
1572+
" all commands or its subcommands.");
1573+
#endif
1574+
1575+
#if defined(CONFIG_SHELL_HELP)
1576+
shell_print(shell,
1577+
"You can try to call commands with <-h> or <--help> parameter"
1578+
" for more information.");
1579+
#endif
1580+
1581+
#if defined(CONFIG_SHELL_METAKEYS)
1582+
shell_print(shell,
1583+
"\nShell supports following meta-keys:\n"
1584+
" Ctrl + (a key from: abcdefklnpuw)\n"
1585+
" Alt + (a key from: bf)\n"
1586+
"Please refer to shell documentation for more details.");
1587+
#endif
1588+
1589+
if (IS_ENABLED(CONFIG_SHELL_HELP)) {
1590+
/* For NULL argument function will print all root commands */
1591+
shell_help_subcmd_print(shell, NULL, "\nAvailable commands:\n");
1592+
} else {
1593+
const struct shell_static_entry *entry;
1594+
size_t idx = 0;
1595+
1596+
shell_print(shell, "\nAvailable commands:");
1597+
while ((entry = shell_cmd_get(NULL, idx++, NULL)) != NULL) {
1598+
shell_print(shell, " %s", entry->syntax);
1599+
}
1600+
}
1601+
1602+
return 0;
1603+
}
1604+
1605+
SHELL_CMD_ARG_REGISTER(help, NULL, "Prints the help message.", cmd_help, 1, 0);

subsys/shell/shell_cmds.c

Lines changed: 0 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -278,41 +278,6 @@ static int cmd_echo(const struct shell *shell, size_t argc, char **argv)
278278
return 0;
279279
}
280280

281-
static int cmd_help(const struct shell *shell, size_t argc, char **argv)
282-
{
283-
ARG_UNUSED(argc);
284-
ARG_UNUSED(argv);
285-
286-
shell_print(shell,
287-
"Please press the <Tab> button to see all available commands.\n"
288-
"You can also use the <Tab> button to prompt or auto-complete"
289-
" all commands or its subcommands.\n"
290-
"You can try to call commands with <-h> or <--help> parameter"
291-
" for more information.");
292-
#if defined(CONFIG_SHELL_METAKEYS)
293-
shell_print(shell,
294-
"\nShell supports following meta-keys:\n"
295-
"Ctrl+a, Ctrl+b, Ctrl+c, Ctrl+d, Ctrl+e, Ctrl+f, Ctrl+k,"
296-
" Ctrl+l, Ctrl+n, Ctrl+p, Ctrl+u, Ctrl+w\nAlt+b, Alt+f.\n"
297-
"Please refer to shell documentation for more details.");
298-
#endif
299-
300-
if (IS_ENABLED(CONFIG_SHELL_HELP)) {
301-
/* For NULL argument function will print all root commands */
302-
shell_help_subcmd_print(shell, NULL, "\nAvailable commands:\n");
303-
} else {
304-
const struct shell_static_entry *entry;
305-
size_t idx = 0;
306-
307-
shell_print(shell, "\nAvailable commands:");
308-
while ((entry = shell_cmd_get(NULL, idx++, NULL)) != NULL) {
309-
shell_print(shell, " %s", entry->syntax);
310-
}
311-
}
312-
313-
return 0;
314-
}
315-
316281
static int cmd_history(const struct shell *shell, size_t argc, char **argv)
317282
{
318283
ARG_UNUSED(argc);
@@ -472,7 +437,6 @@ SHELL_STATIC_SUBCMD_SET_CREATE(m_sub_resize,
472437

473438
SHELL_CMD_ARG_REGISTER(clear, NULL, SHELL_HELP_CLEAR, cmd_clear, 1, 0);
474439
SHELL_CMD_REGISTER(shell, &m_sub_shell, SHELL_HELP_SHELL, NULL);
475-
SHELL_CMD_ARG_REGISTER(help, NULL, SHELL_HELP_HELP, cmd_help, 1, 0);
476440
SHELL_COND_CMD_ARG_REGISTER(CONFIG_SHELL_HISTORY, history, NULL,
477441
SHELL_HELP_HISTORY, cmd_history, 1, 0);
478442
SHELL_COND_CMD_ARG_REGISTER(CONFIG_SHELL_CMDS_RESIZE, resize, &m_sub_resize,

0 commit comments

Comments
 (0)