From nobody Mon Feb 9 12:09:55 2026 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of redhat.com designates 170.10.133.124 as permitted sender) client-ip=170.10.133.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 170.10.133.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=1647328111; cv=none; d=zohomail.com; s=zohoarc; b=e6dnYvOvpqQdqBjQnv0urkeU9W9z+txAeNXqc1jRAcgJhUFrGG1VOOgfdR+e28q2W676QRU9I8Nn/ZI8/y5g73hed8RGMHB63CtwbzILXdmVgadIzTMg/Ik8efw4huz0VOd7SaclPax4JhkdnTGHY9QKtGCnXt+VFHiI3mtCMgw= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1647328111; 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=1izYe2Rp1RzCv7KECB7Zb/L96+Sh7VA7YEwbkBKJ3IA=; b=Vyr2s3no6rriwkoB5KTx4s0oyd/QeFEFXP6728OqNYou4TnJtFc09qXpJ5vRc6ooy09aZADAGuD8EwpSRFfZgCGyKMcpang0I6XpzHhQLclU64Y0XM7BABPy6WOBDAvB/6EDUL8nZ9Y8t2gEoJVadJoMmPsQmhzB4Vm0n+ncsGU= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of redhat.com designates 170.10.133.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 [170.10.133.124]) by mx.zohomail.com with SMTPS id 1647328111901698.3446954103186; Tue, 15 Mar 2022 00:08:31 -0700 (PDT) Received: from mimecast-mx02.redhat.com (mimecast-mx02.redhat.com [66.187.233.88]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id us-mta-656-68pttEVsP-iNunaqB3cAYQ-1; Tue, 15 Mar 2022 03:08:27 -0400 Received: from smtp.corp.redhat.com (int-mx08.intmail.prod.int.rdu2.redhat.com [10.11.54.8]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id 02482803D7A; Tue, 15 Mar 2022 07:08:25 +0000 (UTC) Received: from mm-prod-listman-01.mail-001.prod.us-east-1.aws.redhat.com (mm-prod-listman-01.mail-001.prod.us-east-1.aws.redhat.com [10.30.29.100]) by smtp.corp.redhat.com (Postfix) with ESMTP id E0431C28102; Tue, 15 Mar 2022 07:08:24 +0000 (UTC) Received: from mm-prod-listman-01.mail-001.prod.us-east-1.aws.redhat.com (localhost [IPv6:::1]) by mm-prod-listman-01.mail-001.prod.us-east-1.aws.redhat.com (Postfix) with ESMTP id B8D94193211C; Tue, 15 Mar 2022 07:08:21 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx02.intmail.prod.int.rdu2.redhat.com [10.11.54.2]) by mm-prod-listman-01.mail-001.prod.us-east-1.aws.redhat.com (Postfix) with ESMTP id CA8CA194E021 for ; Tue, 15 Mar 2022 07:08:20 +0000 (UTC) Received: by smtp.corp.redhat.com (Postfix) id BACA74010A05; Tue, 15 Mar 2022 07:08:20 +0000 (UTC) Received: from localhost.localdomain (unknown [10.40.193.11]) by smtp.corp.redhat.com (Postfix) with ESMTP id 5B04940E80E2 for ; Tue, 15 Mar 2022 07:08:20 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1647328110; 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=1izYe2Rp1RzCv7KECB7Zb/L96+Sh7VA7YEwbkBKJ3IA=; b=Q39Uq2GgeRXFULvK20boFwDphUzyacoWGlIzBNQNph+yq5k1ZDnV4hhRVi1M9kvnbqFntu wAeqwadOMhrC66TAyJ25w4cEn+W7FU92fIWP3ys7h5QmS+fj07q6IlloZbRiqGI742KoOr nLMrRaadNpltyd+MeXQMRRPAlWuvct0= X-MC-Unique: 68pttEVsP-iNunaqB3cAYQ-1 X-Original-To: libvir-list@listman.corp.redhat.com From: Michal Privoznik To: libvir-list@redhat.com Subject: [PATCH 2/3] virsh: Introduce virshEnumComplete() Date: Tue, 15 Mar 2022 08:08:16 +0100 Message-Id: <0915d7ec09d8b3dc57bc8a6e4eb886adb698cb12.1647328065.git.mprivozn@redhat.com> In-Reply-To: References: MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.84 on 10.11.54.2 X-BeenThere: libvir-list@redhat.com X-Mailman-Version: 2.1.29 Precedence: list List-Id: Development discussions about the libvirt library & tools List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: libvir-list-bounces@redhat.com Sender: "libvir-list" X-Scanned-By: MIMEDefang 2.85 on 10.11.54.8 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: 1647328113881100001 Content-Type: text/plain; charset="utf-8" We have plenty of completers which iterate over all values of given enum and do nothing more than translate every member into string (using corresponding virXXXTypeToString()). Introduce a convenience function so that callers can pass just VIR_XXX_LAST and virXXXTypeToString and the rest is taken care of. Signed-off-by: Michal Privoznik --- tools/virsh-completer.c | 27 +++++++++++++++++++++++++++ tools/virsh-completer.h | 4 ++++ 2 files changed, 31 insertions(+) diff --git a/tools/virsh-completer.c b/tools/virsh-completer.c index 3d77be3121..e5610d0fe8 100644 --- a/tools/virsh-completer.c +++ b/tools/virsh-completer.c @@ -57,6 +57,33 @@ */ =20 =20 +/** + * virshEnumComplete: + * @last: The number of element in enum (pass VIR_XXX_LAST) + * @intToStr: integer to string conversion (pass virXXXTypeToString) + * + * Convenient function to generate completions across all values + * of given enum. The enum, or values we want to generate, must + * start at 0 and be continuous until @last. + * + * Returns: string list of completions. + */ +char ** +virshEnumComplete(unsigned int last, + const char *(*intToStr)(int)) +{ + char **ret =3D NULL; + size_t i; + + ret =3D g_new0(char *, last + 1); + + for (i =3D 0; i < last; i++) + ret[i] =3D g_strdup(intToStr(i)); + + return ret; +} + + /** * virshCommaStringListComplete: * @input: user input so far diff --git a/tools/virsh-completer.h b/tools/virsh-completer.h index 1d7affbb23..131678dfbc 100644 --- a/tools/virsh-completer.h +++ b/tools/virsh-completer.h @@ -32,6 +32,10 @@ #include "virsh-completer-snapshot.h" #include "virsh-completer-volume.h" =20 +char ** +virshEnumComplete(unsigned int last, + const char *(*intToStr)(int)); + char ** virshCommaStringListComplete(const char *input, const char **options); --=20 2.34.1