monitor: Completion support for various commands.
cover monitor: Completion support for various commands.
This patch series adds a new callback to mon_cmd_t which will make adding completion support for more commands cleaner.
It then adds full or partial arguments completion for 7 different hmp commands.
Hani Benhabiles (7):
monitor: Add command_completion callback to mon_cmd_t.
monitor: Add chardev-remove id argument completion.
monitor: Add chardev-add backend argument completion.
monitor: Add cpu index argument completion.
monitor: Add set_link arguments completion.
monitor: Add netdev_add type argument completion.
monitor: Add netdev_del id argument completion.
hmp-commands.hx | 14 +++- hmp.h | 11 +++ monitor.c | 213 +++++++++++++++++++++++++++++++++++++++++++++++++------- 3 files changed, 211 insertions(+), 27 deletions(-)
Signature · 1 line
1.8.3.2
PATCH 1/7 monitor: Add command_completion callback to mon_cmd_t.
Convert device_add, device_del, object_add and object_del commands to use the new callback.
Also fix drive_del id argument type to activate completion.
--- hmp-commands.hx | 6 +++++- hmp.h | 4 ++++ monitor.c | 65 +++++++++++++++++++++++++++++++++++---------------------- 3 files changed, 49 insertions(+), 26 deletions(-)
hmp-commands.hx +5 -1
@@ -176,7 +176,7 @@ ETEXI { .name = "drive_del", - .args_type = "id:s", + .args_type = "id:B", .params = "device", .help = "remove host block device", .user_print = monitor_user_noop,
@@ -658,6 +658,7 @@ ETEXI .help = "add device, like -device on the command line", .user_print = monitor_user_noop, .mhandler.cmd_new = do_device_add, + .command_completion = device_add_completion, }, STEXI
@@ -673,6 +674,7 @@ ETEXI .params = "device", .help = "remove device", .mhandler.cmd = hmp_device_del, + .command_completion = device_del_completion, }, STEXI
@@ -1254,6 +1256,7 @@ ETEXI .params = "[qom-type=]type,id=str[,prop=value][,...]", .help = "create QOM object", .mhandler.cmd = hmp_object_add, + .command_completion = object_add_completion, }, STEXI
@@ -1268,6 +1271,7 @@ ETEXI .params = "id", .help = "destroy QOM object", .mhandler.cmd = hmp_object_del, + .command_completion = object_del_completion, }, STEXI
hmp.h +4 -0
@@ -92,5 +92,9 @@ void hmp_qemu_io(Monitor *mon, const QDict *qdict);void hmp_cpu_add (Monitor *mon,const QDict *qdict);void hmp_object_add (Monitor *mon,const QDict *qdict);void hmp_object_del (Monitor *mon,const QDict *qdict); +void device_add_completion (Monitor *mon,int nb_args,const char *str); +void device_del_completion (Monitor *mon,int nb_args,const char *str); +void object_add_completion (Monitor *mon,int nb_args,const char *str); +void object_del_completion (Monitor *mon,int nb_args,const char *str);#endif
monitor.c +40 -25
150 lines not on this page · raw message
Signature · 1 line
1.8.3.2
Re: [Qemu-devel] [PATCH 1/7] monitor: Add command_completion callback to mon_cmd_t.
Quoted 4 lines · On Sun, 9 Mar 2014 12:16:11 +0100 Hani Benhabiles <[email protected]> wrote:
Convert
device_add,device_del,object_addandobject_delcommands to use the new callback.Also fix
drive_delid argument type to activate completion.
I think this patch has to be split into at least three patches. One for the drive_del change (which is unrelated with the other stuff), one converting device_add & device_del and the third one converting object_add and object_del.
Also, please, take the simplest conversion for the first patch, which introduces the callback.
One more comment below.
Quoted 73 lines
Signed-off-by Hani Benhabiles <[email protected]>Suggested-by Luiz Capitulino <[email protected]>--- hmp-commands.hx | 6 +++++- hmp.h | 4 ++++ monitor.c | 65 +++++++++++++++++++++++++++++++++++---------------------- 3 files changed, 49 insertions(+), 26 deletions(-)hmp-commands.hx +5
-1@@ -176,7 +176,7 @@ ETEXI { .name = "drive_del", - .args_type = "id:s", + .args_type = "id:B", .params = "device", .help = "remove host block device", .user_print = monitor_user_noop,@@ -658,6 +658,7 @@ ETEXI .help = "add device, like -device on the command line", .user_print = monitor_user_noop, .mhandler.cmd_new = do_device_add, + .command_completion = device_add_completion, }, STEXI@@ -673,6 +674,7 @@ ETEXI .params = "device", .help = "remove device", .mhandler.cmd = hmp_device_del, + .command_completion = device_del_completion, }, STEXI@@ -1254,6 +1256,7 @@ ETEXI .params = "[qom-type=]type,id=str[,prop=value][,...]", .help = "create QOM object", .mhandler.cmd = hmp_object_add, + .command_completion = object_add_completion, }, STEXI@@ -1268,6 +1271,7 @@ ETEXI .params = "id", .help = "destroy QOM object", .mhandler.cmd = hmp_object_del, + .command_completion = object_del_completion, }, STEXIhmp.h +4
-0@@ -92,5 +92,9 @@ void hmp_qemu_io(Monitor *mon, const QDict *qdict);void hmp_cpu_add (Monitor *mon,const QDict *qdict);void hmp_object_add (Monitor *mon,const QDict *qdict);void hmp_object_del (Monitor *mon,const QDict *qdict); +void device_add_completion (Monitor *mon,int nb_args,const char *str); +void device_del_completion (Monitor *mon,int nb_args,const char *str); +void object_add_completion (Monitor *mon,int nb_args,const char *str); +void object_del_completion (Monitor *mon,int nb_args,const char *str);#endif monitor.c +0
-0
monitor.c typedef struct mon_cmd_t { · line 140
Quoted 4 lines
monitor.c +1
-0@@ -137,6 +137,7 @@ typedef struct mon_cmd_t {* used, and mhandler of 1st level plays the role of help function. */ struct mon_cmd_t *sub_table; +void (*command_completion)(Monitor *mon,int nb_args,const char *str);
Why does command_completion need 'mon'? It seems to me that a ReadLineState suffices.
Quoted 153 lines
monitor.c +39
-25} mon_cmd_t;/* file descriptors passed via SCM_RIGHTS */ @@ -4277,13 +4278,17 @@ static const char *next_arg_type(const char *typestr)return (p !=NULL ? ++p : typestr); } -static void device_add_completion (ReadLineState *rs,const char *str) +void device_add_completion (Monitor *mon,int nb_args,const char *str) {GSList *list, *elt;size_t len; +if (nb_args !=2 ) { +return ; + } + len =strlen (str); -readline_set_completion_index (rs, len); +readline_set_completion_index (mon->rs, len); list = elt =object_class_get_list (TYPE_DEVICE , false);while (elt) {const char *name;@@ -4291,35 +4296,39 @@ static void device_add_completion(ReadLineState *rs, const char *str) TYPE_DEVICE); name =object_class_get_name (OBJECT_CLASS (dc));if (!strncmp (name, str, len)) { -readline_add_completion (rs, name); +readline_add_completion (mon->rs, name); } elt = elt->next; }g_slist_free (list); } -static void object_add_completion (ReadLineState *rs,const char *str) +void object_add_completion (Monitor *mon,int nb_args,const char *str) {GSList *list, *elt;size_t len; +if (nb_args !=2 ) { +return ; + } + len =strlen (str); -readline_set_completion_index (rs, len); +readline_set_completion_index (mon->rs, len); list = elt =object_class_get_list (TYPE_USER_CREATABLE , false);while (elt) {const char *name; name =object_class_get_name (OBJECT_CLASS (elt->data));if (!strncmp (name, str, len) &&strcmp (name,TYPE_USER_CREATABLE )) { -readline_add_completion (rs, name); +readline_add_completion (mon->rs, name); } elt = elt->next; }g_slist_free (list); } -static void device_del_completion (ReadLineState *rs,BusState *bus, -const char *str,size_t len) +static void device_del_bus_completion (ReadLineState *rs,BusState *bus, +const char *str,size_t len) {BusChild *kid;@@ -4332,18 +4341,34 @@ static void device_del_completion(ReadLineState *rs, BusState *bus, } QLIST_FOREACH(dev_child, &dev->child_bus, sibling) { -device_del_completion (rs, dev_child, str, len); +device_del_bus_completion (rs, dev_child, str, len); } } } -static void object_del_completion (ReadLineState *rs,const char *str) +void device_del_completion (Monitor *mon,int nb_args,const char *str) +{ +size_t len; + +if (nb_args !=2 ) { +return ; + } + + len =strlen (str); +readline_set_completion_index (mon->rs, len); +device_del_bus_completion (mon->rs,sysbus_get_default (), str, len); +} + +void object_del_completion (Monitor *mon,int nb_args,const char *str) {ObjectPropertyInfoList *list, *start;size_t len; +if (nb_args !=2 ) { +return ; + } len =strlen (str); -readline_set_completion_index (rs, len); +readline_set_completion_index (mon->rs, len); start = list =qmp_qom_list ("/objects" ,NULL );while (list) {@@ -4351,7 +4376,7 @@ static void object_del_completion(ReadLineState *rs, const char *str)if (!strncmp (info->type,"child<" ,5 ) && !strncmp (info->name, str, len)) { -readline_add_completion (rs, info->name); +readline_add_completion (mon->rs, info->name); } list = list->next; }@@ -4395,6 +4420,9 @@ static void monitor_find_completion_by_table(Monitor *mon,return monitor_find_completion_by_table (mon, cmd->sub_table, &args[1 ], nb_args -1 ); } +if (cmd->command_completion) { +return cmd->command_completion (mon, nb_args, args[nb_args -1 ]); + } ptype =next_arg_type (cmd->args_type);for (i =0 ; i < nb_args -2 ; i++) {@@ -4421,13 +4449,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 ; -case 'O' : -if (!strcmp (cmd->name,"device_add" ) && nb_args ==2 ) { -device_add_completion (mon->rs, str); - }else if (!strcmp (cmd->name,"object_add" ) && nb_args ==2 ) { -object_add_completion (mon->rs, str); - } -break ;case 's' :case 'S' :if (!strcmp (cmd->name,"sendkey" )) {@@ -4441,12 +4462,6 @@ static void monitor_find_completion_by_table(Monitor *mon, }else if (!strcmp (cmd->name,"help|?" )) {monitor_find_completion_by_table (mon, cmd_table, &args[1 ], nb_args -1 ); - }else if (!strcmp (cmd->name,"device_del" ) && nb_args ==2 ) { -size_t len =strlen (str); -readline_set_completion_index (mon->rs, len); -device_del_completion (mon->rs,sysbus_get_default (), str, len); - }else if (!strcmp (cmd->name,"object_del" ) && nb_args ==2 ) { -object_del_completion (mon->rs, str); }break ;default :
Re: [Qemu-devel] [PATCH 1/7] monitor: Add command_completion callback to mon_cmd_t.
Quoted 9 lines · Luiz Capitulino
I think this patch has to be split into at least three patches. One for the
drive_delchange (which is unrelated with the other stuff), one convertingdevice_add&device_deland the third one convertingobject_addandobject_del.Also, please, take the simplest conversion for the first patch, which introduces the callback.
Ok, I will split them. Just felt that the number of patches was growing-up too fast.
Quoted 69 lines
One more comment below.
Quoted 67 lines
Signed-off-by Hani Benhabiles <[email protected]>Suggested-by Luiz Capitulino <[email protected]>--- hmp-commands.hx | 6 +++++- hmp.h | 4 ++++ monitor.c | 65 +++++++++++++++++++++++++++++++++++---------------------- 3 files changed, 49 insertions(+), 26 deletions(-)hmp-commands.hx +5
-1@@ -176,7 +176,7 @@ ETEXI { .name = "drive_del", - .args_type = "id:s", + .args_type = "id:B", .params = "device", .help = "remove host block device", .user_print = monitor_user_noop,@@ -658,6 +658,7 @@ ETEXI .help = "add device, like -device on the command line", .user_print = monitor_user_noop, .mhandler.cmd_new = do_device_add, + .command_completion = device_add_completion, }, STEXI@@ -673,6 +674,7 @@ ETEXI .params = "device", .help = "remove device", .mhandler.cmd = hmp_device_del, + .command_completion = device_del_completion, }, STEXI@@ -1254,6 +1256,7 @@ ETEXI .params = "[qom-type=]type,id=str[,prop=value][,...]", .help = "create QOM object", .mhandler.cmd = hmp_object_add, + .command_completion = object_add_completion, }, STEXI@@ -1268,6 +1271,7 @@ ETEXI .params = "id", .help = "destroy QOM object", .mhandler.cmd = hmp_object_del, + .command_completion = object_del_completion, }, STEXIhmp.h +4
-0@@ -92,5 +92,9 @@ void hmp_qemu_io(Monitor *mon, const QDict *qdict);void hmp_cpu_add (Monitor *mon,const QDict *qdict);void hmp_object_add (Monitor *mon,const QDict *qdict);void hmp_object_del (Monitor *mon,const QDict *qdict); +void device_add_completion (Monitor *mon,int nb_args,const char *str); +void device_del_completion (Monitor *mon,int nb_args,const char *str); +void object_add_completion (Monitor *mon,int nb_args,const char *str); +void object_del_completion (Monitor *mon,int nb_args,const char *str);
Quoted 13 lines
monitor.c typedef struct mon_cmd_t { · line 140
Quoted 10 lines
hmp.h +0
-0#endif monitor.c +1
-0@@ -137,6 +137,7 @@ typedef struct mon_cmd_t {* used, and mhandler of 1st level plays the role of help function. */ struct mon_cmd_t *sub_table; +void (*command_completion)(Monitor *mon,int nb_args,const char *str);Why does
command_completionneed 'mon'? It seems to me that a ReadLineState suffices.
No particular reason right now. I just tried to keep the prototype general enough in order to not have to make a mass conversion in case some need shows up in the future. Should I just use ReadLineState in the next series version ?
Re: [Qemu-devel] [PATCH 1/7] monitor: Add command_completion callback to mon_cmd_t.
Quoted 7 lines · On Thu, 27 Mar 2014 22:55:46 +0100 Hani Benhabiles <[email protected]> wrote:
Quoted 6 lines · Luiz Capitulino
I think this patch has to be split into at least three patches. One for the
drive_delchange (which is unrelated with the other stuff), one convertingdevice_add&device_deland the third one convertingobject_addandobject_del.
Quoted 6 lines
Quoted 3 lines
Also, please, take the simplest conversion for the first patch, which introduces the callback.
Ok, I will split them. Just felt that the number of patches was growing-up too fast.
That's not a problem.
Quoted 83 lines
Quoted 69 lines
One more comment below.
Quoted 67 lines
Signed-off-by Hani Benhabiles <[email protected]>Suggested-by Luiz Capitulino <[email protected]>--- hmp-commands.hx | 6 +++++- hmp.h | 4 ++++ monitor.c | 65 +++++++++++++++++++++++++++++++++++---------------------- 3 files changed, 49 insertions(+), 26 deletions(-)hmp-commands.hx +5
-1@@ -176,7 +176,7 @@ ETEXI { .name = "drive_del", - .args_type = "id:s", + .args_type = "id:B", .params = "device", .help = "remove host block device", .user_print = monitor_user_noop,@@ -658,6 +658,7 @@ ETEXI .help = "add device, like -device on the command line", .user_print = monitor_user_noop, .mhandler.cmd_new = do_device_add, + .command_completion = device_add_completion, }, STEXI@@ -673,6 +674,7 @@ ETEXI .params = "device", .help = "remove device", .mhandler.cmd = hmp_device_del, + .command_completion = device_del_completion, }, STEXI@@ -1254,6 +1256,7 @@ ETEXI .params = "[qom-type=]type,id=str[,prop=value][,...]", .help = "create QOM object", .mhandler.cmd = hmp_object_add, + .command_completion = object_add_completion, }, STEXI@@ -1268,6 +1271,7 @@ ETEXI .params = "id", .help = "destroy QOM object", .mhandler.cmd = hmp_object_del, + .command_completion = object_del_completion, }, STEXIhmp.h +4
-0@@ -92,5 +92,9 @@ void hmp_qemu_io(Monitor *mon, const QDict *qdict);void hmp_cpu_add (Monitor *mon,const QDict *qdict);void hmp_object_add (Monitor *mon,const QDict *qdict);void hmp_object_del (Monitor *mon,const QDict *qdict); +void device_add_completion (Monitor *mon,int nb_args,const char *str); +void device_del_completion (Monitor *mon,int nb_args,const char *str); +void object_add_completion (Monitor *mon,int nb_args,const char *str); +void object_del_completion (Monitor *mon,int nb_args,const char *str);Quoted 13 lines
monitor.c typedef struct mon_cmd_t { · line 140
Quoted 10 lines
hmp.h +0
-0#endif monitor.c +1
-0@@ -137,6 +137,7 @@ typedef struct mon_cmd_t {* used, and mhandler of 1st level plays the role of help function. */ struct mon_cmd_t *sub_table; +void (*command_completion)(Monitor *mon,int nb_args,const char *str);Why does
command_completionneed 'mon'? It seems to me that a ReadLineState suffices.
Quoted 3 lines
No particular reason right now. I just tried to keep the prototype general enough in order to not have to make a mass conversion in case some need shows up in the future. Should I just use ReadLineState in the next series version ?
IMO, yes. If, in the future, it turns out we need a Monitor object we can just update the callback signature.
PATCH 2/7 monitor: Add chardev-remove id argument completion.
In reply to Hani Benhabiles--- hmp-commands.hx | 1 + hmp.h | 2 ++ monitor.c | 23 +++++++++++++++++++++++ 3 files changed, 26 insertions(+)
hmp-commands.hx +1 -0
@@ -1630,6 +1630,7 @@ ETEXI .params = "id", .help = "remove chardev", .mhandler.cmd = hmp_chardev_remove, + .command_completion = chardev_remove_completion, }, STEXI
hmp.h +2 -0
@@ -96,5 +96,7 @@ void device_add_completion(Monitor *mon, int nb_args, const char *str);void device_del_completion (Monitor *mon,int nb_args,const char *str);void object_add_completion (Monitor *mon,int nb_args,const char *str);void object_del_completion (Monitor *mon,int nb_args,const char *str); +void chardev_remove_completion (Monitor *mon,int nb_args,const char *str); +#endif
monitor.c +23 -0
@@ -4346,6 +4346,29 @@ static void device_del_bus_completion(ReadLineState *rs, BusState *bus, } } +void chardev_remove_completion (Monitor *mon,int nb_args,const char *str) +{ +size_t len; +ChardevInfoList *list, *start; + +if (nb_args !=2 ) { +return ; + } + len =strlen (str); +readline_set_completion_index (mon->rs, len); + + start = list =qmp_query_chardev (NULL ); +while (list) { +ChardevInfo *chr = list->value; + +if (!strncmp (chr->label, str, len)) { +readline_add_completion (mon->rs, chr->label); + } + list = list->next; + } +qapi_free_ChardevInfoList (start); +} +void device_del_completion (Monitor *mon,int nb_args,const char *str) {size_t len;
Signature · 1 line
1.8.3.2
PATCH 3/7 monitor: Add chardev-add backend argument completion.
In reply to Hani Benhabiles--- hmp-commands.hx | 1 + hmp.h | 1 + monitor.c | 23 +++++++++++++++++++++++ 3 files changed, 25 insertions(+)
hmp-commands.hx +1 -0
@@ -1614,6 +1614,7 @@ ETEXI .params = "args", .help = "add chardev", .mhandler.cmd = hmp_chardev_add, + .command_completion = chardev_add_completion, }, STEXI
hmp.h +1 -0
@@ -96,6 +96,7 @@ void device_add_completion(Monitor *mon, int nb_args, const char *str);void device_del_completion (Monitor *mon,int nb_args,const char *str);void object_add_completion (Monitor *mon,int nb_args,const char *str);void object_del_completion (Monitor *mon,int nb_args,const char *str); +void chardev_add_completion (Monitor *mon,int nb_args,const char *str);void chardev_remove_completion (Monitor *mon,int nb_args,const char *str);
monitor.c +23 -0
@@ -4278,6 +4278,29 @@ static const char *next_arg_type(const char *typestr)return (p !=NULL ? ++p : typestr); } +void chardev_add_completion (Monitor *mon,int nb_args,const char *str) +{ +size_t len; +ChardevBackendInfoList *list, *start; + +if (nb_args !=2 ) { +return ; + } + len =strlen (str); +readline_set_completion_index (mon->rs, len); + + start = list =qmp_query_chardev_backends (NULL ); +while (list) { +const char *chr_name = list->value->name; + +if (!strncmp (chr_name, str, len)) { +readline_add_completion (mon->rs, chr_name); + } + list = list->next; + } +qapi_free_ChardevBackendInfoList (start); +} +void device_add_completion (Monitor *mon,int nb_args,const char *str) {GSList *list, *elt;
Signature · 1 line
1.8.3.2
PATCH 4/7 monitor: Add cpu index argument completion.
In reply to Hani Benhabiles--- hmp-commands.hx | 1 + hmp.h | 1 + monitor.c | 24 ++++++++++++++++++++++++ 3 files changed, 26 insertions(+)
hmp-commands.hx +1 -0
@@ -690,6 +690,7 @@ ETEXI .params = "index", .help = "set the default CPU", .mhandler.cmd = hmp_cpu, + .command_completion = cpu_completion, }, STEXI
hmp.h +1 -0
@@ -98,6 +98,7 @@ void object_add_completion(Monitor *mon, int nb_args, const char *str);void object_del_completion (Monitor *mon,int nb_args,const char *str);void chardev_add_completion (Monitor *mon,int nb_args,const char *str);void chardev_remove_completion (Monitor *mon,int nb_args,const char *str); +void cpu_completion (Monitor *mon,int nb_args,const char *str);#endif
monitor.c +24 -0
@@ -4429,6 +4429,30 @@ void object_del_completion(Monitor *mon, int nb_args, const char *str)qapi_free_ObjectPropertyInfoList (start); } +void cpu_completion (Monitor *mon,int nb_args,const char *str) +{ +CpuInfoList *cpu_list, *start; +size_t len; + +if (nb_args !=2 ) { +return ; + } + len =strlen (str); +readline_set_completion_index (mon->rs, len); + + start = cpu_list =qmp_query_cpus (NULL ); +while (cpu_list) { +char name[16 ]; +snprintf (name,sizeof (name),"%" PRId64, cpu_list->value->CPU); + +if (!strncmp (str, name, len)) { +readline_add_completion (mon->rs, name); + } + cpu_list = cpu_list->next; + } +qapi_free_CpuInfoList (start); +} + static void monitor_find_completion_by_table(Monitor *mon, const mon_cmd_t *cmd_table, char **args,
Signature · 1 line
1.8.3.2
Re: [Qemu-devel] [PATCH 4/7] monitor: Add cpu index argument completion.
Quoted 1 line · On Sun, 9 Mar 2014 12:16:14 +0100 Hani Benhabiles <[email protected]> wrote:
Signed-off-by Hani Benhabiles <[email protected]>
Honest question: is this one really worth it? Aren't we just auto-completing a single integer?
Quoted 65 lines
--- hmp-commands.hx | 1 + hmp.h | 1 + monitor.c | 24 ++++++++++++++++++++++++ 3 files changed, 26 insertions(+)hmp-commands.hx +1
-0@@ -690,6 +690,7 @@ ETEXI .params = "index", .help = "set the default CPU", .mhandler.cmd = hmp_cpu, + .command_completion = cpu_completion, }, STEXIhmp.h +1
-0@@ -98,6 +98,7 @@ void object_add_completion(Monitor *mon, int nb_args, const char *str);void object_del_completion (Monitor *mon,int nb_args,const char *str);void chardev_add_completion (Monitor *mon,int nb_args,const char *str);void chardev_remove_completion (Monitor *mon,int nb_args,const char *str); +void cpu_completion (Monitor *mon,int nb_args,const char *str);#endif monitor.c +24
-0@@ -4429,6 +4429,30 @@ void object_del_completion(Monitor *mon, int nb_args, const char *str)qapi_free_ObjectPropertyInfoList (start); } +void cpu_completion (Monitor *mon,int nb_args,const char *str) +{ +CpuInfoList *cpu_list, *start; +size_t len; + +if (nb_args !=2 ) { +return ; + } + len =strlen (str); +readline_set_completion_index (mon->rs, len); + + start = cpu_list =qmp_query_cpus (NULL ); +while (cpu_list) { +char name[16 ]; +snprintf (name,sizeof (name),"%" PRId64, cpu_list->value->CPU); + +if (!strncmp (str, name, len)) { +readline_add_completion (mon->rs, name); + } + cpu_list = cpu_list->next; + } +qapi_free_CpuInfoList (start); +} + static void monitor_find_completion_by_table(Monitor *mon, const mon_cmd_t *cmd_table, char **args,
Re: [Qemu-devel] [PATCH 4/7] monitor: Add cpu index argument completion.
Quoted 7 lines · Luiz Capitulino
Quoted 1 line · On Sun, 9 Mar 2014 12:16:14 +0100 Hani Benhabiles <[email protected]> wrote:
Signed-off-by Hani Benhabiles <[email protected]>Honest question: is this one really worth it? Aren't we just auto-completing a single integer?
It could for example serve for fast discovery, without having to check "info cpus" before hand.
No strong opinion about it, so feel free to take it or not. I did it because well, it was trivial enough and took too few efforts to leave behind.
PATCH 5/7 monitor: Add set_link arguments completion.
In reply to Hani BenhabilesThis also adds the add_completion_option() function which is to be used for other commands completions as well.
--- hmp-commands.hx | 1 + hmp.h | 1 + monitor.c | 45 +++++++++++++++++++++++++++++++++++++++++++++ 3 files changed, 47 insertions(+)
hmp-commands.hx +1 -0
@@ -1332,6 +1332,7 @@ ETEXI .params = "name on|off", .help = "change the link status of a network adapter", .mhandler.cmd = hmp_set_link, + .command_completion = set_link_completion, }, STEXI
hmp.h +1 -0
@@ -99,6 +99,7 @@ void object_del_completion(Monitor *mon, int nb_args, const char *str);void chardev_add_completion (Monitor *mon,int nb_args,const char *str);void chardev_remove_completion (Monitor *mon,int nb_args,const char *str);void cpu_completion (Monitor *mon,int nb_args,const char *str); +void set_link_completion (Monitor *mon,int nb_args,const char *str);#endif
monitor.c +45 -0
57 lines not on this page · raw message
Signature · 1 line
1.8.3.2
PATCH 6/7 monitor: Add netdev_add type argument completion.
In reply to Hani BenhabilesAlso update the command's documentation.
--- hmp-commands.hx | 3 ++- hmp.h | 1 + monitor.c | 18 ++++++++++++++++++ 3 files changed, 21 insertions(+), 1 deletion(-)
hmp-commands.hx +2 -1
@@ -1226,9 +1226,10 @@ ETEXI { .name = "netdev_add", .args_type = "netdev:O", - .params = "[user|tap|socket|hubport|netmap],id=str[,prop=value][,...]", + .params = "[user|tap|socket|vde|bridge|hubport|netmap],id=str[,prop=value][,...]", .help = "add host network device", .mhandler.cmd = hmp_netdev_add, + .command_completion = netdev_add_completion, }, STEXI
hmp.h +1 -0
@@ -100,6 +100,7 @@ void chardev_add_completion(Monitor *mon, int nb_args, const char *str);void chardev_remove_completion (Monitor *mon,int nb_args,const char *str);void cpu_completion (Monitor *mon,int nb_args,const char *str);void set_link_completion (Monitor *mon,int nb_args,const char *str); +void netdev_add_completion (Monitor *mon,int nb_args,const char *str);#endif
monitor.c +18 -0
@@ -4312,6 +4312,24 @@ void chardev_add_completion(Monitor *mon, int nb_args, const char *str)qapi_free_ChardevBackendInfoList (start); } +void netdev_add_completion (Monitor *mon,int nb_args,const char *str) +{ +size_t len; + +if (nb_args !=2 ) { +return ; + } + len =strlen (str); +readline_set_completion_index (mon->rs, len); +add_completion_option (mon, str,"user" ); +add_completion_option (mon, str,"tap" ); +add_completion_option (mon, str,"socket" ); +add_completion_option (mon, str,"vde" ); +add_completion_option (mon, str,"bridge" ); +add_completion_option (mon, str,"hubport" ); +add_completion_option (mon, str,"netmap" ); +} +void device_add_completion (Monitor *mon,int nb_args,const char *str) {GSList *list, *elt;
Signature · 1 line
1.8.3.2
PATCH 7/7 monitor: Add netdev_del id argument completion.
In reply to Hani Benhabiles--- hmp-commands.hx | 1 + hmp.h | 1 + monitor.c | 15 +++++++++++++++ 3 files changed, 17 insertions(+)
hmp-commands.hx +1 -0
@@ -1244,6 +1244,7 @@ ETEXI .params = "id", .help = "remove host network device", .mhandler.cmd = hmp_netdev_del, + .command_completion = netdev_del_completion, }, STEXI
hmp.h +1 -0
@@ -101,6 +101,7 @@ void chardev_remove_completion(Monitor *mon, int nb_args, const char *str);void cpu_completion (Monitor *mon,int nb_args,const char *str);void set_link_completion (Monitor *mon,int nb_args,const char *str);void netdev_add_completion (Monitor *mon,int nb_args,const char *str); +void netdev_del_completion (Monitor *mon,int nb_args,const char *str);#endif
monitor.c +15 -0
@@ -4516,6 +4516,21 @@ void set_link_completion(Monitor *mon, int nb_args, const char *str) } } +void netdev_del_completion (Monitor *mon,int nb_args,const char *str) +{ +struct NicCompletionData data = { + .mon = mon, + .str = str, + }; + +if (nb_args !=2 ) { +return ; + } + +readline_set_completion_index (mon->rs,strlen (str)); +qemu_foreach_nic (check_nic_completion, &data); +} + static void monitor_find_completion_by_table(Monitor *mon, const mon_cmd_t *cmd_table, char **args,
Signature · 1 line
1.8.3.2
Quoted 4 lines · On Sun, 9 Mar 2014 12:16:10 +0100 Hani Benhabiles <[email protected]> wrote:
This patch series adds a new callback to
mon_cmd_twhich will make adding completion support for more commands cleaner.It then adds full or partial arguments completion for 7 different hmp commands.
Not high priority for 2.0, right?
I won't have review bandwidth to review this before hard-freeze (which happens in two days), so this is going to be postponed to 2.1.
Quoted 6 lines · Luiz Capitulino
Quoted 3 lines · On Sun, 9 Mar 2014 12:16:10 +0100 Hani Benhabiles <[email protected]> wrote:
This patch series adds a new callback to
mon_cmd_twhich will make adding completion support for more commands cleaner.
Quoted 6 lines
Quoted 1 line
It then adds full or partial arguments completion for 7 different hmp commands.
Not high priority for 2.0, right?
I won't have review bandwidth to review this before hard-freeze (which happens in two days), so this is going to be postponed to 2.1.
Not high priority. Just that I will send another series that will build on top of this.
Quoted 4 lines · On Sun, 9 Mar 2014 12:16:10 +0100 Hani Benhabiles <[email protected]> wrote:
This patch series adds a new callback to
mon_cmd_twhich will make adding completion support for more commands cleaner.It then adds full or partial arguments completion for 7 different hmp commands.
The general approach seems OK to me, but I could use some help to review the entire series.
Stefan, could you please review the set_link(), netdev_add/del() changes?
Quoted 15 lines
Hani Benhabiles (7):
monitor: Addcommand_completioncallback tomon_cmd_t.
monitor: Add chardev-remove id argument completion.
monitor: Add chardev-add backend argument completion.
monitor: Add cpu index argument completion.
monitor: Addset_linkarguments completion.
monitor: Addnetdev_addtype argument completion.
monitor: Addnetdev_delid argument completion.hmp-commands.hx | 14 +++- hmp.h | 11 +++ monitor.c | 213 +++++++++++++++++++++++++++++++++++++++++++++++++------- 3 files changed, 211 insertions(+), 27 deletions(-)
Quoted 6 lines · Luiz Capitulino
Quoted 3 lines · On Sun, 9 Mar 2014 12:16:10 +0100 Hani Benhabiles <[email protected]> wrote:
This patch series adds a new callback to
mon_cmd_twhich will make adding completion support for more commands cleaner.
Quoted 7 lines
Quoted 1 line
It then adds full or partial arguments completion for 7 different hmp commands.
The general approach seems OK to me, but I could use some help to review the entire series.
Stefan, could you please review the
set_link(), netdev_add/del() changes?
Better review the new series I will send soon.