Simple embedded shell with runtime pluggable commands.

Dependents:   DataBus2018

Implements a simple unix-like shell for embedded systems with a pluggable command architecture.

Revision:
8:41b7274a9753
Parent:
5:8f486f4d29d3
Child:
11:23f61057d877
--- a/SimpleShell.cpp	Wed Dec 12 17:58:27 2018 +0000
+++ b/SimpleShell.cpp	Wed Dec 12 18:30:49 2018 +0000
@@ -4,8 +4,22 @@
 SimpleShell::SimpleShell()
 {
     lookupEnd = 0;
+    // Built-in shell commands
+    attach(callback(this, &SimpleShell::help), "help");
+    // TODO: cd
 }
 
+
+void SimpleShell::help()
+{
+    printf("Available commands: ");
+    for (int i=0; i < lookupEnd; i++) {
+        printf("%s ", lookup[i].command);
+    }
+    printf("\n\n");
+}
+
+
 void SimpleShell::run()
 {
     bool done=false;
@@ -15,6 +29,7 @@
     strcpy(_cwd, "/log");
 
     printf("Type help for assistance.\n");
+    help();   
     while (!done) {
         printPrompt();
         readCommand();
@@ -39,10 +54,6 @@
         lookup[lookupEnd].command = command;
         lookupEnd++;
     }
-    
-    for (int i=0; i < lookupEnd; i++) {
-        printf("%s\n", lookup[i].command);
-    }
         
     return;
 }