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;


Nashif, Anas
 

Submit a pull request please with the change below. Seems to be a reasonable enhancement.

Anas

On 26/05/2017, 02:08, "zephyr-devel-bounces@lists.zephyrproject.org on behalf of Siddharth Chandrasekaran" <zephyr-devel-bounces@lists.zephyrproject.org on behalf of siddharth@embedjournal.com> wrote:

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;

_______________________________________________
Zephyr-devel mailing list
Zephyr-devel@lists.zephyrproject.org
https://lists.zephyrproject.org/mailman/listinfo/zephyr-devel


Siddharth Chandrasekaran
 

Hello Anas,

Thanks, already raised PR #320.

Siddharth.


---- On Mon, 29 May 2017 08:13:41 +0530 anas.nashif@... wrote ----

Submit a pull request please with the change below. Seems to be a reasonable enhancement.

Anas

On 26/05/2017, 02:08, "zephyr-devel-bounces@... on behalf of Siddharth Chandrasekaran" <zephyr-devel-bounces@... on behalf of siddharth@...> wrote:

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;

_______________________________________________
Zephyr-devel mailing list
Zephyr-devel@...
https://lists.zephyrproject.org/mailman/listinfo/zephyr-devel