summaryrefslogtreecommitdiff
path: root/client
diff options
context:
space:
mode:
authorPatrik Flykt <patrik.flykt@linux.intel.com>2013-04-18 12:28:21 (GMT)
committerPatrik Flykt <patrik.flykt@linux.intel.com>2013-04-23 09:36:09 (GMT)
commita3204d77fed1b870f95da2466c090aa636d2cc2d (patch)
treeb95bc8ee52071db3b6b9eabbd0a55ef6dbac071e /client
parentfc8c1be1cc13d756dde3b256a211bca85c6bae78 (diff)
downloadconnman-a3204d77fed1b870f95da2466c090aa636d2cc2d.zip
connman-a3204d77fed1b870f95da2466c090aa636d2cc2d.tar.gz
connman-a3204d77fed1b870f95da2466c090aa636d2cc2d.tar.bz2
client: Add command completion
Add completion support for connmanctl commands.
Diffstat (limited to 'client')
-rw-r--r--client/commands.c22
-rw-r--r--client/commands.h1
-rw-r--r--client/input.c14
3 files changed, 37 insertions, 0 deletions
diff --git a/client/commands.c b/client/commands.c
index 8b4ca53..32a8220 100644
--- a/client/commands.c
+++ b/client/commands.c
@@ -1277,3 +1277,25 @@ int __connmanctl_commands(DBusConnection *dbus_conn, char *argv[], int argc)
fprintf(stderr, "Error '%s': Unknown command\n", argv[0]);
return -EINVAL;
}
+
+char *__connmanctl_lookup_command(const char *text, int state)
+{
+ static int i = 0;
+ static int len = 0;
+
+ if (state == 0) {
+ i = 0;
+ len = strlen(text);
+ }
+
+ while (cmd_table[i].cmd != NULL) {
+ const char *command = cmd_table[i].cmd;
+
+ i++;
+
+ if (strncmp(text, command, len) == 0)
+ return strdup(command);
+ }
+
+ return NULL;
+}
diff --git a/client/commands.h b/client/commands.h
index ce9ceca..6ae9029 100644
--- a/client/commands.h
+++ b/client/commands.h
@@ -23,3 +23,4 @@
#include <dbus/dbus.h>
int __connmanctl_commands(DBusConnection *connection, char *argv[], int argc);
+char *__connmanctl_lookup_command(const char *text, int state);
diff --git a/client/input.c b/client/input.c
index f1aa0d3..20ce7f9 100644
--- a/client/input.c
+++ b/client/input.c
@@ -122,6 +122,19 @@ static gboolean input_handler(GIOChannel *channel, GIOCondition condition,
return TRUE;
}
+static char **complete_command(const char *text, int start, int end)
+{
+ char **command = NULL;
+
+ rl_attempted_completion_over = 1;
+
+ if (start == 0)
+ command = rl_completion_matches(text,
+ __connmanctl_lookup_command);
+
+ return command;
+}
+
int __connmanctl_input_init(int argc, char *argv[])
{
char *help[] = {
@@ -153,6 +166,7 @@ int __connmanctl_input_init(int argc, char *argv[])
g_io_channel_unref(channel);
rl_callback_handler_install("connmanctl> ", rl_handler);
+ rl_attempted_completion_function = complete_command;
err = -EINPROGRESS;
} else {