diff mbox

[2/2] monitor: support sub commands in auto completion

Message ID 1371796658-15632-3-git-send-email-xiawenc@linux.vnet.ibm.com
State New
Headers show

Commit Message

Wayne Xia June 21, 2013, 6:37 a.m. UTC
This patch allow auot completion work normal in sub command case,
"info block [DEVICE]" can auto complete now, by re-enter the completion
function. Also, original "info" is treated as a special case, now it is
treated as a sub command group, global variable info_cmds is not used
any more.

Signed-off-by: Wenchao Xia <xiawenc@linux.vnet.ibm.com>
---
 monitor.c |   12 ++++++------
 1 files changed, 6 insertions(+), 6 deletions(-)

Comments

Luiz Capitulino June 21, 2013, 3:24 p.m. UTC | #1
On Fri, 21 Jun 2013 14:37:38 +0800
Wenchao Xia <xiawenc@linux.vnet.ibm.com> wrote:

> This patch allow auot completion work normal in sub command case,
> "info block [DEVICE]" can auto complete now, by re-enter the completion
> function. Also, original "info" is treated as a special case, now it is
> treated as a sub command group, global variable info_cmds is not used
> any more.
> 
> Signed-off-by: Wenchao Xia <xiawenc@linux.vnet.ibm.com>
> ---
>  monitor.c |   12 ++++++------
>  1 files changed, 6 insertions(+), 6 deletions(-)
> 
> diff --git a/monitor.c b/monitor.c
> index bc60171..c706644 100644
> --- a/monitor.c
> +++ b/monitor.c
> @@ -4180,6 +4180,11 @@ static void monitor_find_completion(Monitor *mon,
>              goto cleanup;
>          }
>  
> +        if (cmd->sub_table) {
> +            return monitor_find_completion(mon, cmd->sub_table,
> +                                           cmdline + strlen(cmd->name));
> +        }
> +
>          ptype = next_arg_type(cmd->args_type);
>          for(i = 0; i < nb_args - 2; i++) {
>              if (*ptype != '\0') {
> @@ -4207,12 +4212,7 @@ static void monitor_find_completion(Monitor *mon,
>              break;
>          case 's':
>              /* XXX: more generic ? */

I think you can drop this comment too.

> -            if (!strcmp(cmd->name, "info")) {
> -                readline_set_completion_index(mon->rs, strlen(str));
> -                for(cmd = info_cmds; cmd->name != NULL; cmd++) {
> -                    cmd_completion(mon, str, cmd->name);
> -                }
> -            } else if (!strcmp(cmd->name, "sendkey")) {
> +            if (!strcmp(cmd->name, "sendkey")) {
>                  char *sep = strrchr(str, '-');
>                  if (sep)
>                      str = sep + 1;
diff mbox

Patch

diff --git a/monitor.c b/monitor.c
index bc60171..c706644 100644
--- a/monitor.c
+++ b/monitor.c
@@ -4180,6 +4180,11 @@  static void monitor_find_completion(Monitor *mon,
             goto cleanup;
         }
 
+        if (cmd->sub_table) {
+            return monitor_find_completion(mon, cmd->sub_table,
+                                           cmdline + strlen(cmd->name));
+        }
+
         ptype = next_arg_type(cmd->args_type);
         for(i = 0; i < nb_args - 2; i++) {
             if (*ptype != '\0') {
@@ -4207,12 +4212,7 @@  static void monitor_find_completion(Monitor *mon,
             break;
         case 's':
             /* XXX: more generic ? */
-            if (!strcmp(cmd->name, "info")) {
-                readline_set_completion_index(mon->rs, strlen(str));
-                for(cmd = info_cmds; cmd->name != NULL; cmd++) {
-                    cmd_completion(mon, str, cmd->name);
-                }
-            } else if (!strcmp(cmd->name, "sendkey")) {
+            if (!strcmp(cmd->name, "sendkey")) {
                 char *sep = strrchr(str, '-');
                 if (sep)
                     str = sep + 1;