From nobody Mon Feb 9 21:21:31 2026 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of redhat.com designates 63.128.21.124 as permitted sender) client-ip=63.128.21.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 63.128.21.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=1612448062; cv=none; d=zohomail.com; s=zohoarc; b=gJ3Rwv/bJ7hyTxlZT4cVhK0g5NamYMgxlAsWKMCzjIT1ZBCLMgqxwtPSMR8wFVwT5dI67vPfBGV7J6WUe/HgUk1PVh8nz1XsMuSS/GSZin+QgKVMgL9FDVTKyrJR408PbvhtixuNUGP15e+WEuZS+r8OE460hHnK2oNohP5jOpU= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1612448062; 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=kg3g3PHPEdZekhhaaZOH1MGQ2meaB2o8CpZ+QKj8wjE=; b=Gp8lmUmaiukExZ2/e06pqMIolIIfrhHu6AFJJTej+32TW860Y08K1H1WPPOCXCkvXDh/1/phy/CsAaUSfhc+AjG+xX7Rdo9RQ2Mmt5/AAqm535ld0F+8oaK7YjqfSBcybOVw+yZxW3CPPC6F3FH+TRnOMdAFNpQmgHBpgF/eM2Y= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of redhat.com designates 63.128.21.124 as permitted sender) smtp.mailfrom=libvir-list-bounces@redhat.com; dmarc=pass header.from= (p=none dis=none) header.from= Return-Path: Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [63.128.21.124]) by mx.zohomail.com with SMTPS id 1612448062615488.38895668859004; Thu, 4 Feb 2021 06:14:22 -0800 (PST) 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-216-zyPfTVFbNJOAaU2L-0juAg-1; Thu, 04 Feb 2021 09:14:18 -0500 Received: from smtp.corp.redhat.com (int-mx01.intmail.prod.int.phx2.redhat.com [10.5.11.11]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id 654ACC7408; Thu, 4 Feb 2021 14:14:12 +0000 (UTC) Received: from colo-mx.corp.redhat.com (colo-mx02.intmail.prod.int.phx2.redhat.com [10.5.11.21]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 418FC722E1; Thu, 4 Feb 2021 14:14:12 +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 0727B58080; Thu, 4 Feb 2021 14:14:12 +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 114EDv7I031656 for ; Thu, 4 Feb 2021 09:13:57 -0500 Received: by smtp.corp.redhat.com (Postfix) id 0DF1C5D9EF; Thu, 4 Feb 2021 14:13:57 +0000 (UTC) Received: from localhost.localdomain (unknown [10.40.193.72]) by smtp.corp.redhat.com (Postfix) with ESMTP id 838BF5D9C9 for ; Thu, 4 Feb 2021 14:13:56 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1612448061; 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=kg3g3PHPEdZekhhaaZOH1MGQ2meaB2o8CpZ+QKj8wjE=; b=dtdeRAJcR1gtS+bmw4UI/3kJxTM9z+gtQM9X8x3VUV4YkKG6d2u4u0LLZ7SPLkBYCi5drY W+oByjsfvqcJ8PST23WjcbRwGRvehzdS6tbK79EDzjMTUds35XTKHkYr4OmHYJUTucaMXc rmXnZdaTSqxiD60K3dtKKMAXHDQw4g0= X-MC-Unique: zyPfTVFbNJOAaU2L-0juAg-1 From: Michal Privoznik To: libvir-list@redhat.com Subject: [PATCH 10/12] vsh: Simplify condition for calling completer callback Date: Thu, 4 Feb 2021 15:13:35 +0100 Message-Id: <7882e140ad65e86cea43a3cfd5d510e56d31e9c6.1612447905.git.mprivozn@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.11 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) Content-Type: text/plain; charset="utf-8" The way we currently call completer callbacks is that if we've found --option that user wants to complete value for and it has callback set then the callback is called. And just before that, if no --option to have the value completed is found or is found and is of boolean type then a list of --option is generated (for given command). But these two conditions can never be true at the same time because boolean type of --options do not accept values. Therefore the calling of completer callback can be promoted onto the same level as the --option list generation. This means that merging of two lists can be dropped to and completer callback can store its retval directly into @list (but as shown earlier one of the string lists to merge is always empty). Signed-off-by: Michal Privoznik --- tools/vsh.c | 44 +++++++++++++++++++------------------------- 1 file changed, 19 insertions(+), 25 deletions(-) diff --git a/tools/vsh.c b/tools/vsh.c index e0dbda04c8..0d3c4fd7c7 100644 --- a/tools/vsh.c +++ b/tools/vsh.c @@ -2750,34 +2750,28 @@ vshReadlineParse(const char *text, int state) =20 if (!cmd) { list =3D vshReadlineCommandGenerator(text); - } else { - if (!opt || opt->type =3D=3D VSH_OT_BOOL) - list =3D vshReadlineOptionsGenerator(text, cmd, partial); + } else if (!opt || opt->type =3D=3D VSH_OT_BOOL) { + list =3D vshReadlineOptionsGenerator(text, cmd, partial); + } else if (opt && opt->completer) { + list =3D opt->completer(autoCompleteOpaque, + partial, + opt->completer_flags); + } =20 - if (opt && opt->completer) { - g_auto(GStrv) completer_list =3D opt->completer(autoComple= teOpaque, - partial, - opt->complet= er_flags); + /* Escape completions, if needed (i.e. argument + * we are completing wasn't started with a quote + * character). This also enables filtering done + * below to work properly. */ + if (list && + !rl_completion_quote_character) { + size_t i; =20 - /* Escape completions, if needed (i.e. argument - * we are completing wasn't started with a quote - * character). This also enables filtering done - * below to work properly. */ - if (completer_list && - !rl_completion_quote_character) { - size_t i; + for (i =3D 0; list[i]; i++) { + g_auto(virBuffer) buf =3D VIR_BUFFER_INITIALIZER; =20 - for (i =3D 0; completer_list[i]; i++) { - g_auto(virBuffer) buf =3D VIR_BUFFER_INITIALIZER; - - virBufferEscape(&buf, '\\', " ", "%s", completer_l= ist[i]); - VIR_FREE(completer_list[i]); - completer_list[i] =3D virBufferContentAndReset(&bu= f); - } - } - - if (virStringListMerge(&list, &completer_list) < 0) - goto cleanup; + virBufferEscape(&buf, '\\', " ", "%s", list[i]); + VIR_FREE(list[i]); + list[i] =3D virBufferContentAndReset(&buf); } } =20 --=20 2.26.2