summaryrefslogtreecommitdiff
path: root/util
diff options
context:
space:
mode:
Diffstat (limited to 'util')
-rw-r--r--util/qemu-option.c32
1 files changed, 26 insertions, 6 deletions
diff --git a/util/qemu-option.c b/util/qemu-option.c
index 9a5f263294..de42e2a406 100644
--- a/util/qemu-option.c
+++ b/util/qemu-option.c
@@ -224,7 +224,14 @@ static const char *opt_type_to_string(enum QemuOptType type)
g_assert_not_reached();
}
-void qemu_opts_print_help(QemuOptsList *list)
+/**
+ * Print the list of options available in the given list. If
+ * @print_caption is true, a caption (including the list name, if it
+ * exists) is printed. The options itself will be indented, so
+ * @print_caption should only be set to false if the caller prints its
+ * own custom caption (so that the indentation makes sense).
+ */
+void qemu_opts_print_help(QemuOptsList *list, bool print_caption)
{
QemuOptDesc *desc;
int i;
@@ -234,12 +241,12 @@ void qemu_opts_print_help(QemuOptsList *list)
desc = list->desc;
while (desc && desc->name) {
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,
+ g_string_append_printf(str, " %s=<%s>", desc->name,
opt_type_to_string(desc->type));
if (desc->help) {
+ if (str->len < 24) {
+ g_string_append_printf(str, "%*s", 24 - (int)str->len, "");
+ }
g_string_append_printf(str, " - %s", desc->help);
}
g_ptr_array_add(array, g_string_free(str, false));
@@ -247,6 +254,19 @@ void qemu_opts_print_help(QemuOptsList *list)
}
g_ptr_array_sort(array, (GCompareFunc)qemu_pstrcmp0);
+ if (print_caption && array->len > 0) {
+ if (list->name) {
+ printf("%s options:\n", list->name);
+ } else {
+ printf("Options:\n");
+ }
+ } else if (array->len == 0) {
+ if (list->name) {
+ printf("There are no options for %s.\n", list->name);
+ } else {
+ printf("No options available.\n");
+ }
+ }
for (i = 0; i < array->len; i++) {
printf("%s\n", (char *)array->pdata[i]);
}
@@ -930,7 +950,7 @@ QemuOpts *qemu_opts_parse_noisily(QemuOptsList *list, const char *params,
opts = opts_parse(list, params, permit_abbrev, false, &invalidp, &err);
if (err) {
if (invalidp && has_help_option(params)) {
- qemu_opts_print_help(list);
+ qemu_opts_print_help(list, true);
error_free(err);
} else {
error_report_err(err);