Shell add 'exit' command to leave current module


Siddharth Chandrasekaran
 

Hello,

In shell, to select a module, we use 'select <module_name>'. When inside
a module, there is no indication on how one has to leave the module.
Would it be better to have an 'exit' ?

I know (after reading code) we can use 'select' without and argument to
go back to default module but having an exit will make things more
clear. Besides, people are used to hitting 'exit' or 'quit' to leave a
prompt so I thought it makes sense to have it here as well.

Proposed change listed below.

Thanks,
Siddharth.

---

diff --git a/subsys/shell/shell.c b/subsys/shell/shell.c
index 228f876..7e53aad 100644
--- a/subsys/shell/shell.c
+++ b/subsys/shell/shell.c
@@ -233,6 +233,7 @@ static int show_help(int argc, char *argv[])
}

print_module_commands(module);
+ printk("\nEnter 'exit' to leave current module.\n");
} else { /* help for all entities */
printk("Available modules:\n");
for (module = 0; module < NUM_OF_SHELL_ENTITIES; module++) {
@@ -280,6 +281,15 @@ static int select_module(int argc, char *argv[])
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[])
{
const char *first_string = argv[0];
@@ -301,6 +311,10 @@ static shell_cmd_function_t get_cb(int argc, char *argv[])
return select_module;
}

+ if (!strcmp(first_string, "exit")) {
+ return exit_module;
+ }
+
if ((argc == 1) && (default_module == -1)) {
printk("Missing parameter\n");
return NULL;

Join devel@lists.zephyrproject.org to automatically receive all group messages.