1
0
mirror of https://gitlab.com/libvirt/libvirt.git synced 2025-03-20 06:50:22 +03:00

virsh: Pretty the output of qemu-agent-command

This adds a new option "--pretty" for qemu-agent-command, to
pretty-format the returned JSON string.
This commit is contained in:
Osier Yang 2013-05-14 23:32:33 +08:00
parent 8b9eb14a6d
commit b77737372d

View File

@ -7605,6 +7605,10 @@ static const vshCmdOptDef opts_qemu_agent_command[] = {
.type = VSH_OT_BOOL,
.help = N_("execute command without timeout")
},
{.name = "pretty",
.type = VSH_OT_BOOL,
.help = N_("pretty-print the output")
},
{.name = "cmd",
.type = VSH_OT_ARGV,
.flags = VSH_OFLAG_REQ,
@ -7626,6 +7630,7 @@ cmdQemuAgentCommand(vshControl *ctl, const vshCmd *cmd)
const vshCmdOpt *opt = NULL;
virBuffer buf = VIR_BUFFER_INITIALIZER;
bool pad = false;
virJSONValuePtr pretty = NULL;
dom = vshCommandOptDomain(ctl, cmd, NULL);
if (dom == NULL)
@ -7670,6 +7675,17 @@ cmdQemuAgentCommand(vshControl *ctl, const vshCmd *cmd)
}
result = virDomainQemuAgentCommand(dom, guest_agent_cmd, timeout, flags);
if (vshCommandOptBool(cmd, "pretty")) {
char *tmp;
pretty = virJSONValueFromString(result);
if (pretty && (tmp = virJSONValueToString(pretty, true))) {
VIR_FREE(result);
result = tmp;
} else {
vshResetLibvirtError();
}
}
vshPrint(ctl, "%s\n", result);
ret = true;