summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-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 8b4ca535..32a82200 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 ce9ceca2..6ae9029b 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 f1aa0d34..20ce7f9c 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 {