From nobody Wed May 14 20:16:40 2025 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.com: domain of redhat.com designates 209.132.183.28 as permitted sender) client-ip=209.132.183.28; envelope-from=libvir-list-bounces@redhat.com; helo=mx1.redhat.com; Authentication-Results: mx.zohomail.com; spf=pass (zoho.com: domain of redhat.com designates 209.132.183.28 as permitted sender) smtp.mailfrom=libvir-list-bounces@redhat.com; dmarc=pass(p=none dis=none) header.from=redhat.com Return-Path: Received: from mx1.redhat.com (mx1.redhat.com [209.132.183.28]) by mx.zohomail.com with SMTPS id 153503979220080.6107587663065; Thu, 23 Aug 2018 08:56:32 -0700 (PDT) Received: from smtp.corp.redhat.com (int-mx07.intmail.prod.int.phx2.redhat.com [10.5.11.22]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 7553030832D7; Thu, 23 Aug 2018 15:56:30 +0000 (UTC) Received: from colo-mx.corp.redhat.com (colo-mx01.intmail.prod.int.phx2.redhat.com [10.5.11.20]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 2EC501001F5D; Thu, 23 Aug 2018 15:56:30 +0000 (UTC) Received: from lists01.pubmisc.prod.ext.phx2.redhat.com (lists01.pubmisc.prod.ext.phx2.redhat.com [10.5.19.33]) by colo-mx.corp.redhat.com (Postfix) with ESMTP id CFBC0181A12F; Thu, 23 Aug 2018 15:56:29 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx03.intmail.prod.int.rdu2.redhat.com [10.11.54.3]) by lists01.pubmisc.prod.ext.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id w7NFroq4028070 for ; Thu, 23 Aug 2018 11:53:50 -0400 Received: by smtp.corp.redhat.com (Postfix) id 176AA10CD893; Thu, 23 Aug 2018 15:53:50 +0000 (UTC) Received: from localhost.localdomain.com (unknown [10.43.2.88]) by smtp.corp.redhat.com (Postfix) with ESMTP id 8661D10CD890; Thu, 23 Aug 2018 15:53:49 +0000 (UTC) From: Simon Kobyda To: libvir-list@redhat.com Date: Thu, 23 Aug 2018 17:53:42 +0200 Message-Id: <20180823155343.29044-3-skobyda@redhat.com> In-Reply-To: <20180823155343.29044-1-skobyda@redhat.com> References: <20180823155343.29044-1-skobyda@redhat.com> X-Scanned-By: MIMEDefang 2.78 on 10.11.54.3 X-loop: libvir-list@redhat.com Cc: Simon Kobyda Subject: [libvirt] [PATCH v5 2/3] virsh: Implement new table API for virsh list X-BeenThere: libvir-list@redhat.com X-Mailman-Version: 2.1.12 Precedence: junk List-Id: Development discussions about the libvirt library & tools List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Sender: libvir-list-bounces@redhat.com Errors-To: libvir-list-bounces@redhat.com X-Scanned-By: MIMEDefang 2.84 on 10.5.11.22 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.44]); Thu, 23 Aug 2018 15:56:31 +0000 (UTC) X-ZohoMail: RDMRC_0 RSF_0 Z_629925259 SPT_0 Content-Type: text/plain; charset="utf-8" Instead of printing it straight in virsh, it creates table struct which is filled with header and rows(domains). It allows us to know more about table before printing to calculate alignment right. Signed-off-by: Simon Kobyda --- tests/virshtest.c | 14 ++++++------ tools/virsh-domain-monitor.c | 43 ++++++++++++++++++++---------------- 2 files changed, 31 insertions(+), 26 deletions(-) diff --git a/tests/virshtest.c b/tests/virshtest.c index 94548a82d1..10cd0d356b 100644 --- a/tests/virshtest.c +++ b/tests/virshtest.c @@ -98,9 +98,9 @@ static int testCompareListDefault(const void *data ATTRIB= UTE_UNUSED) { const char *const argv[] =3D { VIRSH_DEFAULT, "list", NULL }; const char *exp =3D "\ - Id Name State\n\ -----------------------------------------------------\n\ - 1 test running\n\ + Id Name State \n\ +----------------------\n\ + 1 test running \n\ \n"; return testCompareOutputLit(exp, NULL, argv); } @@ -109,10 +109,10 @@ static int testCompareListCustom(const void *data ATT= RIBUTE_UNUSED) { const char *const argv[] =3D { VIRSH_CUSTOM, "list", NULL }; const char *exp =3D "\ - Id Name State\n\ -----------------------------------------------------\n\ - 1 fv0 running\n\ - 2 fc4 running\n\ + Id Name State \n\ +----------------------\n\ + 1 fv0 running \n\ + 2 fc4 running \n\ \n"; return testCompareOutputLit(exp, NULL, argv); } diff --git a/tools/virsh-domain-monitor.c b/tools/virsh-domain-monitor.c index b9b4f9739b..adc5bb1a7a 100644 --- a/tools/virsh-domain-monitor.c +++ b/tools/virsh-domain-monitor.c @@ -39,6 +39,7 @@ #include "virmacaddr.h" #include "virxml.h" #include "virstring.h" +#include "vsh-table.h" =20 VIR_ENUM_DECL(virshDomainIOError) VIR_ENUM_IMPL(virshDomainIOError, @@ -1901,6 +1902,7 @@ cmdList(vshControl *ctl, const vshCmd *cmd) char id_buf[INT_BUFSIZE_BOUND(unsigned int)]; unsigned int id; unsigned int flags =3D VIR_CONNECT_LIST_DOMAINS_ACTIVE; + vshTablePtr table =3D NULL; =20 /* construct filter flags */ if (vshCommandOptBool(cmd, "inactive") || @@ -1940,15 +1942,12 @@ cmdList(vshControl *ctl, const vshCmd *cmd) /* print table header in legacy mode */ if (optTable) { if (optTitle) - vshPrintExtra(ctl, " %-5s %-30s %-10s %-20s\n%s\n", - _("Id"), _("Name"), _("State"), _("Title"), - "-----------------------------------------" - "-----------------------------------------"); + table =3D vshTableNew("Id", "Name", "State", "Title", NULL); else - vshPrintExtra(ctl, " %-5s %-30s %s\n%s\n", - _("Id"), _("Name"), _("State"), - "-----------------------------------------" - "-----------"); + table =3D vshTableNew("Id", "Name", "State", NULL); + + if (!table) + goto cleanup; } =20 for (i =3D 0; i < list->ndomains; i++) { @@ -1973,20 +1972,22 @@ cmdList(vshControl *ctl, const vshCmd *cmd) if (optTitle) { if (!(title =3D virshGetDomainDescription(ctl, dom, true, = 0))) goto cleanup; - - vshPrint(ctl, " %-5s %-30s %-10s %-20s\n", id_buf, - virDomainGetName(dom), - state =3D=3D -2 ? _("saved") - : virshDomainStateToString(state), - title); - + if (vshTableRowAppend(table, id_buf, + virDomainGetName(dom), + state =3D=3D -2 ? _("saved") + : virshDomainStateToString(state), + title, NULL) < 0) + goto cleanup; VIR_FREE(title); } else { - vshPrint(ctl, " %-5s %-30s %s\n", id_buf, - virDomainGetName(dom), - state =3D=3D -2 ? _("saved") - : virshDomainStateToString(state)); + if (vshTableRowAppend(table, id_buf, + virDomainGetName(dom), + state =3D=3D -2 ? _("saved") + : virshDomainStateToString(state), + NULL) < 0) + goto cleanup; } + } else if (optUUID && optName) { if (virDomainGetUUIDString(dom, uuid) < 0) { vshError(ctl, "%s", _("Failed to get domain's UUID")); @@ -2004,8 +2005,12 @@ cmdList(vshControl *ctl, const vshCmd *cmd) } } =20 + if (optTable) + vshTablePrintToStdout(table, ctl); + ret =3D true; cleanup: + vshTableFree(table); virshDomainListFree(list); return ret; } --=20 2.17.1 -- libvir-list mailing list libvir-list@redhat.com https://www.redhat.com/mailman/listinfo/libvir-list