[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Qemu-devel] [PATCH 02/10] qemu-option: improve qemu_opts_print_help() o
From: |
Marc-André Lureau |
Subject: |
[Qemu-devel] [PATCH 02/10] qemu-option: improve qemu_opts_print_help() output |
Date: |
Thu, 6 Sep 2018 19:12:19 +0400 |
Modify qemu_opts_print_help():
- to print expected argument type
- skip description if not available
- sort lines
- prefix with the list name (like qdev, to avoid confusion)
- drop 16-chars alignment, use a '-' as seperator for option name and
description
For ex, "-spice ?" output is changed from:
port No description available
tls-port No description available
addr No description available
[...]
gl No description available
rendernode No description available
to:
spice.addr=str
spice.agent-mouse=bool (on/off)
spice.disable-agent-file-xfer=bool (on/off)
[...]
spice.x509-key-password=str
spice.zlib-glz-wan-compression=str
"qemu-img create -f qcow2 -o ?", changed from:
size Virtual disk size
compat Compatibility level (0.10 or 1.1)
backing_file File name of a base image
[...]
lazy_refcounts Postpone refcount updates
refcount_bits Width of a reference count entry in bits
to:
backing_file=str - File name of a base image
backing_fmt=str - Image format of the base image
cluster_size=size - qcow2 cluster size
[...]
refcount_bits=num - Width of a reference count entry in bits
size=size - Virtual disk size
Signed-off-by: Marc-André Lureau <address@hidden>
---
util/qemu-option.c | 44 ++++++++++++++++++++++++++++++++++++++++++--
1 file changed, 42 insertions(+), 2 deletions(-)
diff --git a/util/qemu-option.c b/util/qemu-option.c
index 557b6c6626..a54cf74b49 100644
--- a/util/qemu-option.c
+++ b/util/qemu-option.c
@@ -208,17 +208,57 @@ out:
return result;
}
+static const char *opt_type_to_string(enum QemuOptType type)
+{
+ switch (type) {
+ case QEMU_OPT_STRING:
+ return "str";
+ case QEMU_OPT_BOOL:
+ return "bool (on/off)";
+ case QEMU_OPT_NUMBER:
+ return "num";
+ case QEMU_OPT_SIZE:
+ return "size";
+ }
+
+ g_assert_not_reached();
+}
+
+static gint
+pstrcmp(const char **a, const char **b)
+{
+ return g_strcmp0(*a, *b);
+}
+
void qemu_opts_print_help(QemuOptsList *list)
{
QemuOptDesc *desc;
+ int i;
+ GPtrArray *array = g_ptr_array_new();
assert(list);
desc = list->desc;
while (desc && desc->name) {
- printf("%-16s %s\n", desc->name,
- desc->help ? desc->help : "No description available");
+ GString *str = g_string_new(NULL);
+ if (list->name) {
+ g_string_append_printf(str, "%s.", list->name);
+ }
+ g_string_append_printf(str, "%s=%s", desc->name,
+ opt_type_to_string(desc->type));
+ if (desc->help) {
+ g_string_append_printf(str, " - %s", desc->help);
+ }
+ g_ptr_array_add(array, g_string_free(str, false));
desc++;
}
+
+ g_ptr_array_sort(array, (GCompareFunc)pstrcmp);
+ for (i = 0; i < array->len; i++) {
+ printf("%s\n", (char *)array->pdata[i]);
+ }
+ g_ptr_array_set_free_func(array, g_free);
+ g_ptr_array_free(array, true);
+
}
/* ------------------------------------------------------------------ */
--
2.19.0.rc1
- [Qemu-devel] [PATCH 00/10] Various qemu command line options help improvements, Marc-André Lureau, 2018/09/06
- [Qemu-devel] [PATCH 01/10] qemu-option: add help fallback to print the list of options, Marc-André Lureau, 2018/09/06
- [Qemu-devel] [PATCH 03/10] qom/object: fix iterating properties over a class, Marc-André Lureau, 2018/09/06
- [Qemu-devel] [PATCH 02/10] qemu-option: improve qemu_opts_print_help() output,
Marc-André Lureau <=
- [Qemu-devel] [PATCH 04/10] qom/object: register 'type' property as class property, Marc-André Lureau, 2018/09/06
- [Qemu-devel] [PATCH 06/10] tests/qom-proplist: check properties are not listed multiple times, Marc-André Lureau, 2018/09/06
- [Qemu-devel] [PATCH 07/10] tests/qom-proplist: check class properties iterator, Marc-André Lureau, 2018/09/06
- [Qemu-devel] [PATCH 08/10] vl: handle -object ?, Marc-André Lureau, 2018/09/06
- [Qemu-devel] [PATCH 05/10] tests/qom-proplist: check duplicate "bv" property registration failed, Marc-André Lureau, 2018/09/06
- [Qemu-devel] [PATCH 09/10] hostmem: add some properties description, Marc-André Lureau, 2018/09/06
- [Qemu-devel] [PATCH 10/10] vl: list user creatable propeties if '?' as argument, Marc-André Lureau, 2018/09/06