qom: Support JSON in HMP object_add and tools --object
Support JSON for --object in all tools and in HMP object_add in the same way as it is supported in qobject_input_visitor_new_str(). Signed-off-by: Kevin Wolf <kwolf@redhat.com> Message-Id: <20210312131921.421023-1-kwolf@redhat.com> Reviewed-by: Eric Blake <eblake@redhat.com> Reviewed-by: Markus Armbruster <armbru@redhat.com> Signed-off-by: Kevin Wolf <kwolf@redhat.com>
This commit is contained in:
parent
f3b70e0779
commit
155b5f8b8d
@ -296,12 +296,19 @@ static void user_creatable_print_help_from_qdict(QDict *args)
|
|||||||
ObjectOptions *user_creatable_parse_str(const char *optarg, Error **errp)
|
ObjectOptions *user_creatable_parse_str(const char *optarg, Error **errp)
|
||||||
{
|
{
|
||||||
ERRP_GUARD();
|
ERRP_GUARD();
|
||||||
QDict *args;
|
QObject *obj;
|
||||||
bool help;
|
bool help;
|
||||||
Visitor *v;
|
Visitor *v;
|
||||||
ObjectOptions *options;
|
ObjectOptions *options;
|
||||||
|
|
||||||
args = keyval_parse(optarg, "qom-type", &help, errp);
|
if (optarg[0] == '{') {
|
||||||
|
obj = qobject_from_json(optarg, errp);
|
||||||
|
if (!obj) {
|
||||||
|
return NULL;
|
||||||
|
}
|
||||||
|
v = qobject_input_visitor_new(obj);
|
||||||
|
} else {
|
||||||
|
QDict *args = keyval_parse(optarg, "qom-type", &help, errp);
|
||||||
if (*errp) {
|
if (*errp) {
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
@ -311,10 +318,13 @@ ObjectOptions *user_creatable_parse_str(const char *optarg, Error **errp)
|
|||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
v = qobject_input_visitor_new_keyval(QOBJECT(args));
|
obj = QOBJECT(args);
|
||||||
|
v = qobject_input_visitor_new_keyval(obj);
|
||||||
|
}
|
||||||
|
|
||||||
visit_type_ObjectOptions(v, NULL, &options, errp);
|
visit_type_ObjectOptions(v, NULL, &options, errp);
|
||||||
visit_free(v);
|
visit_free(v);
|
||||||
qobject_unref(args);
|
qobject_unref(obj);
|
||||||
|
|
||||||
return options;
|
return options;
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user