[PATCH] virsh: Pretty the output of qemu-agent-command

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



This adds a new option "--pretty" for qemu-agent-command, to
pretty-format the returned JSON string.
---
 tools/virsh-domain.c | 16 ++++++++++++++++
 1 file changed, 16 insertions(+)

diff --git a/tools/virsh-domain.c b/tools/virsh-domain.c
index 546b182..bb94ac1 100644
--- a/tools/virsh-domain.c
+++ b/tools/virsh-domain.c
@@ -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;
-- 
1.8.1.4

--
libvir-list mailing list
libvir-list@xxxxxxxxxx
https://www.redhat.com/mailman/listinfo/libvir-list




[Index of Archives]     [Virt Tools]     [Libvirt Users]     [Lib OS Info]     [Fedora Users]     [Fedora Desktop]     [Fedora SELinux]     [Big List of Linux Books]     [Yosemite News]     [KDE Users]     [Fedora Tools]