monitor: Convert help|? to use command_completion.
Quoted 62 lines · On Sun, 27 Apr 2014 17:00:03 +0100 Hani Benhabiles <[email protected]> wrote:
Signed-off-by Hani Benhabiles <[email protected]>--- hmp-commands.hx | 1 + hmp.h | 1 + monitor.c | 24 +++++++++++++++++------- 3 files changed, 19 insertions(+), 7 deletions(-)hmp-commands.hx +1
-0@@ -15,6 +15,7 @@ ETEXI .params = "[cmd]", .help = "show the help", .mhandler.cmd = do_help_cmd, + .command_completion = help_completion, }, STEXIhmp.h +1
-0@@ -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@@ -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().
Re: [Qemu-devel] [PATCH 0/7] Miscellaneous command completion patches
In reply to a message not in the archiveQuoted 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_addnow 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 aboutset_linkpatch: It prints both backend and frontend values because both are accepted byset_linkcommand.
Quoted 8 lines
Hani Benhabiles (7):
monitor: Convert sendkey to usecommand_completion.
monitor: Convert help|? to usecommand_completion.
monitor: Add chardev-remove command completion.
monitor: Add chardev-add backend argument completion.
monitor: Addset_linkarguments completion.
monitor: Addnetdev_addtype argument completion.
monitor: Addnetdev_delid 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
Stefan Hajnoczi
Reviewed-byRe: [Qemu-devel] [PATCH 5/7] monitor: Add set_link arguments completion.
In reply to a message not in the archiveQuoted 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
Signed-off-by Hani Benhabiles <[email protected]>--- hmp-commands.hx | 1 + hmp.h | 1 + monitor.c | 34 ++++++++++++++++++++++++++++++++++ net/net.c | 2 +- 4 files changed, 37 insertions(+), 1 deletion(-)
Stefan Hajnoczi
Reviewed-byRe: [Qemu-devel] [PATCH 6/7] monitor: Add netdev_add type argument completion.
In reply to a message not in the archiveQuoted 8 lines · Hani Benhabiles
Also update the command's documentation.
Signed-off-by Hani Benhabiles <[email protected]>--- hmp-commands.hx | 3 ++- hmp.h | 1 + monitor.c | 15 +++++++++++++++ 3 files changed, 18 insertions(+), 1 deletion(-)
Stefan Hajnoczi
Reviewed-byRe: [Qemu-devel] [PATCH 7/7] monitor: Add netdev_del id argument completion.
In reply to a message not in the archiveQuoted 6 lines · Hani Benhabiles
Signed-off-by Hani Benhabiles <[email protected]>--- hmp-commands.hx | 1 + hmp.h | 1 + monitor.c | 26 ++++++++++++++++++++++++++ 3 files changed, 28 insertions(+)
Quoted 78 lines · Luiz Capitulino
Quoted 62 lines · On Sun, 27 Apr 2014 17:00:03 +0100 Hani Benhabiles <[email protected]> wrote:
Signed-off-by Hani Benhabiles <[email protected]>--- hmp-commands.hx | 1 + hmp.h | 1 + monitor.c | 24 +++++++++++++++++------- 3 files changed, 19 insertions(+), 7 deletions(-)hmp-commands.hx +1
-0@@ -15,6 +15,7 @@ ETEXI .params = "[cmd]", .help = "show the help", .mhandler.cmd = do_help_cmd, + .command_completion = help_completion, }, STEXIhmp.h +1
-0@@ -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@@ -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.