]> git.ipfire.org Git - thirdparty/libvirt.git/commitdiff
virsh: Pretty the output of qemu-agent-command
authorOsier Yang <jyang@redhat.com>
Tue, 14 May 2013 15:32:33 +0000 (23:32 +0800)
committerOsier Yang <jyang@redhat.com>
Tue, 14 May 2013 17:02:25 +0000 (01:02 +0800)
This adds a new option "--pretty" for qemu-agent-command, to
pretty-format the returned JSON string.

tools/virsh-domain.c

index 546b18284c4a182ddceb5479b84c62373f5e2373..bb94ac1ae9d3939a4570d110d254ba335192c5c2 100644 (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;