shell: Add 'exit' command to leave a module

In console shell, add explicit, 'exit' command to leave the current
module. Currently this is being achieved by overloading select command
(without an argument).

Signed-off-by: Siddharth Chandrasekaran <siddharth@embedjournal.com>
This commit is contained in:
Siddharth Chandrasekaran 2017-05-28 13:53:27 +05:30 committed by Anas Nashif
commit faaf859a46

View file

@ -242,6 +242,7 @@ static int show_help(int argc, char *argv[])
} }
print_module_commands(module); print_module_commands(module);
printk("\nEnter 'exit' to leave current module.\n");
} else { /* help for all entities */ } else { /* help for all entities */
printk("Available modules:\n"); printk("Available modules:\n");
for (module = 0; module < NUM_OF_SHELL_ENTITIES; module++) { for (module = 0; module < NUM_OF_SHELL_ENTITIES; module++) {
@ -289,6 +290,15 @@ static int select_module(int argc, char *argv[])
return 0; return 0;
} }
static int exit_module(int argc, char *argv[])
{
if (argc == 1) {
default_module = -1;
}
return 0;
}
static shell_cmd_function_t get_cb(int argc, char *argv[]) static shell_cmd_function_t get_cb(int argc, char *argv[])
{ {
const char *first_string = argv[0]; const char *first_string = argv[0];
@ -310,6 +320,10 @@ static shell_cmd_function_t get_cb(int argc, char *argv[])
return select_module; return select_module;
} }
if (!strcmp(first_string, "exit")) {
return exit_module;
}
if ((argc == 1) && (default_module == -1)) { if ((argc == 1) && (default_module == -1)) {
printk("Missing parameter\n"); printk("Missing parameter\n");
return NULL; return NULL;