diff mbox

object: Add 'help' option to print all available object backend types

Message ID 20160816171316.16959-1-lma@suse.com (mailing list archive)
State New, archived
Headers show

Commit Message

Lin Ma Aug. 16, 2016, 5:13 p.m. UTC
Signed-off-by: Lin Ma <lma@suse.com>
---
 qemu-options.hx         |  5 ++++-
 qom/object_interfaces.c | 16 ++++++++++++++++
 2 files changed, 20 insertions(+), 1 deletion(-)

Comments

Markus Armbruster Aug. 17, 2016, 6:48 a.m. UTC | #1
Lin Ma <lma@suse.com> writes:

> Signed-off-by: Lin Ma <lma@suse.com>
> ---
>  qemu-options.hx         |  5 ++++-
>  qom/object_interfaces.c | 16 ++++++++++++++++
>  2 files changed, 20 insertions(+), 1 deletion(-)
>
> diff --git a/qemu-options.hx b/qemu-options.hx
> index a71aaf8..c5f4a12 100644
> --- a/qemu-options.hx
> +++ b/qemu-options.hx
> @@ -3752,7 +3752,8 @@ DEF("object", HAS_ARG, QEMU_OPTION_object,
>      "                create a new object of type TYPENAME setting properties\n"
>      "                in the order they are specified.  Note that the 'id'\n"
>      "                property must be set.  These objects are placed in the\n"
> -    "                '/objects' path.\n",
> +    "                '/objects' path.\n"
> +    "                Use '-object help' to print available backend types.\n",
>      QEMU_ARCH_ALL)
>  STEXI
>  @item -object @var{typename}[,@var{prop1}=@var{value1},...]
> @@ -3762,6 +3763,8 @@ in the order they are specified.  Note that the 'id'
>  property must be set.  These objects are placed in the
>  '/objects' path.
>  
> +Use '-object help' to print available backend types.
> +
>  @table @option
>  
>  @item -object memory-backend-file,id=@var{id},size=@var{size},mem-path=@var{dir},share=@var{on|off}
> diff --git a/qom/object_interfaces.c b/qom/object_interfaces.c
> index bf59846..8f820a4 100644
> --- a/qom/object_interfaces.c
> +++ b/qom/object_interfaces.c
> @@ -58,6 +58,22 @@ Object *user_creatable_add(const QDict *qdict,
>          goto out_visit;
>      }
>  
> +    if (!strcmp(type, "help")) {

Please use is_help_option().

> +        printf("Available object backend types:\n");
> +        GSList *list = object_class_get_list(TYPE_USER_CREATABLE, false);
> +        while (list) {
> +            const char *name;
> +            name = object_class_get_name(OBJECT_CLASS(list->data));
> +            /* Ignore user-creatable. */
> +            if (strcmp(name, TYPE_USER_CREATABLE)) {
> +                printf("%s\n", name);
> +            }
> +            list = list->next;
> +        }
> +        g_slist_free(list);
> +        exit(0);
> +    }
> +
>      qdict_del(pdict, "id");
>      visit_type_str(v, "id", &id, &local_err);
>      if (local_err) {
Lin Ma Aug. 18, 2016, 9:57 a.m. UTC | #2
>>> Markus Armbruster <armbru@redhat.com> 2016/8/17 星期三 下午 2:48 >>>
>Lin Ma <lma@suse.com> writes:
>
>> Signed-off-by: Lin Ma <lma@suse.com>
>> ---
>>  qemu-options.hx   	  |  5 ++++-
>>  qom/object_interfaces.c | 16 ++++++++++++++++
>>  2 files changed, 20 insertions(+), 1 deletion(-)
>>
>> diff --git a/qemu-options.hx b/qemu-options.hx
>> index a71aaf8..c5f4a12 100644
>> --- a/qemu-options.hx
>> +++ b/qemu-options.hx
>> @@ -3752,7 +3752,8 @@ DEF("object", HAS_ARG, QEMU_OPTION_object,
>>	  "   			 create a new object of type TYPENAME setting properties\n"
>>	  "   			 in the order they are specified.  Note that the 'id'\n"
>>	  "   			 property must be set.  These objects are placed in the\n"
>> -    " 			   '/objects' path.\n",
>> +    " 			   '/objects' path.\n"
>> +    " 			   Use '-object help' to print available backend types.\n",
>>	  QEMU_ARCH_ALL)
>>  STEXI
>>  @item -object @var{typename}[,@var{prop1}=@var{value1},...]
>> @@ -3762,6 +3763,8 @@ in the order they are specified.  Note that the 'id'
>>  property must be set.  These objects are placed in the
>>  '/objects' path.
>>  
>> +Use '-object help' to print available backend types.
>> +
>>  @table @option
>>  
>>  @item -object memory-backend-file,id=@var{id},size=@var{size},mem-path=@var{dir},share=@var{on|off}
>> diff --git a/qom/object_interfaces.c b/qom/object_interfaces.c
>> index bf59846..8f820a4 100644
>> --- a/qom/object_interfaces.c
>> +++ b/qom/object_interfaces.c
>> @@ -58,6 +58,22 @@ Object *user_creatable_add(const QDict *qdict,
>>		  goto out_visit;
>>	  }
>>  
>> +    if (!strcmp(type, "help")) {
>
>Please use is_help_option().
ok, will do it.
btw, Should I add the behaviour like -device argument T,help
to show additional help for type T ?

>> +	    printf("Available object backend types:\n");
>> +	    GSList *list = object_class_get_list(TYPE_USER_CREATABLE, false);
>> +	    while (list) {
>> +		    const char *name;
>> +		    name = object_class_get_name(OBJECT_CLASS(list->data));
>> +		    /* Ignore user-creatable. */
>> +		    if (strcmp(name, TYPE_USER_CREATABLE)) {
>> +			    printf("%s\n", name);
>> +		    }
>> +		    list = list->next;
>> +	    }
>> +	    g_slist_free(list);
>> +	    exit(0);
>> +    }
>> +
>>	  qdict_del(pdict, "id");
>>	  visit_type_str(v, "id", &id, &local_err);
>>	  if (local_err) {
Andreas Färber Aug. 18, 2016, 10:14 a.m. UTC | #3
Am 18.08.2016 um 11:57 schrieb Lin Ma:
>>>> Markus Armbruster <armbru@redhat.com> 2016/8/17 星期三 下午 2:48 >>>
>>Lin Ma <lma@suse.com> writes:
>>
>>> Signed-off-by: Lin Ma <lma@suse.com>
>>> ---
>>>  qemu-options.hx         |  5 ++++-
>>>  qom/object_interfaces.c | 16 ++++++++++++++++
>>>  2 files changed, 20 insertions(+), 1 deletion(-)
>>>
>>> diff --git a/qemu-options.hx b/qemu-options.hx
>>> index a71aaf8..c5f4a12 100644
>>> --- a/qemu-options.hx
>>> +++ b/qemu-options.hx
>>> @@ -3752,7 +3752,8 @@ DEF("object", HAS_ARG, QEMU_OPTION_object,
>>>      "                create a new object of type TYPENAME setting
> properties\n"
>>>      "                in the order they are specified.  Note that the
> 'id'\n"
>>>      "                property must be set.  These objects are placed
> in the\n"
>>> -    "                '/objects' path.\n",
>>> +    "                '/objects' path.\n"
>>> +    "                Use '-object help' to print available backend
> types.\n",
>>>      QEMU_ARCH_ALL)
>>>  STEXI
>>>  @item -object @var{typename}[,@var{prop1}=@var{value1},...]
>>> @@ -3762,6 +3763,8 @@ in the order they are specified.  Note that the
> 'id'
>>>  property must be set.  These objects are placed in the
>>>  '/objects' path.
>>> 
>>> +Use '-object help' to print available backend types.
>>> +
>>>  @table @option
>>> 
>>>  @item -object
> memory-backend-file,id=@var{id},size=@var{size},mem-path=@var{dir},share=@var{on|off}
>>> diff --git a/qom/object_interfaces.c b/qom/object_interfaces.c
>>> index bf59846..8f820a4 100644
>>> --- a/qom/object_interfaces.c
>>> +++ b/qom/object_interfaces.c
>>> @@ -58,6 +58,22 @@ Object *user_creatable_add(const QDict *qdict,
>>>          goto out_visit;
>>>      }
>>> 
>>> +    if (!strcmp(type, "help")) {
>>
>>Please use is_help_option().
> ok, will do it.

Thanks, otherwise looks good to me. However, I am not really the
maintainer of object_interfaces.c, please check the git log and also CC
Stefan/Paolo or whomever it was for review.

> btw, Should I add the behaviour like -device argument T,help
> to show additional help for type T ?

Not necessarily in this patch, could be done as follow-up.

Cheers,
Andreas

>>> +        printf("Available object backend types:\n");
>>> +        GSList *list = object_class_get_list(TYPE_USER_CREATABLE,
> false);
>>> +        while (list) {
>>> +            const char *name;
>>> +            name = object_class_get_name(OBJECT_CLASS(list->data));
>>> +            /* Ignore user-creatable. */
>>> +            if (strcmp(name, TYPE_USER_CREATABLE)) {
>>> +                printf("%s\n", name);
>>> +            }
>>> +            list = list->next;
>>> +        }
>>> +        g_slist_free(list);
>>> +        exit(0);
>>> +    }
>>> +
>>>      qdict_del(pdict, "id");
>>>      visit_type_str(v, "id", &id, &local_err);
>>>      if (local_err) {
diff mbox

Patch

diff --git a/qemu-options.hx b/qemu-options.hx
index a71aaf8..c5f4a12 100644
--- a/qemu-options.hx
+++ b/qemu-options.hx
@@ -3752,7 +3752,8 @@  DEF("object", HAS_ARG, QEMU_OPTION_object,
     "                create a new object of type TYPENAME setting properties\n"
     "                in the order they are specified.  Note that the 'id'\n"
     "                property must be set.  These objects are placed in the\n"
-    "                '/objects' path.\n",
+    "                '/objects' path.\n"
+    "                Use '-object help' to print available backend types.\n",
     QEMU_ARCH_ALL)
 STEXI
 @item -object @var{typename}[,@var{prop1}=@var{value1},...]
@@ -3762,6 +3763,8 @@  in the order they are specified.  Note that the 'id'
 property must be set.  These objects are placed in the
 '/objects' path.
 
+Use '-object help' to print available backend types.
+
 @table @option
 
 @item -object memory-backend-file,id=@var{id},size=@var{size},mem-path=@var{dir},share=@var{on|off}
diff --git a/qom/object_interfaces.c b/qom/object_interfaces.c
index bf59846..8f820a4 100644
--- a/qom/object_interfaces.c
+++ b/qom/object_interfaces.c
@@ -58,6 +58,22 @@  Object *user_creatable_add(const QDict *qdict,
         goto out_visit;
     }
 
+    if (!strcmp(type, "help")) {
+        printf("Available object backend types:\n");
+        GSList *list = object_class_get_list(TYPE_USER_CREATABLE, false);
+        while (list) {
+            const char *name;
+            name = object_class_get_name(OBJECT_CLASS(list->data));
+            /* Ignore user-creatable. */
+            if (strcmp(name, TYPE_USER_CREATABLE)) {
+                printf("%s\n", name);
+            }
+            list = list->next;
+        }
+        g_slist_free(list);
+        exit(0);
+    }
+
     qdict_del(pdict, "id");
     visit_type_str(v, "id", &id, &local_err);
     if (local_err) {