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>
This commit is contained in:
parent
8bf12c4f75
commit
0e301d4427
@ -214,52 +214,66 @@ char *object_property_help(const char *name, const char *type,
|
|||||||
return g_string_free(str, false);
|
return g_string_free(str, false);
|
||||||
}
|
}
|
||||||
|
|
||||||
bool user_creatable_print_help(const char *type, QemuOpts *opts)
|
static void user_creatable_print_types(void)
|
||||||
|
{
|
||||||
|
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);
|
||||||
|
}
|
||||||
|
|
||||||
|
static bool user_creatable_print_type_properites(const char *type)
|
||||||
{
|
{
|
||||||
ObjectClass *klass;
|
ObjectClass *klass;
|
||||||
|
ObjectPropertyIterator iter;
|
||||||
|
ObjectProperty *prop;
|
||||||
|
GPtrArray *array;
|
||||||
|
int i;
|
||||||
|
|
||||||
if (is_help_option(type)) {
|
klass = object_class_by_name(type);
|
||||||
GSList *l, *list;
|
if (!klass) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
printf("List of user creatable objects:\n");
|
array = g_ptr_array_new();
|
||||||
list = object_class_get_list_sorted(TYPE_USER_CREATABLE, false);
|
object_class_property_iter_init(&iter, klass);
|
||||||
for (l = list; l != NULL; l = l->next) {
|
while ((prop = object_property_iter_next(&iter))) {
|
||||||
ObjectClass *oc = OBJECT_CLASS(l->data);
|
if (!prop->set) {
|
||||||
printf(" %s\n", object_class_get_name(oc));
|
continue;
|
||||||
}
|
}
|
||||||
g_slist_free(list);
|
|
||||||
|
g_ptr_array_add(array,
|
||||||
|
object_property_help(prop->name, prop->type,
|
||||||
|
prop->defval, prop->description));
|
||||||
|
}
|
||||||
|
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;
|
||||||
|
}
|
||||||
|
|
||||||
|
bool user_creatable_print_help(const char *type, QemuOpts *opts)
|
||||||
|
{
|
||||||
|
if (is_help_option(type)) {
|
||||||
|
user_creatable_print_types();
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
klass = object_class_by_name(type);
|
if (qemu_opt_has_help_opt(opts)) {
|
||||||
if (klass && qemu_opt_has_help_opt(opts)) {
|
return user_creatable_print_type_properites(type);
|
||||||
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))) {
|
|
||||||
if (!prop->set) {
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
|
|
||||||
g_ptr_array_add(array,
|
|
||||||
object_property_help(prop->name, prop->type,
|
|
||||||
prop->defval, prop->description));
|
|
||||||
}
|
|
||||||
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;
|
return false;
|
||||||
|
Loading…
Reference in New Issue
Block a user