Patchwork [2/3] qdev: Add help for property value

login
register
mail settings
Submitter Stefan Weil
Date Jan. 20, 2010, 9:58 p.m.
Message ID <1264024715-23417-2-git-send-email-weil@mail.berlios.de>
Download mbox | patch
Permalink /patch/43377/
State New
Headers show

Comments

Stefan Weil - Jan. 20, 2010, 9:58 p.m.
When called with property value "?",
a help text will be printed (instead of an error message).

This is useful for command lines like
    	qemu -device e1000,mac=?
and is already standard for other command line options.

A better help text could be provided by extending
the Property structure with a desc field.

Signed-off-by: Stefan Weil <weil@mail.berlios.de>
---
 hw/qdev-properties.c |    9 +++++++--
 1 files changed, 7 insertions(+), 2 deletions(-)
Markus Armbruster - Jan. 21, 2010, 4:42 p.m.
Stefan Weil <weil@mail.berlios.de> writes:

> When called with property value "?",
> a help text will be printed (instead of an error message).
>
> This is useful for command lines like
>     	qemu -device e1000,mac=?
> and is already standard for other command line options.
>
> A better help text could be provided by extending
> the Property structure with a desc field.
>
> Signed-off-by: Stefan Weil <weil@mail.berlios.de>
> ---
>  hw/qdev-properties.c |    9 +++++++--
>  1 files changed, 7 insertions(+), 2 deletions(-)
>
> diff --git a/hw/qdev-properties.c b/hw/qdev-properties.c
> index 8547ad2..f5ca05f 100644
> --- a/hw/qdev-properties.c
> +++ b/hw/qdev-properties.c
> @@ -565,8 +565,13 @@ int qdev_prop_parse(DeviceState *dev, const char *name, const char *value)
>          return -1;
>      }
>      if (prop->info->parse(dev, prop, value) != 0) {
> -        fprintf(stderr, "property \"%s.%s\": failed to parse \"%s\"\n",
> -                dev->info->name, name, value);
> +        if (strcmp(value, "?") != 0) {
> +            fprintf(stderr, "property \"%s.%s\": failed to parse \"%s\"\n",
> +                    dev->info->name, name, value);
> +        } else {
> +            fprintf(stderr, "%s.%s=%s\n",
> +                    dev->info->name, name, prop->info->name);
> +        }
>          return -1;
>      }
>      return 0;

This one is problematic.  If prop->info->parse() accepts "?", help is
inaccessible.  PATCH 1/3 is immune to that problem, because we won't
name a property "?".

PATCH 1/3 already makes -device FOO,? print all property names.  I
figure it could just as well print all help along with names.

Patch

diff --git a/hw/qdev-properties.c b/hw/qdev-properties.c
index 8547ad2..f5ca05f 100644
--- a/hw/qdev-properties.c
+++ b/hw/qdev-properties.c
@@ -565,8 +565,13 @@  int qdev_prop_parse(DeviceState *dev, const char *name, const char *value)
         return -1;
     }
     if (prop->info->parse(dev, prop, value) != 0) {
-        fprintf(stderr, "property \"%s.%s\": failed to parse \"%s\"\n",
-                dev->info->name, name, value);
+        if (strcmp(value, "?") != 0) {
+            fprintf(stderr, "property \"%s.%s\": failed to parse \"%s\"\n",
+                    dev->info->name, name, value);
+        } else {
+            fprintf(stderr, "%s.%s=%s\n",
+                    dev->info->name, name, prop->info->name);
+        }
         return -1;
     }
     return 0;