Add completion support for connmanctl commands.
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;
+}
#include <dbus/dbus.h>
int __connmanctl_commands(DBusConnection *connection, char *argv[], int argc);
+char *__connmanctl_lookup_command(const char *text, int state);
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[] = {
g_io_channel_unref(channel);
rl_callback_handler_install("connmanctl> ", rl_handler);
+ rl_attempted_completion_function = complete_command;
err = -EINPROGRESS;
} else {