From: "Marc-André Lureau" <marcandre.lureau@redhat.com>
To: qemu-devel@nongnu.org
Cc: peter.maydell@linaro.org,
"Marc-André Lureau" <marcandre.lureau@redhat.com>
Subject: [Qemu-devel] [PULL v2 04/12] qemu-option: improve qemu_opts_print_help() output
Date: Fri, 5 Oct 2018 16:29:02 +0400 [thread overview]
Message-ID: <20181005122910.11745-5-marcandre.lureau@redhat.com> (raw)
In-Reply-To: <20181005122910.11745-1-marcandre.lureau@redhat.com>
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 help" 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 help", 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 <marcandre.lureau@redhat.com>
Reviewed-by: Eric Blake <eblake@redhat.com>
---
util/qemu-option.c | 38 ++++++++++++++++++++++++++++++++++++--
1 file changed, 36 insertions(+), 2 deletions(-)
diff --git a/util/qemu-option.c b/util/qemu-option.c
index 557b6c6626..9a5f263294 100644
--- a/util/qemu-option.c
+++ b/util/qemu-option.c
@@ -208,17 +208,51 @@ 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();
+}
+
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)qemu_pstrcmp0);
+ 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.271.gfe8321ec05
next prev parent reply other threads:[~2018-10-05 12:29 UTC|newest]
Thread overview: 14+ messages / expand[flat|nested] mbox.gz Atom feed top
2018-10-05 12:28 [Qemu-devel] [PULL v2 00/12] Option patches Marc-André Lureau
2018-10-05 12:28 ` [Qemu-devel] [PULL v2 01/12] qdev-monitor: print help to stdout Marc-André Lureau
2018-10-05 12:29 ` [Qemu-devel] [PULL v2 02/12] cutils: add qemu_pstrcmp0() Marc-André Lureau
2018-10-05 12:29 ` [Qemu-devel] [PULL v2 03/12] qemu-option: add help fallback to print the list of options Marc-André Lureau
2018-10-05 12:29 ` Marc-André Lureau [this message]
2018-10-05 12:29 ` [Qemu-devel] [PULL v2 05/12] qom/object: fix iterating properties over a class Marc-André Lureau
2018-10-05 12:29 ` [Qemu-devel] [PULL v2 06/12] qom/object: register 'type' property as class property Marc-André Lureau
2018-10-05 12:29 ` [Qemu-devel] [PULL v2 07/12] tests/qom-proplist: check duplicate "bv" property registration failed Marc-André Lureau
2018-10-05 12:29 ` [Qemu-devel] [PULL v2 08/12] tests/qom-proplist: check properties are not listed multiple times Marc-André Lureau
2018-10-05 12:29 ` [Qemu-devel] [PULL v2 09/12] tests/qom-proplist: check class properties iterator Marc-André Lureau
2018-10-05 12:29 ` [Qemu-devel] [PULL v2 10/12] vl: handle -object help Marc-André Lureau
2018-10-05 12:29 ` [Qemu-devel] [PULL v2 11/12] hostmem: add some properties description Marc-André Lureau
2018-10-05 12:29 ` [Qemu-devel] [PULL v2 12/12] vl: list user creatable properties when 'help' is argument Marc-André Lureau
2018-10-08 10:10 ` [Qemu-devel] [PULL v2 00/12] Option patches Peter Maydell
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20181005122910.11745-5-marcandre.lureau@redhat.com \
--to=marcandre.lureau@redhat.com \
--cc=peter.maydell@linaro.org \
--cc=qemu-devel@nongnu.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).