monitor: Add argument completion for multiple commands.
cover monitor: Add argument completion for multiple commands.
This patch series add argument completion to multiple human monitor console commands.
For device_add and object_add, only the 1st argument is completed.
Hani Benhabiles (4):
monitor: Add device_del id argument completion.
monitor: Add device_add device argument completion.
monitor: Add object_del id argument completion.
monitor: Add object_add class argument completion.
monitor.c | 95 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 95 insertions(+)
Signature · 1 line
1.8.3.2
PATCH 1/4 monitor: Add device_del id argument completion.
--- monitor.c | 23 +++++++++++++++++++++++ 1 file changed, 23 insertions(+)
monitor.c +23 -0
@@ -4254,6 +4254,25 @@ static const char *next_arg_type(const char *typestr)return (p !=NULL ? ++p : typestr); } +static void device_del_completion (ReadLineState *rs,BusState *bus, +const char *str,size_t len) +{ +BusChild *kid; + + QTAILQ_FOREACH(kid, &bus->children, sibling) { +DeviceState *dev = kid->child; +BusState *dev_child; + +if (dev->id && !strncmp (str, dev->id, len)) { +readline_add_completion (rs, dev->id); + } + + QLIST_FOREACH(dev_child, &dev->child_bus, sibling) { +device_del_completion (rs, dev_child, str, len); + } + } +} + static void monitor_find_completion_by_table(Monitor *mon, const mon_cmd_t *cmd_table, char **args,
@@ -4330,6 +4349,10 @@ 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); }break ;default :
Signature · 1 line
1.8.3.2
Re: [Qemu-devel] [PATCH 1/4] monitor: Add device_del id argument completion.
Quoted 3 lines · On Thu, 6 Feb 2014 23:30:10 +0100 Hani Benhabiles <[email protected]> wrote:
--- monitor.c | 23 +++++++++++++++++++++++ 1 file changed, 23 insertions(+)
Your S-o-B is missing in all patches. Can reply to them adding it?
Quoted 42 lines
monitor.c +23
-0@@ -4254,6 +4254,25 @@ static const char *next_arg_type(const char *typestr)return (p !=NULL ? ++p : typestr); } +static void device_del_completion (ReadLineState *rs,BusState *bus, +const char *str,size_t len) +{ +BusChild *kid; + + QTAILQ_FOREACH(kid, &bus->children, sibling) { +DeviceState *dev = kid->child; +BusState *dev_child; + +if (dev->id && !strncmp (str, dev->id, len)) { +readline_add_completion (rs, dev->id); + } + + QLIST_FOREACH(dev_child, &dev->child_bus, sibling) { +device_del_completion (rs, dev_child, str, len); + } + } +} + static void monitor_find_completion_by_table(Monitor *mon, const mon_cmd_t *cmd_table, char **args,@@ -4330,6 +4349,10 @@ 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); }break ;default :
PATCH 2/4 monitor: Add device_add device argument completion.
In reply to Hani Benhabiles--- monitor.c | 26 ++++++++++++++++++++++++++ 1 file changed, 26 insertions(+)
monitor.c +26 -0
@@ -4254,6 +4254,27 @@ static const char *next_arg_type(const char *typestr)return (p !=NULL ? ++p : typestr); } +static void device_add_completion (ReadLineState *rs,const char *str) +{ +GSList *list, *elt; +size_t len; + + len =strlen (str); +readline_set_completion_index (rs, len); + list = elt =object_class_get_list (TYPE_DEVICE , false); +while (elt) { +const char *name; +DeviceClass *dc =OBJECT_CLASS_CHECK (DeviceClass, elt->data, +TYPE_DEVICE ); + name =object_class_get_name (OBJECT_CLASS (dc)); +if (!strncmp (name, str, len)) { +readline_add_completion (rs, name); + } + elt = elt->next; + } +g_slist_free (list); +} +static void device_del_completion (ReadLineState *rs,BusState *bus,const char *str,size_t len) {
@@ -4336,6 +4357,11 @@ 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); + } +break ;case 's' :case 'S' :if (!strcmp (cmd->name,"sendkey" )) {
Signature · 1 line
1.8.3.2
PATCH 3/4 monitor: Add object_del id argument completion.
In reply to Hani Benhabiles--- monitor.c | 23 +++++++++++++++++++++++ 1 file changed, 23 insertions(+)
monitor.c +23 -0
@@ -4294,6 +4294,27 @@ static void device_del_completion(ReadLineState *rs, BusState *bus, } } +static void object_del_completion (ReadLineState *rs,const char *str) +{ +ObjectPropertyInfoList *list, *start; +size_t len; + + len =strlen (str); +readline_set_completion_index (rs, len); + + start = list =qmp_qom_list ("/objects" ,NULL ); +while (list) { +ObjectPropertyInfo *info = list->value; + +if (!strncmp (info->type,"child<" ,5 ) + && !strncmp (info->name, str, len)) { +readline_add_completion (rs, info->name); + } + list = list->next; + } +qapi_free_ObjectPropertyInfoList (start); +} + static void monitor_find_completion_by_table(Monitor *mon, const mon_cmd_t *cmd_table, char **args,
@@ -4379,6 +4400,8 @@ static void monitor_find_completion_by_table(Monitor *mon,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 :
Signature · 1 line
1.8.3.2
PATCH 4/4 monitor: Add object_add class argument completion.
In reply to Hani Benhabiles--- monitor.c | 23 +++++++++++++++++++++++ 1 file changed, 23 insertions(+)
monitor.c +23 -0
@@ -56,6 +56,7 @@#include "qapi/qmp/qjson.h" #include "qapi/qmp/json-streamer.h" #include "qapi/qmp/json-parser.h" +#include <qom/object_interfaces.h> #include "qemu/osdep.h" #include "cpu.h" #include "trace.h"
@@ -4275,6 +4276,26 @@ static void device_add_completion(ReadLineState *rs, const char *str)g_slist_free (list); } +static void object_add_completion (ReadLineState *rs,const char *str) +{ +GSList *list, *elt; +size_t len; + + len =strlen (str); +readline_set_completion_index (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); + } + elt = elt->next; + } +g_slist_free (list); +} +static void device_del_completion (ReadLineState *rs,BusState *bus,const char *str,size_t len) {
@@ -4381,6 +4402,8 @@ static void monitor_find_completion_by_table(Monitor *mon,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' :
Signature · 1 line
1.8.3.2
Re: [Qemu-devel] [PATCH 4/4] monitor: Add object_add class argument completion.
Quoted 44 lines · On Thu, 6 Feb 2014 23:30:13 +0100 Hani Benhabiles <[email protected]> wrote:
--- monitor.c | 23 +++++++++++++++++++++++ 1 file changed, 23 insertions(+)monitor.c +21
-0@@ -56,6 +56,7 @@#include "qapi/qmp/qjson.h" #include "qapi/qmp/json-streamer.h" #include "qapi/qmp/json-parser.h" +#include <qom/object_interfaces.h> #include "qemu/osdep.h" #include "cpu.h" #include "trace.h" @@ -4275,6 +4276,26 @@ static void device_add_completion(ReadLineState *rs, const char *str)g_slist_free (list); } +static void object_add_completion (ReadLineState *rs,const char *str) +{ +GSList *list, *elt; +size_t len; + + len =strlen (str); +readline_set_completion_index (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); + } + elt = elt->next; + } +g_slist_free (list); +} +static void device_del_completion (ReadLineState *rs,BusState *bus,const char *str,size_t len) {
monitor.c static void monitor_find_completion_by_table(Monitor *mon, · line 4409
Quoted 8 lines
monitor.c +2
-0@@ -4381,6 +4402,8 @@ static void monitor_find_completion_by_table(Monitor *mon,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' :
Those many ifs need to be generalized. Maybe we could add a command_completion callback to mon_cmd_t? Anyway, I won't refuse the series because of that but it would be very welcome to improve this.
Re: [Qemu-devel] [PATCH 4/4] monitor: Add object_add class argument completion.
Quoted 51 lines · Luiz Capitulino
Quoted 48 lines · On Thu, 6 Feb 2014 23:30:13 +0100 Hani Benhabiles <[email protected]> wrote:
--- monitor.c | 23 +++++++++++++++++++++++ 1 file changed, 23 insertions(+)monitor.c +22
-0@@ -56,6 +56,7 @@#include "qapi/qmp/qjson.h" #include "qapi/qmp/json-streamer.h" #include "qapi/qmp/json-parser.h" +#include <qom/object_interfaces.h> #include "qemu/osdep.h" #include "cpu.h" #include "trace.h" @@ -4275,6 +4276,26 @@ static void device_add_completion(ReadLineState *rs, const char *str)g_slist_free (list); } +static void object_add_completion (ReadLineState *rs,const char *str) +{ +GSList *list, *elt; +size_t len; + + len =strlen (str); +readline_set_completion_index (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); + } + elt = elt->next; + } +g_slist_free (list); +} +static void device_del_completion (ReadLineState *rs,BusState *bus,const char *str,size_t len) {@@ -4381,6 +4402,8 @@ static void monitor_find_completion_by_table(Monitor *mon,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 ) {
Quoted 8 lines
monitor.c static void monitor_find_completion_by_table(Monitor *mon, · line 4409
Quoted 4 lines
monitor.c +1
-0+object_add_completion (mon->rs, str); }break ;case 's' :Those many ifs need to be generalized. Maybe we could add a
command_completioncallback tomon_cmd_t? Anyway, I won't refuse the series because of that but it would be very welcome to improve this.
I agree that it could be made better. I will be looking at it next for possible improvements.
Cheers,
Hani.
Quoted 5 lines · On Thu, 6 Feb 2014 23:30:09 +0100 Hani Benhabiles <[email protected]> wrote:
This patch series add argument completion to multiple human monitor console commands.
For
device_addandobject_add, only the 1st argument is completed.
Quoted 8 lines
Hani Benhabiles (4):
monitor: Adddevice_delid argument completion.
monitor: Adddevice_adddevice argument completion.
monitor: Addobject_delid argument completion.
monitor: Addobject_addclass argument completion.monitor.c | 95 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 95 insertions(+)
Series look good and I've applied it to my queue, but I need your sob before sending a pull request.
Quoted 14 lines · Luiz Capitulino
Quoted 11 lines · On Thu, 6 Feb 2014 23:30:09 +0100 Hani Benhabiles <[email protected]> wrote:
This patch series add argument completion to multiple human monitor console commands.
For
device_addandobject_add, only the 1st argument is completed.Hani Benhabiles (4):
monitor: Adddevice_delid argument completion.
monitor: Adddevice_adddevice argument completion.
monitor: Addobject_delid argument completion.
monitor: Addobject_addclass argument completion.
Quoted 5 lines
Quoted 2 lines
monitor.c | 95 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 95 insertions(+)Series look good and I've applied it to my queue, but I need your sob before sending a pull request.
Thanks Luiz! Sorry about the s-o-b.