summaryrefslogtreecommitdiffstats
path: root/qom
diff options
context:
space:
mode:
authorKevin Wolf2019-10-11 19:20:12 +0200
committerKevin Wolf2019-10-14 17:12:48 +0200
commit3e9297f3659701a72110f0f560b4cc22452972f1 (patch)
tree8efe5e822111ba96540ce56ca0ecb78078f2b25d /qom
parentiotests/028: Fix for long $TEST_DIRs (diff)
downloadqemu-3e9297f3659701a72110f0f560b4cc22452972f1.tar.gz
qemu-3e9297f3659701a72110f0f560b4cc22452972f1.tar.xz
qemu-3e9297f3659701a72110f0f560b4cc22452972f1.zip
vl: Split off user_creatable_print_help()
Printing help for --object is something that we not only want in the system emulator, but also in tools that support --object. Move it into a separate function in qom/object_interfaces.c to make the code accessible for tools. Signed-off-by: Kevin Wolf <kwolf@redhat.com> Reviewed-by: Eric Blake <eblake@redhat.com>
Diffstat (limited to 'qom')
-rw-r--r--qom/object_interfaces.c61
1 files changed, 61 insertions, 0 deletions
diff --git a/qom/object_interfaces.c b/qom/object_interfaces.c
index cb5809934a..46cd6eab5c 100644
--- a/qom/object_interfaces.c
+++ b/qom/object_interfaces.c
@@ -1,8 +1,11 @@
#include "qemu/osdep.h"
+
+#include "qemu/cutils.h"
#include "qapi/error.h"
#include "qapi/qmp/qdict.h"
#include "qapi/qmp/qerror.h"
#include "qom/object_interfaces.h"
+#include "qemu/help_option.h"
#include "qemu/module.h"
#include "qemu/option.h"
#include "qapi/opts-visitor.h"
@@ -155,6 +158,64 @@ int user_creatable_add_opts_foreach(void *opaque, QemuOpts *opts, Error **errp)
return 0;
}
+bool user_creatable_print_help(const char *type, QemuOpts *opts)
+{
+ ObjectClass *klass;
+
+ if (is_help_option(type)) {
+ GSList *l, *list;
+
+ printf("List of user creatable objects:\n");
+ 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));
+ }
+ g_slist_free(list);
+ return true;
+ }
+
+ klass = object_class_by_name(type);
+ if (klass && qemu_opt_has_help_opt(opts)) {
+ ObjectPropertyIterator iter;
+ ObjectProperty *prop;
+ GPtrArray *array = g_ptr_array_new();
+ int i;
+
+ object_class_property_iter_init(&iter, klass);
+ while ((prop = object_property_iter_next(&iter))) {
+ GString *str;
+
+ if (!prop->set) {
+ continue;
+ }
+
+ str = g_string_new(NULL);
+ 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]);
+ }
+ g_ptr_array_set_free_func(array, g_free);
+ g_ptr_array_free(array, true);
+ return true;
+ }
+
+ return false;
+}
void user_creatable_del(const char *id, Error **errp)
{