shell: Add shell_set_root_cmd function

New function allows to set from the code the root command. It is
an equivalent of calling 'select <rootcmd>' except it sets command
for all shell instances.

Signed-off-by: Krzysztof Chruscinski <krzysztof.chruscinski@nordicsemi.no>
This commit is contained in:
Krzysztof Chruscinski 2020-04-07 08:19:20 +02:00 committed by Ioannis Glaropoulos
commit 450c6b44f9
4 changed files with 54 additions and 4 deletions

View file

@ -252,8 +252,7 @@ void shell_cmd_get(const struct shell *shell,
*entry = NULL;
if (lvl == SHELL_CMD_ROOT_LVL) {
if (shell_in_select_mode(shell) &&
IS_ENABLED(CONFIG_SHELL_CMDS_SELECT)) {
if (shell_in_select_mode(shell)) {
const struct shell_static_entry *ptr =
shell->ctx->selected_cmd;
if (ptr->subcmd->u.entry[idx].syntax != NULL) {
@ -362,6 +361,23 @@ const struct shell_static_entry *shell_get_last_command(
return entry;
}
int shell_set_root_cmd(const char *cmd)
{
const struct shell_static_entry *entry;
entry = cmd ? shell_root_cmd_find(cmd) : NULL;
if (cmd && (entry == NULL)) {
return -EINVAL;
}
Z_STRUCT_SECTION_FOREACH(shell, sh) {
sh->ctx->selected_cmd = entry;
}
return 0;
}
int shell_command_add(char *buff, u16_t *buff_len,
const char *new_cmd, const char *pattern)
{