aboutsummaryrefslogtreecommitdiff
path: root/client/rl.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'client/rl.cpp')
-rw-r--r--client/rl.cpp27
1 files changed, 12 insertions, 15 deletions
diff --git a/client/rl.cpp b/client/rl.cpp
index 32a4df0..b016370 100644
--- a/client/rl.cpp
+++ b/client/rl.cpp
@@ -7,7 +7,7 @@
#include <readline/history.h>
#include "rl.h"
-#include "sock.h"
+#include "cmd.h"
void rl_printf(const char *fmt, ...) {
// save line
@@ -36,9 +36,13 @@ void rl_printf(const char *fmt, ...) {
free(saved_line);
}
-void cmd_test() {
- const char* data = "Hello world!";
- i2c_send(0x39, (char*) data, strlen(data));
+static bool cli_cmd(char* line) {
+ for (size_t i = 0; i < cmds_length; i++) {
+ if (strcmp(line, cmds[i].name) != 0) continue;
+ cmds[i].handle(line);
+ return true;
+ }
+ return false;
}
int cli_main() {
@@ -47,18 +51,11 @@ int cli_main() {
if (input != NULL) free(input);
input = readline(CLI_PROMPT);
- // exit on ^D or ^C (EOF)
- if (input == NULL) return EXIT_SUCCESS;
+ if (input == NULL) return EXIT_SUCCESS; // exit on ^D (EOF)
+ if (*input == '\0') continue; // ignore empty lines
+ add_history(input);
- // add non-empty line to history
- if (*input) add_history(input);
-
- if (strcmp(input, "exit") == 0) return EXIT_SUCCESS;
-
- if (strcmp(input, "test") == 0) {
- cmd_test();
- continue;
- }
+ if (cli_cmd(input)) continue;
printf("unknown command!\n");
}