[PATCH 4/9] hostapd_cli: Add completion for help command

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



Implement command completion support for help command.

Signed-off-by: Mikael Kanstrup <mikael.kanstrup@xxxxxxxxxxxxxx>
---
 hostapd/hostapd_cli.c | 36 +++++++++++++++++++++++++++++++++++-
 1 file changed, 35 insertions(+), 1 deletion(-)

diff --git a/hostapd/hostapd_cli.c b/hostapd/hostapd_cli.c
index 37ed449..55f511a 100644
--- a/hostapd/hostapd_cli.c
+++ b/hostapd/hostapd_cli.c
@@ -75,6 +75,7 @@ static int ping_interval = 5;
 static int interactive = 0;
 
 static void print_help(FILE *stream, const char *cmd);
+static char ** list_cmd_list(void);
 
 static void usage(void)
 {
@@ -103,6 +104,24 @@ static void usage(void)
 }
 
 
+static int get_cmd_arg_num(const char *str, int pos)
+{
+	int arg = 0, i;
+
+	for (i = 0; i <= pos; i++) {
+		if (str[i] != ' ') {
+			arg++;
+			while (i <= pos && str[i] != ' ')
+				i++;
+		}
+	}
+
+	if (arg > 0)
+		arg--;
+	return arg;
+}
+
+
 static int str_starts(const char *src, const char *match)
 {
 	return os_strncmp(src, match, os_strlen(match)) == 0;
@@ -753,6 +772,21 @@ static int hostapd_cli_cmd_help(struct wpa_ctrl *ctrl, int argc, char *argv[])
 }
 
 
+static char ** hostapd_cli_complete_help(const char *str, int pos)
+{
+	int arg = get_cmd_arg_num(str, pos);
+	char **res = NULL;
+
+	switch (arg) {
+	case 1:
+		res = list_cmd_list();
+		break;
+	}
+
+	return res;
+}
+
+
 static int hostapd_cli_cmd_license(struct wpa_ctrl *ctrl, int argc,
 				   char *argv[])
 {
@@ -1257,7 +1291,7 @@ static const struct hostapd_cli_cmd hostapd_cli_commands[] = {
 	  NULL },
 	{ "get_config", hostapd_cli_cmd_get_config, NULL,
 	  "= show current configuration" },
-	{ "help", hostapd_cli_cmd_help, NULL,
+	{ "help", hostapd_cli_cmd_help, hostapd_cli_complete_help,
 	  "= show this usage help" },
 	{ "interface", hostapd_cli_cmd_interface, NULL,
 	  "[ifname] = show interfaces/select interface" },
-- 
2.9.0.137.gcf4c2cf


_______________________________________________
Hostap mailing list
Hostap@xxxxxxxxxxxxxxxxxxx
http://lists.infradead.org/mailman/listinfo/hostap



[Index of Archives]     [Linux Wireless]     [Linux Kernel]     [ATH6KL]     [Linux Bluetooth]     [Linux Netdev]     [Kernel Newbies]     [IDE]     [Security]     [Git]     [Netfilter]     [Bugtraq]     [Yosemite News]     [MIPS Linux]     [ARM Linux]     [Linux Security]     [Linux RAID]     [Linux ATA RAID]     [Samba]     [Device Mapper]

  Powered by Linux