Let's factor out the code to format a help string for a property. We
are going to reuse it in qdev next, which will bring some consistency.
Signed-off-by: Marc-André Lureau <marcandre.lureau@redhat.com>
---
include/qom/object.h | 13 +++++++++++++
qom/object_interfaces.c | 39 +++++++++++++++++++++++----------------
2 files changed, 36 insertions(+), 16 deletions(-)
diff --git a/include/qom/object.h b/include/qom/object.h
index 933e5c6cb9..a28e37a648 100644
--- a/include/qom/object.h
+++ b/include/qom/object.h
@@ -1854,6 +1854,19 @@ Object *container_get(Object *root, const char *path);
*/
size_t object_type_get_instance_size(const char *typename);
+/**
+ * object_property_help:
+ * @name: the name of the property
+ * @type: the type of the property
+ * @defval: the default value
+ * @description: description of the property
+ *
+ * Returns: a user-friendly formatted string describing the property
+ * for help purposes.
+ */
+char *object_property_help(const char *name, const char *type,
+ const char *defval, const char *description);
+
G_DEFINE_AUTOPTR_CLEANUP_FUNC(Object, object_unref)
#endif
diff --git a/qom/object_interfaces.c b/qom/object_interfaces.c
index edb4cc4a3d..b7157d6ab0 100644
--- a/qom/object_interfaces.c
+++ b/qom/object_interfaces.c
@@ -158,6 +158,25 @@ int user_creatable_add_opts_foreach(void *opaque, QemuOpts
*opts, Error **errp)
return 0;
}
+char *object_property_help(const char *name, const char *type,
+ const char *defval, const char *description)
+{
+ GString *str = g_string_new(NULL);
+
+ g_string_append_printf(str, " %s=<%s>", name, type);
+ if (defval) {
+ g_string_append_printf(str, " (default: %s)", defval);
+ }