qom: Factor out helpers from user_creatable_print_help()

This creates separate helper functions for printing a list of user
creatable object types and for printing a list of properties of a given
type. This will allow using these parts without having a QemuOpts.

Signed-off-by: Kevin Wolf <kwolf@redhat.com>
Reviewed-by: Eric Blake <eblake@redhat.com>
Reviewed-by: Markus Armbruster <armbru@redhat.com>
Message-Id: <20201007164903.282198-3-kwolf@redhat.com>
Signed-off-by: Kevin Wolf <kwolf@redhat.com>
master
Kevin Wolf 2020-10-07 18:49:01 +02:00
parent 8bf12c4f75
commit 0e301d4427
1 changed files with 52 additions and 38 deletions

View File

@ -214,11 +214,8 @@ char *object_property_help(const char *name, const char *type,
return g_string_free(str, false);
}
bool user_creatable_print_help(const char *type, QemuOpts *opts)
static void user_creatable_print_types(void)
{
ObjectClass *klass;
if (is_help_option(type)) {
GSList *l, *list;
printf("List of user creatable objects:\n");
@ -228,16 +225,22 @@ bool user_creatable_print_help(const char *type, QemuOpts *opts)
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)) {
static bool user_creatable_print_type_properites(const char *type)
{
ObjectClass *klass;
ObjectPropertyIterator iter;
ObjectProperty *prop;
GPtrArray *array = g_ptr_array_new();
GPtrArray *array;
int i;
klass = object_class_by_name(type);
if (!klass) {
return false;
}
array = g_ptr_array_new();
object_class_property_iter_init(&iter, klass);
while ((prop = object_property_iter_next(&iter))) {
if (!prop->set) {
@ -262,6 +265,17 @@ bool user_creatable_print_help(const char *type, QemuOpts *opts)
return true;
}
bool user_creatable_print_help(const char *type, QemuOpts *opts)
{
if (is_help_option(type)) {
user_creatable_print_types();
return true;
}
if (qemu_opt_has_help_opt(opts)) {
return user_creatable_print_type_properites(type);
}
return false;
}