From nobody Mon Feb 9 09:46:39 2026 Delivered-To: importer@patchew.org Received-SPF: none (zohomail.com: 8.43.85.245 is neither permitted nor denied by domain of lists.libvirt.org) client-ip=8.43.85.245; envelope-from=devel-bounces@lists.libvirt.org; helo=lists.libvirt.org; Authentication-Results: mx.zohomail.com; spf=none (zohomail.com: 8.43.85.245 is neither permitted nor denied by domain of lists.libvirt.org) smtp.mailfrom=devel-bounces@lists.libvirt.org; dmarc=fail(p=none dis=none) header.from=redhat.com Return-Path: Received: from lists.libvirt.org (lists.libvirt.org [8.43.85.245]) by mx.zohomail.com with SMTPS id 1710160760263862.2422957425042; Mon, 11 Mar 2024 05:39:20 -0700 (PDT) Received: by lists.libvirt.org (Postfix, from userid 996) id E677317F6; Mon, 11 Mar 2024 08:39:18 -0400 (EDT) Received: from lists.libvirt.org (localhost [IPv6:::1]) by lists.libvirt.org (Postfix) with ESMTP id 1E74A1F60; Mon, 11 Mar 2024 07:36:48 -0400 (EDT) Received: by lists.libvirt.org (Postfix, from userid 996) id AA3D31EAB; Mon, 11 Mar 2024 07:32:45 -0400 (EDT) Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.133.124]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by lists.libvirt.org (Postfix) with ESMTPS id C4A801E08 for ; Mon, 11 Mar 2024 07:31:26 -0400 (EDT) Received: from mimecast-mx02.redhat.com (mx-ext.redhat.com [66.187.233.73]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-104-U_fn7VDXOGO83n3MpxrKDQ-1; Mon, 11 Mar 2024 07:31:24 -0400 Received: from smtp.corp.redhat.com (int-mx03.intmail.prod.int.rdu2.redhat.com [10.11.54.3]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id 9117E1C0512C for ; Mon, 11 Mar 2024 11:31:24 +0000 (UTC) Received: from speedmetal.lan (unknown [10.45.242.5]) by smtp.corp.redhat.com (Postfix) with ESMTP id 147D91121306 for ; Mon, 11 Mar 2024 11:31:23 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.4.4 (2020-01-24) on lists.libvirt.org X-Spam-Level: X-Spam-Status: No, score=-0.8 required=5.0 tests=HEADER_FROM_DIFFERENT_DOMAINS, MAILING_LIST_MULTI,RCVD_IN_DNSWL_NONE,RCVD_IN_MSPIKE_H4, RCVD_IN_MSPIKE_WL,SPF_HELO_NONE,T_SCC_BODY_TEXT_LINE autolearn=unavailable autolearn_force=no version=3.4.4 X-MC-Unique: U_fn7VDXOGO83n3MpxrKDQ-1 From: Peter Krempa To: devel@lists.libvirt.org Subject: [PATCH 23/23] vsh: Automatically calculate VSH_OFLAG_REQ_OPT Date: Mon, 11 Mar 2024 12:31:00 +0100 Message-ID: <7c2439f21b99e6c0d23b8545f1c89a5c33ad743f.1710156504.git.pkrempa@redhat.com> In-Reply-To: References: MIME-Version: 1.0 X-Scanned-By: MIMEDefang 3.4.1 on 10.11.54.3 X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Message-ID-Hash: U36D4ZJGZCQXTYJBLUJR5MBRIEVH3K77 X-Message-ID-Hash: U36D4ZJGZCQXTYJBLUJR5MBRIEVH3K77 X-MailFrom: pkrempa@redhat.com X-Mailman-Rule-Misses: dmarc-mitigation; no-senders; approved; emergency; loop; banned-address; member-moderation; header-match-config-1; header-match-config-2; header-match-config-3; header-match-devel.lists.libvirt.org-0; nonmember-moderation; administrivia; implicit-dest; max-recipients; max-size; news-moderation; no-subject; suspicious-header X-Mailman-Version: 3.2.2 Precedence: list List-Id: Development discussions about the libvirt library & tools Archived-At: List-Archive: List-Help: List-Post: List-Subscribe: List-Unsubscribe: Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable X-ZM-MESSAGEID: 1710160760579100001 The command line parser automatically requires the option name for any optional arguments, but for required non-positional ones special handling needs to be done. This patch makes the VSH_OFLAG_REQ_OPT flag completely redundant as it can be calculated. Signed-off-by: Peter Krempa --- tools/virsh-backup.c | 1 - tools/virsh-checkpoint.c | 1 - tools/virsh-domain-monitor.c | 1 - tools/virsh-domain.c | 16 +--------------- tools/virsh-host.c | 2 -- tools/virsh-interface.c | 1 - tools/virsh-network.c | 2 -- tools/virsh-nodedev.c | 1 - tools/virsh-nwfilter.c | 2 -- tools/virsh-pool.c | 1 - tools/virsh-secret.c | 2 -- tools/virsh-snapshot.c | 2 -- tools/virsh-volume.c | 1 - tools/virt-admin.c | 1 - tools/vsh.c | 6 +++++- tools/vsh.h | 1 - 16 files changed, 6 insertions(+), 35 deletions(-) diff --git a/tools/virsh-backup.c b/tools/virsh-backup.c index 7a7834d7ff..f8b11355a1 100644 --- a/tools/virsh-backup.c +++ b/tools/virsh-backup.c @@ -107,7 +107,6 @@ static const vshCmdOptDef opts_backup_dumpxml[] =3D { VIRSH_COMMON_OPT_DOMAIN_FULL(VIR_CONNECT_LIST_DOMAINS_ACTIVE), {.name =3D "xpath", .type =3D VSH_OT_STRING, - .flags =3D VSH_OFLAG_REQ_OPT, .completer =3D virshCompleteEmpty, .help =3D N_("xpath expression to filter the XML document") }, diff --git a/tools/virsh-checkpoint.c b/tools/virsh-checkpoint.c index 869c071700..ef086fd1a5 100644 --- a/tools/virsh-checkpoint.c +++ b/tools/virsh-checkpoint.c @@ -826,7 +826,6 @@ static const vshCmdOptDef opts_checkpoint_dumpxml[] =3D= { }, {.name =3D "xpath", .type =3D VSH_OT_STRING, - .flags =3D VSH_OFLAG_REQ_OPT, .completer =3D virshCompleteEmpty, .help =3D N_("xpath expression to filter the XML document") }, diff --git a/tools/virsh-domain-monitor.c b/tools/virsh-domain-monitor.c index 6c2499fb9f..ff2872d497 100644 --- a/tools/virsh-domain-monitor.c +++ b/tools/virsh-domain-monitor.c @@ -277,7 +277,6 @@ static const vshCmdOptDef opts_dommemstat[] =3D { VIRSH_COMMON_OPT_DOMAIN_FULL(VIR_CONNECT_LIST_DOMAINS_ACTIVE), {.name =3D "period", .type =3D VSH_OT_INT, - .flags =3D VSH_OFLAG_REQ_OPT, .help =3D N_("period in seconds to set collection") }, VIRSH_COMMON_OPT_CONFIG(N_("affect next boot")), diff --git a/tools/virsh-domain.c b/tools/virsh-domain.c index 7c2613c85b..65c67ff038 100644 --- a/tools/virsh-domain.c +++ b/tools/virsh-domain.c @@ -3436,7 +3436,6 @@ static const vshCmdOptDef opts_dom_pm_suspend[] =3D { }, {.name =3D "duration", .type =3D VSH_OT_INT, - .flags =3D VSH_OFLAG_REQ_OPT, .help =3D N_("duration in seconds") }, {.name =3D NULL} @@ -4471,7 +4470,6 @@ static const vshCmdOptDef opts_save_image_dumpxml[] = =3D { }, {.name =3D "xpath", .type =3D VSH_OT_STRING, - .flags =3D VSH_OFLAG_REQ_OPT, .completer =3D virshCompleteEmpty, .help =3D N_("xpath expression to filter the XML document") }, @@ -4877,7 +4875,6 @@ static const vshCmdOptDef opts_managed_save_dumpxml[]= =3D { }, {.name =3D "xpath", .type =3D VSH_OT_STRING, - .flags =3D VSH_OFLAG_REQ_OPT, .completer =3D virshCompleteEmpty, .help =3D N_("xpath expression to filter the XML document") }, @@ -4987,12 +4984,10 @@ static const vshCmdOptDef opts_schedinfo[] =3D { VIRSH_COMMON_OPT_DOMAIN_FULL(0), {.name =3D "weight", .type =3D VSH_OT_INT, - .flags =3D VSH_OFLAG_REQ_OPT, .help =3D N_("weight for XEN_CREDIT") }, {.name =3D "cap", .type =3D VSH_OT_INT, - .flags =3D VSH_OFLAG_REQ_OPT, .help =3D N_("cap for XEN_CREDIT") }, VIRSH_COMMON_OPT_CURRENT(N_("get/set current scheduler info")), @@ -8500,13 +8495,11 @@ static const vshCmdOptDef opts_send_key[] =3D { VIRSH_COMMON_OPT_DOMAIN_FULL(VIR_CONNECT_LIST_DOMAINS_ACTIVE), {.name =3D "codeset", .type =3D VSH_OT_STRING, - .flags =3D VSH_OFLAG_REQ_OPT, .completer =3D virshCodesetNameCompleter, .help =3D N_("the codeset of keycodes, default:linux") }, {.name =3D "holdtime", .type =3D VSH_OT_INT, - .flags =3D VSH_OFLAG_REQ_OPT, .help =3D N_("the time (in milliseconds) how long the keys will be he= ld") }, {.name =3D "keycode", @@ -9436,12 +9429,10 @@ static const vshCmdOptDef opts_domsetlaunchsecstate= [] =3D { VIRSH_COMMON_OPT_DOMAIN_FULL(0), {.name =3D "secrethdr", .type =3D VSH_OT_STRING, - .flags =3D VSH_OFLAG_REQ_OPT, .help =3D N_("path to file containing the secret header"), }, {.name =3D "secret", .type =3D VSH_OT_STRING, - .flags =3D VSH_OFLAG_REQ_OPT, .help =3D N_("path to file containing the secret"), }, {.name =3D "set-address", @@ -9613,7 +9604,6 @@ static const vshCmdOptDef opts_qemu_monitor_command[]= =3D { }, {.name =3D "pass-fds", .type =3D VSH_OT_STRING, - .flags =3D VSH_OFLAG_REQ_OPT, .completer =3D virshCompleteEmpty, .help =3D N_("pass file descriptors N,M,... along with the command") }, @@ -9995,7 +9985,6 @@ static const vshCmdOptDef opts_qemu_agent_command[] = =3D { VIRSH_COMMON_OPT_DOMAIN_FULL(VIR_CONNECT_LIST_DOMAINS_ACTIVE), {.name =3D "timeout", .type =3D VSH_OT_INT, - .flags =3D VSH_OFLAG_REQ_OPT, .help =3D N_("timeout seconds. must be positive.") }, {.name =3D "async", @@ -10231,7 +10220,6 @@ static const vshCmdOptDef opts_dumpxml[] =3D { }, {.name =3D "xpath", .type =3D VSH_OT_STRING, - .flags =3D VSH_OFLAG_REQ_OPT, .completer =3D virshCompleteEmpty, .help =3D N_("xpath expression to filter the XML document") }, @@ -10341,7 +10329,7 @@ static const vshCmdOptDef opts_domxmltonative[] =3D= { .required =3D true, .help =3D N_("target config data type format") }, - VIRSH_COMMON_OPT_DOMAIN_OT_STRING_FULL(VSH_OFLAG_REQ_OPT, 0), + VIRSH_COMMON_OPT_DOMAIN_OT_STRING_FULL(0, 0), {.name =3D "xml", .type =3D VSH_OT_STRING, .completer =3D virshCompletePathLocalExisting, @@ -11311,7 +11299,6 @@ static const vshCmdOptDef opts_migrate_compcache[] = =3D { VIRSH_COMMON_OPT_DOMAIN_FULL(VIR_CONNECT_LIST_DOMAINS_ACTIVE), {.name =3D "size", .type =3D VSH_OT_INT, - .flags =3D VSH_OFLAG_REQ_OPT, .help =3D N_("requested size of the cache (in bytes) used for compres= sion") }, {.name =3D NULL} @@ -12964,7 +12951,6 @@ static const vshCmdOptDef opts_guest_agent_timeout[= ] =3D { VIRSH_COMMON_OPT_DOMAIN_FULL(0), {.name =3D "timeout", .type =3D VSH_OT_INT, - .flags =3D VSH_OFLAG_REQ_OPT, .help =3D N_("timeout seconds.") }, {.name =3D NULL} diff --git a/tools/virsh-host.c b/tools/virsh-host.c index ffb993de79..94b1879d5f 100644 --- a/tools/virsh-host.c +++ b/tools/virsh-host.c @@ -45,7 +45,6 @@ static const vshCmdInfo info_capabilities =3D { static const vshCmdOptDef opts_capabilities[] =3D { {.name =3D "xpath", .type =3D VSH_OT_STRING, - .flags =3D VSH_OFLAG_REQ_OPT, .completer =3D virshCompleteEmpty, .help =3D N_("xpath expression to filter the XML document") }, @@ -104,7 +103,6 @@ static const vshCmdOptDef opts_domcapabilities[] =3D { }, {.name =3D "xpath", .type =3D VSH_OT_STRING, - .flags =3D VSH_OFLAG_REQ_OPT, .completer =3D virshCompleteEmpty, .help =3D N_("xpath expression to filter the XML document") }, diff --git a/tools/virsh-interface.c b/tools/virsh-interface.c index 1b1344c17c..6f79dc4ba5 100644 --- a/tools/virsh-interface.c +++ b/tools/virsh-interface.c @@ -453,7 +453,6 @@ static const vshCmdOptDef opts_interface_dumpxml[] =3D { }, {.name =3D "xpath", .type =3D VSH_OT_STRING, - .flags =3D VSH_OFLAG_REQ_OPT, .completer =3D virshCompleteEmpty, .help =3D N_("xpath expression to filter the XML document") }, diff --git a/tools/virsh-network.c b/tools/virsh-network.c index 376de46cf4..e38ecff443 100644 --- a/tools/virsh-network.c +++ b/tools/virsh-network.c @@ -665,7 +665,6 @@ static const vshCmdOptDef opts_network_dumpxml[] =3D { }, {.name =3D "xpath", .type =3D VSH_OT_STRING, - .flags =3D VSH_OFLAG_REQ_OPT, .completer =3D virshCompleteEmpty, .help =3D N_("xpath expression to filter the XML document") }, @@ -1891,7 +1890,6 @@ static const vshCmdOptDef opts_network_port_dumpxml[]= =3D { VIRSH_COMMON_OPT_NETWORK_PORT(0), {.name =3D "xpath", .type =3D VSH_OT_STRING, - .flags =3D VSH_OFLAG_REQ_OPT, .completer =3D virshCompleteEmpty, .help =3D N_("xpath expression to filter the XML document") }, diff --git a/tools/virsh-nodedev.c b/tools/virsh-nodedev.c index 90cfc187e5..23b1d45c92 100644 --- a/tools/virsh-nodedev.c +++ b/tools/virsh-nodedev.c @@ -583,7 +583,6 @@ static const vshCmdOptDef opts_node_device_dumpxml[] = =3D { }, {.name =3D "xpath", .type =3D VSH_OT_STRING, - .flags =3D VSH_OFLAG_REQ_OPT, .completer =3D virshCompleteEmpty, .help =3D N_("xpath expression to filter the XML document") }, diff --git a/tools/virsh-nwfilter.c b/tools/virsh-nwfilter.c index f54d2a0ae5..69473b4935 100644 --- a/tools/virsh-nwfilter.c +++ b/tools/virsh-nwfilter.c @@ -175,7 +175,6 @@ static const vshCmdOptDef opts_nwfilter_dumpxml[] =3D { }, {.name =3D "xpath", .type =3D VSH_OT_STRING, - .flags =3D VSH_OFLAG_REQ_OPT, .completer =3D virshCompleteEmpty, .help =3D N_("xpath expression to filter the XML document") }, @@ -577,7 +576,6 @@ static const vshCmdOptDef opts_nwfilter_binding_dumpxml= [] =3D { }, {.name =3D "xpath", .type =3D VSH_OT_STRING, - .flags =3D VSH_OFLAG_REQ_OPT, .completer =3D virshCompleteEmpty, .help =3D N_("xpath expression to filter the XML document") }, diff --git a/tools/virsh-pool.c b/tools/virsh-pool.c index 67cc1b94cf..7bbdd7d661 100644 --- a/tools/virsh-pool.c +++ b/tools/virsh-pool.c @@ -729,7 +729,6 @@ static const vshCmdOptDef opts_pool_dumpxml[] =3D { }, {.name =3D "xpath", .type =3D VSH_OT_STRING, - .flags =3D VSH_OFLAG_REQ_OPT, .completer =3D virshCompleteEmpty, .help =3D N_("xpath expression to filter the XML document") }, diff --git a/tools/virsh-secret.c b/tools/virsh-secret.c index 7e10afa765..f99e17f2e8 100644 --- a/tools/virsh-secret.c +++ b/tools/virsh-secret.c @@ -131,7 +131,6 @@ static const vshCmdOptDef opts_secret_dumpxml[] =3D { }, {.name =3D "xpath", .type =3D VSH_OT_STRING, - .flags =3D VSH_OFLAG_REQ_OPT, .completer =3D virshCompleteEmpty, .help =3D N_("xpath expression to filter the XML document") }, @@ -187,7 +186,6 @@ static const vshCmdOptDef opts_secret_set_value[] =3D { }, {.name =3D "file", .type =3D VSH_OT_STRING, - .flags =3D VSH_OFLAG_REQ_OPT, .completer =3D virshCompletePathLocalExisting, .help =3D N_("read secret from file"), }, diff --git a/tools/virsh-snapshot.c b/tools/virsh-snapshot.c index 899bae7e9a..80a8c9e754 100644 --- a/tools/virsh-snapshot.c +++ b/tools/virsh-snapshot.c @@ -356,7 +356,6 @@ static const vshCmdOptDef opts_snapshot_create_as[] =3D= { }, {.name =3D "memspec", .type =3D VSH_OT_STRING, - .flags =3D VSH_OFLAG_REQ_OPT, .help =3D N_("memory attributes: [file=3D]name[,snapshot=3Dtype]") }, {.name =3D "diskspec", @@ -1579,7 +1578,6 @@ static const vshCmdOptDef opts_snapshot_dumpxml[] =3D= { }, {.name =3D "xpath", .type =3D VSH_OT_STRING, - .flags =3D VSH_OFLAG_REQ_OPT, .completer =3D virshCompleteEmpty, .help =3D N_("xpath expression to filter the XML document") }, diff --git a/tools/virsh-volume.c b/tools/virsh-volume.c index 8794126f21..104a4a081c 100644 --- a/tools/virsh-volume.c +++ b/tools/virsh-volume.c @@ -1119,7 +1119,6 @@ static const vshCmdOptDef opts_vol_dumpxml[] =3D { VIRSH_COMMON_OPT_POOL_OPTIONAL, {.name =3D "xpath", .type =3D VSH_OT_STRING, - .flags =3D VSH_OFLAG_REQ_OPT, .completer =3D virshCompleteEmpty, .help =3D N_("xpath expression to filter the XML document") }, diff --git a/tools/virt-admin.c b/tools/virt-admin.c index 37bc6fe4f0..c3b3cc8ccd 100644 --- a/tools/virt-admin.c +++ b/tools/virt-admin.c @@ -1003,7 +1003,6 @@ static const vshCmdOptDef opts_daemon_timeout[] =3D { .type =3D VSH_OT_INT, .required =3D true, .help =3D N_("number of seconds the daemon will run without any activ= e connection"), - .flags =3D VSH_OFLAG_REQ_OPT }, {.name =3D NULL} }; diff --git a/tools/vsh.c b/tools/vsh.c index 85296c35c7..c88c13fbe0 100644 --- a/tools/vsh.c +++ b/tools/vsh.c @@ -442,7 +442,11 @@ vshCmddefOptParse(const vshCmdDef *cmd, if (opt->type =3D=3D VSH_OT_ALIAS) continue; /* skip the alias option */ - if (!(opt->flags & VSH_OFLAG_REQ_OPT)) + /* The command line parser requires the argument name for optional= or + * non-positional arguments automatically, but if we need to do it + * explicitly for required non-positional arguments. + * This bitmap needs to be set on te negation of the above */ + if (!(opt->required && !opt->positional)) *opts_need_arg |=3D 1ULL << i; if (opt->required) diff --git a/tools/vsh.h b/tools/vsh.h index 5f3e610dd7..4b7fea8ba0 100644 --- a/tools/vsh.h +++ b/tools/vsh.h @@ -99,7 +99,6 @@ typedef enum { enum { VSH_OFLAG_NONE =3D 0, /* without flags */ VSH_OFLAG_EMPTY_OK =3D (1 << 1), /* empty string option allowed */ - VSH_OFLAG_REQ_OPT =3D (1 << 2), /* --optionname required */ }; /* forward declarations */ --=20 2.44.0 _______________________________________________ Devel mailing list -- devel@lists.libvirt.org To unsubscribe send an email to devel-leave@lists.libvirt.org