From nobody Mon Feb 9 23:00:18 2026 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of redhat.com designates 216.205.24.124 as permitted sender) client-ip=216.205.24.124; envelope-from=libvir-list-bounces@redhat.com; helo=us-smtp-delivery-124.mimecast.com; Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of redhat.com designates 216.205.24.124 as permitted sender) smtp.mailfrom=libvir-list-bounces@redhat.com; dmarc=pass(p=none dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1628773947; cv=none; d=zohomail.com; s=zohoarc; b=G3BcdMxHMJAwAznzYJeaago/MTwGH4eGYHcUINGJVRwNHk43YxjBUfxPRzsxAF3oXVstvXPUUCQz1E7bRUYHddwGuWKIyLNkJc10IZVpYtkEhkVp8AMof01Mn6hzOvjz7xLc+XipE6t4BSBjKyirs1iyuDgX7sgNnFS1dH56WtY= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1628773947; h=Content-Type:Content-Transfer-Encoding:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To; bh=Dp8ODgYC66q0kPWiROg6rag0UG7WGnCE61oMgRa1wcw=; b=Pq8sLg/g50ORL39nVg8Tp3CSKxDem9q2IF18oQGOMngNKy1SpQ0XCGV5uWrhKoCiXUOr5T0GkYTKS936DXOvqo+PV14utoDruoZqwPqQ9l2ARFWWDdIe5hYgcDFVj/LIPtEJHjfAMfXtoWjnCmrrcWeYi/77tdtbJPwZG2zljOI= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of redhat.com designates 216.205.24.124 as permitted sender) smtp.mailfrom=libvir-list-bounces@redhat.com; dmarc=pass header.from= (p=none dis=none) Return-Path: Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [216.205.24.124]) by mx.zohomail.com with SMTPS id 1628773947569828.4539166744132; Thu, 12 Aug 2021 06:12:27 -0700 (PDT) Received: from mimecast-mx01.redhat.com (mimecast-mx01.redhat.com [209.132.183.4]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-557-sClPyxo3PPKj7ELbojpmcA-1; Thu, 12 Aug 2021 09:12:25 -0400 Received: from smtp.corp.redhat.com (int-mx04.intmail.prod.int.phx2.redhat.com [10.5.11.14]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id 3B22310B1E85; Thu, 12 Aug 2021 13:11:07 +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 17F935D9C6; Thu, 12 Aug 2021 13:11:07 +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 DA101181A137; Thu, 12 Aug 2021 13:11:06 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx04.intmail.prod.int.phx2.redhat.com [10.5.11.14]) by lists01.pubmisc.prod.ext.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id 17CD1l4q029745 for ; Thu, 12 Aug 2021 09:01:47 -0400 Received: by smtp.corp.redhat.com (Postfix) id 6C8F75DA61; Thu, 12 Aug 2021 13:01:47 +0000 (UTC) Received: from speedmetal.redhat.com (unknown [10.40.208.33]) by smtp.corp.redhat.com (Postfix) with ESMTP id C79AA5D9C6 for ; Thu, 12 Aug 2021 13:01:46 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1628773946; h=from:from:sender:sender:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:mime-version:mime-version: content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references:list-id:list-help: list-unsubscribe:list-subscribe:list-post; bh=Dp8ODgYC66q0kPWiROg6rag0UG7WGnCE61oMgRa1wcw=; b=Y3xq0ScWkiljeMiw2Q13xhgRoYUEKG2j2IopHnWTmWO8aQmSVYauN94v7hikgio3seuBdW fn56Uefcua9XN2Uxxrhw8vtLalVkZZwmOfoxcE7d+GL0beZgr+i0SLdrUYYx2nNFzU/BlR J0mY/XNW44IsdoB7FrrVAFrTuTx2YlA= X-MC-Unique: sClPyxo3PPKj7ELbojpmcA-1 From: Peter Krempa To: libvir-list@redhat.com Subject: [PATCH 5/6] virsh: Add testing for vshStringToArray Date: Thu, 12 Aug 2021 15:01:35 +0200 Message-Id: <7d209edda66215ac28c55d4e796d55e4e8b1d33a.1628773245.git.pkrempa@redhat.com> In-Reply-To: References: MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.14 X-loop: libvir-list@redhat.com 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: , Sender: libvir-list-bounces@redhat.com Errors-To: libvir-list-bounces@redhat.com X-Scanned-By: MIMEDefang 2.79 on 10.5.11.14 Authentication-Results: relay.mimecast.com; auth=pass smtp.auth=CUSA124A263 smtp.mailfrom=libvir-list-bounces@redhat.com X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Transfer-Encoding: quoted-printable X-ZohoMail-DKIM: pass (identity @redhat.com) X-ZM-MESSAGEID: 1628773948843100001 Content-Type: text/plain; charset="utf-8" Add a '--split' switch for the 'virsh echo' command and add few test cases to the virshtest. Signed-off-by: Peter Krempa --- tests/virshtest.c | 11 +++++++++++ tools/vsh.c | 15 +++++++++++++++ 2 files changed, 26 insertions(+) diff --git a/tests/virshtest.c b/tests/virshtest.c index 07c27428ae..751e8ffc49 100644 --- a/tests/virshtest.c +++ b/tests/virshtest.c @@ -487,6 +487,17 @@ mymain(void) DO_TEST(46, "a\n", "#unbalanced; 'quotes\"\necho a # b"); DO_TEST(47, "a\n", "\\# ignored;echo a\n'#also' ignored"); + /* test of splitting in vshStringToArray */ + DO_TEST(48, "a\nb,c,\nd,,e,,\nf,,,e\n", + "-q", "echo", "--split", "a,b,,c,,,d,,,,e,,,,,f,,,,,,e"); + DO_TEST(49, "\na\nb,c,\nd,,e,,\nf,,,e\n\n", + "-q", "echo", "--split", ",a,b,,c,,,d,,,,e,,,,,f,,,,,,e,"); + DO_TEST(50, ",a\nb,c,\nd,,e,,\nf,,,e,\n", + "-q", "echo", "--split", ",,a,b,,c,,,d,,,,e,,,,,f,,,,,,e,,"); + DO_TEST(51, ",\na\nb,c,\nd,,e,,\nf,,,e,\n\n", + "-q", "echo", "--split", ",,,a,b,,c,,,d,,,,e,,,,,f,,,,,,e,,,"); + DO_TEST(52, ",,a\nb,c,\nd,,e,,\nf,,,e,,\n", + "-q", "echo", "--split", ",,,,a,b,,c,,,d,,,,e,,,,,f,,,,,,e,,,,= "); # undef DO_TEST VIR_FREE(custom_uri); diff --git a/tools/vsh.c b/tools/vsh.c index 2456267426..cdcf67684e 100644 --- a/tools/vsh.c +++ b/tools/vsh.c @@ -3118,6 +3118,10 @@ const vshCmdOptDef opts_echo[] =3D { .type =3D VSH_OT_BOOL, .help =3D N_("escape for XML use") }, + {.name =3D "split", + .type =3D VSH_OT_BOOL, + .help =3D N_("split each argument on ','; ',,' is an escape sequence") + }, {.name =3D "err", .type =3D VSH_OT_BOOL, .help =3D N_("output to stderr"), @@ -3156,11 +3160,14 @@ cmdEcho(vshControl *ctl, const vshCmd *cmd) bool shell =3D vshCommandOptBool(cmd, "shell"); bool xml =3D vshCommandOptBool(cmd, "xml"); bool err =3D vshCommandOptBool(cmd, "err"); + bool split =3D vshCommandOptBool(cmd, "split"); const vshCmdOpt *opt =3D NULL; g_autofree char *arg =3D NULL; g_auto(virBuffer) buf =3D VIR_BUFFER_INITIALIZER; VSH_EXCLUSIVE_OPTIONS_VAR(shell, xml); + VSH_EXCLUSIVE_OPTIONS_VAR(shell, split); + VSH_EXCLUSIVE_OPTIONS_VAR(xml, split); while ((opt =3D vshCommandOptArgv(ctl, cmd, opt))) { const char *curr =3D opt->data; @@ -3169,6 +3176,14 @@ cmdEcho(vshControl *ctl, const vshCmd *cmd) virBufferEscapeString(&buf, "%s", curr); } else if (shell) { virBufferEscapeShell(&buf, curr); + } else if (split) { + g_auto(GStrv) spl =3D NULL; + GStrv n; + + vshStringToArray(curr, &spl); + + for (n =3D spl; *n; n++) + virBufferAsprintf(&buf, "%s\n", *n); } else { virBufferAdd(&buf, curr, -1); } --=20 2.31.1