Browse Source

wpa_cli: Add optional argument for the help command

"help <cmd>" can now be used to print the usage text for the
specified command (or set of commands matching the prefix).

Signed-hostap: Jouni Malinen <j@w1.fi>
Jouni Malinen 12 years ago
parent
commit
2af4d404a8
1 changed files with 26 additions and 8 deletions
  1. 26 8
      wpa_supplicant/wpa_cli.c

+ 26 - 8
wpa_supplicant/wpa_cli.c

@@ -92,10 +92,11 @@ static DEFINE_DL_LIST(p2p_peers); /* struct cli_txt_entry */
 static DEFINE_DL_LIST(p2p_groups); /* struct cli_txt_entry */
 static DEFINE_DL_LIST(p2p_groups); /* struct cli_txt_entry */
 
 
 
 
-static void print_help(void);
+static void print_help(const char *cmd);
 static void wpa_cli_mon_receive(int sock, void *eloop_ctx, void *sock_ctx);
 static void wpa_cli_mon_receive(int sock, void *eloop_ctx, void *sock_ctx);
 static void wpa_cli_close_connection(void);
 static void wpa_cli_close_connection(void);
 static char * wpa_cli_get_default_ifname(void);
 static char * wpa_cli_get_default_ifname(void);
+static char ** wpa_list_cmd_list(void);
 
 
 
 
 static void usage(void)
 static void usage(void)
@@ -112,7 +113,7 @@ static void usage(void)
 	       "  -B = run a daemon in the background\n"
 	       "  -B = run a daemon in the background\n"
 	       "  default path: " CONFIG_CTRL_IFACE_DIR "\n"
 	       "  default path: " CONFIG_CTRL_IFACE_DIR "\n"
 	       "  default interface: first interface found in socket path\n");
 	       "  default interface: first interface found in socket path\n");
-	print_help();
+	print_help(NULL);
 }
 }
 
 
 
 
@@ -527,11 +528,26 @@ static int wpa_cli_cmd_pmksa(struct wpa_ctrl *ctrl, int argc, char *argv[])
 
 
 static int wpa_cli_cmd_help(struct wpa_ctrl *ctrl, int argc, char *argv[])
 static int wpa_cli_cmd_help(struct wpa_ctrl *ctrl, int argc, char *argv[])
 {
 {
-	print_help();
+	print_help(argc > 0 ? argv[0] : NULL);
 	return 0;
 	return 0;
 }
 }
 
 
 
 
+static char ** wpa_cli_complete_help(const char *str, int pos)
+{
+	int arg = get_cmd_arg_num(str, pos);
+	char **res = NULL;
+
+	switch (arg) {
+	case 1:
+		res = wpa_list_cmd_list();
+		break;
+	}
+
+	return res;
+}
+
+
 static int wpa_cli_cmd_license(struct wpa_ctrl *ctrl, int argc, char *argv[])
 static int wpa_cli_cmd_license(struct wpa_ctrl *ctrl, int argc, char *argv[])
 {
 {
 	printf("%s\n\n%s\n", wpa_cli_version, wpa_cli_full_license);
 	printf("%s\n\n%s\n", wpa_cli_version, wpa_cli_full_license);
@@ -2131,9 +2147,9 @@ static struct wpa_cli_cmd wpa_cli_commands[] = {
 	{ "mib", wpa_cli_cmd_mib, NULL,
 	{ "mib", wpa_cli_cmd_mib, NULL,
 	  cli_cmd_flag_none,
 	  cli_cmd_flag_none,
 	  "= get MIB variables (dot1x, dot11)" },
 	  "= get MIB variables (dot1x, dot11)" },
-	{ "help", wpa_cli_cmd_help, NULL,
+	{ "help", wpa_cli_cmd_help, wpa_cli_complete_help,
 	  cli_cmd_flag_none,
 	  cli_cmd_flag_none,
-	  "= show this usage help" },
+	  "[command] = show usage help" },
 	{ "interface", wpa_cli_cmd_interface, NULL,
 	{ "interface", wpa_cli_cmd_interface, NULL,
 	  cli_cmd_flag_none,
 	  cli_cmd_flag_none,
 	  "[ifname] = show interfaces/select interface" },
 	  "[ifname] = show interfaces/select interface" },
@@ -2533,12 +2549,14 @@ static void print_cmd_help(struct wpa_cli_cmd *cmd, const char *pad)
 }
 }
 
 
 
 
-static void print_help(void)
+static void print_help(const char *cmd)
 {
 {
 	int n;
 	int n;
 	printf("commands:\n");
 	printf("commands:\n");
-	for (n = 0; wpa_cli_commands[n].cmd; n++)
-		print_cmd_help(&wpa_cli_commands[n], "  ");
+	for (n = 0; wpa_cli_commands[n].cmd; n++) {
+		if (cmd == NULL || str_starts(wpa_cli_commands[n].cmd, cmd))
+			print_cmd_help(&wpa_cli_commands[n], "  ");
+	}
 }
 }