diff mbox

[1/3] qdev: Add help for device properties

Message ID 1264024715-23417-1-git-send-email-weil@mail.berlios.de
State New
Headers show

Commit Message

Stefan Weil Jan. 20, 2010, 9:58 p.m. UTC
When called with property "?", a list of supported
properties will be printed (instead of an error message).

This is useful for command lines like
	qemu -device e1000,?
and was already standard for other options like model=?

Signed-off-by: Stefan Weil <weil@mail.berlios.de>
---
 hw/qdev-properties.c |   15 +++++++++++++--
 1 files changed, 13 insertions(+), 2 deletions(-)

Comments

Markus Armbruster Jan. 21, 2010, 4:38 p.m. UTC | #1
Stefan Weil <weil@mail.berlios.de> writes:

> When called with property "?", a list of supported
> properties will be printed (instead of an error message).
>
> This is useful for command lines like
> 	qemu -device e1000,?
> and was already standard for other options like model=?
>
> Signed-off-by: Stefan Weil <weil@mail.berlios.de>
> ---
>  hw/qdev-properties.c |   15 +++++++++++++--
>  1 files changed, 13 insertions(+), 2 deletions(-)
>
> diff --git a/hw/qdev-properties.c b/hw/qdev-properties.c
> index 277ff9e..8547ad2 100644
> --- a/hw/qdev-properties.c
> +++ b/hw/qdev-properties.c
> @@ -544,8 +544,19 @@ int qdev_prop_parse(DeviceState *dev, const char *name, const char *value)
>  
>      prop = qdev_prop_find(dev, name);
>      if (!prop) {
> -        fprintf(stderr, "property \"%s.%s\" not found\n",
> -                dev->info->name, name);
> +        if (strcmp(name, "?") != 0) {
> +            fprintf(stderr, "property \"%s.%s\" not found\n",
> +                    dev->info->name, name);
> +        } else {
> +            fprintf(stderr, "supported properties:\n");
> +            if (dev->info->props != NULL) {
> +                Property *props = dev->info->props;
> +                while (props->name) {
> +                    fprintf(stderr, "%s.%s\n", dev->info->name, props->name);
> +                    props++;
> +                }
> +            }
> +        }
>          return -1;
>      }
>      if (!prop->info->parse) {

I like it.
Markus Armbruster Jan. 21, 2010, 4:44 p.m. UTC | #2
Markus Armbruster <armbru@redhat.com> writes:

> Stefan Weil <weil@mail.berlios.de> writes:
>
>> When called with property "?", a list of supported
>> properties will be printed (instead of an error message).
>>
>> This is useful for command lines like
>> 	qemu -device e1000,?
>> and was already standard for other options like model=?
>>
>> Signed-off-by: Stefan Weil <weil@mail.berlios.de>
>> ---
>>  hw/qdev-properties.c |   15 +++++++++++++--
>>  1 files changed, 13 insertions(+), 2 deletions(-)
>>
>> diff --git a/hw/qdev-properties.c b/hw/qdev-properties.c
>> index 277ff9e..8547ad2 100644
>> --- a/hw/qdev-properties.c
>> +++ b/hw/qdev-properties.c
>> @@ -544,8 +544,19 @@ int qdev_prop_parse(DeviceState *dev, const char *name, const char *value)
>>  
>>      prop = qdev_prop_find(dev, name);
>>      if (!prop) {
>> -        fprintf(stderr, "property \"%s.%s\" not found\n",
>> -                dev->info->name, name);
>> +        if (strcmp(name, "?") != 0) {
>> +            fprintf(stderr, "property \"%s.%s\" not found\n",
>> +                    dev->info->name, name);
>> +        } else {
>> +            fprintf(stderr, "supported properties:\n");
>> +            if (dev->info->props != NULL) {
>> +                Property *props = dev->info->props;
>> +                while (props->name) {
>> +                    fprintf(stderr, "%s.%s\n", dev->info->name, props->name);
>> +                    props++;
>> +                }
>> +            }
>> +        }
>>          return -1;
>>      }
>>      if (!prop->info->parse) {
>
> I like it.

One question, though: why print DRIVER.PROPNAME instead of just
PROPNAME?  You could still put DRIVER into the heading, say "Properties
of DRIVER:".
Gerd Hoffmann Jan. 21, 2010, 5:28 p.m. UTC | #3
On 01/21/10 17:44, Markus Armbruster wrote:
> Markus Armbruster<armbru@redhat.com>  writes:
>
>>> -        fprintf(stderr, "property \"%s.%s\" not found\n",
>>> -                dev->info->name, name);

>>> +                    fprintf(stderr, "%s.%s\n", dev->info->name, props->name);
>>> +                    props++;

> One question, though: why print DRIVER.PROPNAME instead of just
> PROPNAME?  You could still put DRIVER into the heading, say "Properties
> of DRIVER:".

Probably for consistency with the error messages.

cheers,
   Gerd
diff mbox

Patch

diff --git a/hw/qdev-properties.c b/hw/qdev-properties.c
index 277ff9e..8547ad2 100644
--- a/hw/qdev-properties.c
+++ b/hw/qdev-properties.c
@@ -544,8 +544,19 @@  int qdev_prop_parse(DeviceState *dev, const char *name, const char *value)
 
     prop = qdev_prop_find(dev, name);
     if (!prop) {
-        fprintf(stderr, "property \"%s.%s\" not found\n",
-                dev->info->name, name);
+        if (strcmp(name, "?") != 0) {
+            fprintf(stderr, "property \"%s.%s\" not found\n",
+                    dev->info->name, name);
+        } else {
+            fprintf(stderr, "supported properties:\n");
+            if (dev->info->props != NULL) {
+                Property *props = dev->info->props;
+                while (props->name) {
+                    fprintf(stderr, "%s.%s\n", dev->info->name, props->name);
+                    props++;
+                }
+            }
+        }
         return -1;
     }
     if (!prop->info->parse) {