Skip to contentSkip to conversation

monitor: Convert help|? to use command_completion.

PATCH Luiz Capitulino 3 participants 6 messages May 5, 2014 – May 7, 2014 5 messages not in the archive

lore
Share & tools
lore
#2 lore raw
In reply to a message not in the archive
Quoted 62 lines · On Sun, 27 Apr 2014 17:00:03 +0100 Hani Benhabiles <[email protected]> wrote:
---
 hmp-commands.hx |  1 +
 hmp.h           |  1 +
 monitor.c       | 24 +++++++++++++++++-------
 3 files changed, 19 insertions(+), 7 deletions(-)
hmp-commands.hx +1 -0
index b3f45d6..ba13997 100644
@@ -15,6 +15,7 @@ ETEXI
         .params     = "[cmd]",
         .help       = "show the help",
         .mhandler.cmd = do_help_cmd,
+        .command_completion = help_completion,
     },
 
 STEXI
hmp.h +1 -0
index 12e21e7..55f78fa 100644
@@ -98,5 +98,6 @@ void object_del_completion(ReadLineState *rs, int nb_args, const char *str);
 void device_add_completion(ReadLineState *rs, int nb_args, const char *str);
 void device_del_completion(ReadLineState *rs, int nb_args, const char *str);
 void sendkey_completion(ReadLineState *rs, int nb_args, const char *str);
+void help_completion(ReadLineState *rs, int nb_args, const char *str);
 
 #endif
monitor.c +17 -0
index 7edfcee..acbbaf8 100644
@@ -4407,6 +4407,23 @@ void sendkey_completion(ReadLineState *rs, int nb_args, const char *str)
     }
 }
 
+void help_completion(ReadLineState *rs, int nb_args, const char *str)
+{
+    int i;
+    size_t len;
+
+    if (nb_args != 2) {
+        return;
+    }
+    len = strlen(str);
+    readline_set_completion_index(rs, len);
+    for (i = 0; mon_cmds[i].name; i++) {
+        if (!strncmp(str, mon_cmds[i].name, len)) {
+            readline_add_completion(rs, mon_cmds[i].name);
+        }
+    }
+}
+
 static void monitor_find_completion_by_table(Monitor *mon,
                                              const mon_cmd_t *cmd_table,
                                              char **args,
@@ -4473,13 +4490,6 @@ static void monitor_find_completion_by_table(Monitor *mon,
             readline_set_completion_index(mon->rs, strlen(str));
             bdrv_iterate(block_completion_it, &mbs);
             break;

monitor.c static void monitor_find_completion_by_table(Monitor *mon, · line 4495

Quoted 10 lines
monitor.c +0 -7
-        case 's':
-        case 'S':
-            if (!strcmp(cmd->name, "help|?")) {
-                monitor_find_completion_by_table(mon, cmd_table,
-                                                 &args[1], nb_args - 1);
-            }
-            break;
         default:
             break;
         }

This breaks auto-completion for:

(qemu) help info v

Which would auto-complete "vnc". IIRC, that's one of the reasons we have monitor_find_completion_by_table().

#4 lore raw

Re: [Qemu-devel] [PATCH 0/7] Miscellaneous command completion patches

In reply to a message not in the archive
Quoted 9 lines · On Sun, 27 Apr 2014 17:00:01 +0100 Hani Benhabiles <[email protected]> wrote:

Compared to the larger series sent before:
* Patches 01-03 are already in qmp branch.
* Added patches to convert sendkey, help/? to use new completion callback.
* Dropped patch 06 (cpu index completion) as deemed not useful enough.
* netdev_add now uses the same values array as qapi instead of hardcoding them.
* Left patches 10-17 for a separate series to make review process faster.
* wrt. to Luiz' question about set_link patch: It prints both backend and frontend values because both are accepted by set_link command.

Quoted 8 lines

Hani Benhabiles (7):
monitor: Convert sendkey to use command_completion.
monitor: Convert help|? to use command_completion.
monitor: Add chardev-remove command completion.
monitor: Add chardev-add backend argument completion.
monitor: Add set_link arguments completion.
monitor: Add netdev_add type argument completion.
monitor: Add netdev_del id argument completion.

The first patch looks good. The second one has a problem. For the other patches it would help me to get Reviewed-bys by the following people:

o Gerd: patch 03/07 and patch 04/07
o Stefan: patches 05/07, 06/07 and 07/07

Reviewed-by
#6 lore raw

Re: [Qemu-devel] [PATCH 5/7] monitor: Add set_link arguments completion.

In reply to a message not in the archive
Quoted 6 lines · Hani Benhabiles

Make it possible to query all net clients without specifying an ID when calling qemu_find_net_clients_except().

This also adds the add_completion_option() function which is to be used for other commands completions as well.

Quoted 7 lines
---
 hmp-commands.hx |  1 +
 hmp.h           |  1 +
 monitor.c       | 34 ++++++++++++++++++++++++++++++++++
 net/net.c       |  2 +-
 4 files changed, 37 insertions(+), 1 deletion(-)
#3 lore raw
In reply to Luiz Capitulino
Quoted 78 lines · Luiz Capitulino
Quoted 62 lines · On Sun, 27 Apr 2014 17:00:03 +0100 Hani Benhabiles <[email protected]> wrote:
---
 hmp-commands.hx |  1 +
 hmp.h           |  1 +
 monitor.c       | 24 +++++++++++++++++-------
 3 files changed, 19 insertions(+), 7 deletions(-)
hmp-commands.hx +1 -0
index b3f45d6..ba13997 100644
@@ -15,6 +15,7 @@ ETEXI
         .params     = "[cmd]",
         .help       = "show the help",
         .mhandler.cmd = do_help_cmd,
+        .command_completion = help_completion,
     },
 
 STEXI
hmp.h +1 -0
index 12e21e7..55f78fa 100644
@@ -98,5 +98,6 @@ void object_del_completion(ReadLineState *rs, int nb_args, const char *str);
 void device_add_completion(ReadLineState *rs, int nb_args, const char *str);
 void device_del_completion(ReadLineState *rs, int nb_args, const char *str);
 void sendkey_completion(ReadLineState *rs, int nb_args, const char *str);
+void help_completion(ReadLineState *rs, int nb_args, const char *str);
 
 #endif
monitor.c +17 -0
index 7edfcee..acbbaf8 100644
@@ -4407,6 +4407,23 @@ void sendkey_completion(ReadLineState *rs, int nb_args, const char *str)
     }
 }
 
+void help_completion(ReadLineState *rs, int nb_args, const char *str)
+{
+    int i;
+    size_t len;
+
+    if (nb_args != 2) {
+        return;
+    }
+    len = strlen(str);
+    readline_set_completion_index(rs, len);
+    for (i = 0; mon_cmds[i].name; i++) {
+        if (!strncmp(str, mon_cmds[i].name, len)) {
+            readline_add_completion(rs, mon_cmds[i].name);
+        }
+    }
+}
+
 static void monitor_find_completion_by_table(Monitor *mon,
                                              const mon_cmd_t *cmd_table,
                                              char **args,
@@ -4473,13 +4490,6 @@ static void monitor_find_completion_by_table(Monitor *mon,
             readline_set_completion_index(mon->rs, strlen(str));
             bdrv_iterate(block_completion_it, &mbs);
             break;

monitor.c static void monitor_find_completion_by_table(Monitor *mon, · line 4495

Quoted 10 lines
monitor.c +0 -7
-        case 's':
-        case 'S':
-            if (!strcmp(cmd->name, "help|?")) {
-                monitor_find_completion_by_table(mon, cmd_table,
-                                                 &args[1], nb_args - 1);
-            }
-            break;
         default:
             break;
         }

This breaks auto-completion for:

Quoted 4 lines

(qemu) help info v

Which would auto-complete "vnc". IIRC, that's one of the reasons we have monitor_find_completion_by_table().

Thanks for spotting that.

Quickly thinking about it, a possible way to solve this is to change command_completion() prototype to be passed the whole args table, and not just a string and then have those "special cases" (like help+info) handled.

Better drop patch 02/07 and leave the rest as is for now, I believe. I will send a v2.