[libvirt] [PATCH] virsh-volume: Unify alignment of vol-list output columns

Peter Krempa pkrempa at redhat.com
Tue Nov 12 14:16:53 UTC 2013


Add an extra space before the first column as we have when listing
domains.

Previous output:

$ virsh vol-list glusterpool
Name                 Path
-----------------------------------------
asdf                 gluster://gluster-node-1/gv0/asdf
c                    gluster://gluster-node-1/gv0/c
cd                   gluster://gluster-node-1/gv0/cd

$ virsh vol-list glusterpool --details
Name  Path                               Type     Capacity  Allocation
----------------------------------------------------------------------
asdf  gluster://gluster-node-1/gv0/asdf  unknown    0.00 B      0.00 B
c     gluster://gluster-node-1/gv0/c     unknown   16.00 B     16.00 B
cd    gluster://gluster-node-1/gv0/cd    unknown    0.00 B      0.00 B

New output:

$ virsh vol-list glusterpool
 Name                 Path
------------------------------------------------------------------------------
 asdf                 gluster://gluster-node-1/gv0/asdf
 c                    gluster://gluster-node-1/gv0/c
 cd                   gluster://gluster-node-1/gv0/cd

$ virsh vol-list glusterpool --details
 Name  Path                               Type     Capacity  Allocation
------------------------------------------------------------------------
 asdf  gluster://gluster-node-1/gv0/asdf  unknown    0.00 B      0.00 B
 c     gluster://gluster-node-1/gv0/c     unknown   16.00 B     16.00 B
 cd    gluster://gluster-node-1/gv0/cd    unknown    0.00 B      0.00 B
---
 tools/virsh-volume.c | 11 ++++++-----
 1 file changed, 6 insertions(+), 5 deletions(-)

diff --git a/tools/virsh-volume.c b/tools/virsh-volume.c
index 0a66a6c..d85ae92 100644
--- a/tools/virsh-volume.c
+++ b/tools/virsh-volume.c
@@ -1450,10 +1450,11 @@ cmdVolList(vshControl *ctl, const vshCmd *cmd ATTRIBUTE_UNUSED)
     /* Output basic info then return if --details option not selected */
     if (!details) {
         /* The old output format */
-        vshPrintExtra(ctl, "%-20s %-40s\n", _("Name"), _("Path"));
-        vshPrintExtra(ctl, "-----------------------------------------\n");
+        vshPrintExtra(ctl, " %-20s %-40s\n", _("Name"), _("Path"));
+        vshPrintExtra(ctl, "---------------------------------------"
+                           "---------------------------------------\n");
         for (i = 0; i < list->nvols; i++) {
-            vshPrint(ctl, "%-20s %-40s\n", virStorageVolGetName(list->vols[i]),
+            vshPrint(ctl, " %-20s %-40s\n", virStorageVolGetName(list->vols[i]),
                      volInfoTexts[i].path);
         }

@@ -1503,7 +1504,7 @@ cmdVolList(vshControl *ctl, const vshCmd *cmd ATTRIBUTE_UNUSED)

     /* Create the output template */
     ret = virAsprintf(&outputStr,
-                      "%%-%lus  %%-%lus  %%-%lus  %%%lus  %%%lus\n",
+                      " %%-%lus  %%-%lus  %%-%lus  %%%lus  %%%lus\n",
                       (unsigned long) nameStrLength,
                       (unsigned long) pathStrLength,
                       (unsigned long) typeStrLength,
@@ -1519,7 +1520,7 @@ cmdVolList(vshControl *ctl, const vshCmd *cmd ATTRIBUTE_UNUSED)
              ("Capacity"), _("Allocation"));
     for (i = nameStrLength + pathStrLength + typeStrLength
                            + capStrLength + allocStrLength
-                           + 8; i > 0; i--)
+                           + 10; i > 0; i--)
         vshPrintExtra(ctl, "-");
     vshPrintExtra(ctl, "\n");

-- 
1.8.4.3




More information about the libvir-list mailing list