[Qemu-devel] [PATCH v2 4/5] object: Make option help nicer to read

Max Reitz posted 5 patches 7 years, 3 months ago
[Qemu-devel] [PATCH v2 4/5] object: Make option help nicer to read
Posted by Max Reitz 7 years, 3 months ago
Just like in qemu_opts_print_help(), print the object name as a caption
instead of on every single line, indent all options, add angle brackets
around types, and align the descriptions after 24 characters.

Also, indent every object name in the list of available objects.

Signed-off-by: Max Reitz <mreitz@redhat.com>
---
 vl.c | 13 ++++++++++---
 1 file changed, 10 insertions(+), 3 deletions(-)

diff --git a/vl.c b/vl.c
index ac3ed17de4..ecddbb6b8e 100644
--- a/vl.c
+++ b/vl.c
@@ -2707,7 +2707,7 @@ static bool object_create_initial(const char *type, QemuOpts *opts)
         list = object_class_get_list_sorted(TYPE_USER_CREATABLE, false);
         for (l = list; l != NULL; l = l->next) {
             ObjectClass *oc = OBJECT_CLASS(l->data);
-            printf("%s\n", object_class_get_name(oc));
+            printf("  %s\n", object_class_get_name(oc));
         }
         g_slist_free(list);
         exit(0);
@@ -2729,14 +2729,21 @@ static bool object_create_initial(const char *type, QemuOpts *opts)
             }
 
             str = g_string_new(NULL);
-            g_string_append_printf(str, "%s.%s=%s", type,
-                                   prop->name, prop->type);
+            g_string_append_printf(str, "  %s=<%s>", prop->name, prop->type);
             if (prop->description) {
+                if (str->len < 24) {
+                    g_string_append_printf(str, "%*s", 24 - (int)str->len, "");
+                }
                 g_string_append_printf(str, " - %s", prop->description);
             }
             g_ptr_array_add(array, g_string_free(str, false));
         }
         g_ptr_array_sort(array, (GCompareFunc)qemu_pstrcmp0);
+        if (array->len > 0) {
+            printf("%s options:\n", type);
+        } else {
+            printf("There are no options for %s.\n", type);
+        }
         for (i = 0; i < array->len; i++) {
             printf("%s\n", (char *)array->pdata[i]);
         }
-- 
2.17.1


Re: [Qemu-devel] [PATCH v2 4/5] object: Make option help nicer to read
Posted by Marc-André Lureau 7 years, 3 months ago
On Fri, Oct 19, 2018 at 8:49 PM Max Reitz <mreitz@redhat.com> wrote:
>
> Just like in qemu_opts_print_help(), print the object name as a caption
> instead of on every single line, indent all options, add angle brackets
> around types, and align the descriptions after 24 characters.
>
> Also, indent every object name in the list of available objects.
>
> Signed-off-by: Max Reitz <mreitz@redhat.com>

Reviewed-by: Marc-André Lureau <marcandre.lureau@redhat.com>

> ---
>  vl.c | 13 ++++++++++---
>  1 file changed, 10 insertions(+), 3 deletions(-)
>
> diff --git a/vl.c b/vl.c
> index ac3ed17de4..ecddbb6b8e 100644
> --- a/vl.c
> +++ b/vl.c
> @@ -2707,7 +2707,7 @@ static bool object_create_initial(const char *type, QemuOpts *opts)
>          list = object_class_get_list_sorted(TYPE_USER_CREATABLE, false);
>          for (l = list; l != NULL; l = l->next) {
>              ObjectClass *oc = OBJECT_CLASS(l->data);
> -            printf("%s\n", object_class_get_name(oc));
> +            printf("  %s\n", object_class_get_name(oc));
>          }
>          g_slist_free(list);
>          exit(0);
> @@ -2729,14 +2729,21 @@ static bool object_create_initial(const char *type, QemuOpts *opts)
>              }
>
>              str = g_string_new(NULL);
> -            g_string_append_printf(str, "%s.%s=%s", type,
> -                                   prop->name, prop->type);
> +            g_string_append_printf(str, "  %s=<%s>", prop->name, prop->type);
>              if (prop->description) {
> +                if (str->len < 24) {
> +                    g_string_append_printf(str, "%*s", 24 - (int)str->len, "");
> +                }
>                  g_string_append_printf(str, " - %s", prop->description);
>              }
>              g_ptr_array_add(array, g_string_free(str, false));
>          }
>          g_ptr_array_sort(array, (GCompareFunc)qemu_pstrcmp0);
> +        if (array->len > 0) {
> +            printf("%s options:\n", type);
> +        } else {
> +            printf("There are no options for %s.\n", type);
> +        }
>          for (i = 0; i < array->len; i++) {
>              printf("%s\n", (char *)array->pdata[i]);
>          }
> --
> 2.17.1
>