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 <pkrempa(a)redhat.com>
---
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[] = {
VIRSH_COMMON_OPT_DOMAIN_FULL(VIR_CONNECT_LIST_DOMAINS_ACTIVE),
{.name = "xpath",
.type = VSH_OT_STRING,
- .flags = VSH_OFLAG_REQ_OPT,
.completer = virshCompleteEmpty,
.help = 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[] = {
},
{.name = "xpath",
.type = VSH_OT_STRING,
- .flags = VSH_OFLAG_REQ_OPT,
.completer = virshCompleteEmpty,
.help = 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[] = {
VIRSH_COMMON_OPT_DOMAIN_FULL(VIR_CONNECT_LIST_DOMAINS_ACTIVE),
{.name = "period",
.type = VSH_OT_INT,
- .flags = VSH_OFLAG_REQ_OPT,
.help = 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[] = {
},
{.name = "duration",
.type = VSH_OT_INT,
- .flags = VSH_OFLAG_REQ_OPT,
.help = N_("duration in seconds")
},
{.name = NULL}
@@ -4471,7 +4470,6 @@ static const vshCmdOptDef opts_save_image_dumpxml[] = {
},
{.name = "xpath",
.type = VSH_OT_STRING,
- .flags = VSH_OFLAG_REQ_OPT,
.completer = virshCompleteEmpty,
.help = N_("xpath expression to filter the XML document")
},
@@ -4877,7 +4875,6 @@ static const vshCmdOptDef opts_managed_save_dumpxml[] = {
},
{.name = "xpath",
.type = VSH_OT_STRING,
- .flags = VSH_OFLAG_REQ_OPT,
.completer = virshCompleteEmpty,
.help = N_("xpath expression to filter the XML document")
},
@@ -4987,12 +4984,10 @@ static const vshCmdOptDef opts_schedinfo[] = {
VIRSH_COMMON_OPT_DOMAIN_FULL(0),
{.name = "weight",
.type = VSH_OT_INT,
- .flags = VSH_OFLAG_REQ_OPT,
.help = N_("weight for XEN_CREDIT")
},
{.name = "cap",
.type = VSH_OT_INT,
- .flags = VSH_OFLAG_REQ_OPT,
.help = 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[] = {
VIRSH_COMMON_OPT_DOMAIN_FULL(VIR_CONNECT_LIST_DOMAINS_ACTIVE),
{.name = "codeset",
.type = VSH_OT_STRING,
- .flags = VSH_OFLAG_REQ_OPT,
.completer = virshCodesetNameCompleter,
.help = N_("the codeset of keycodes, default:linux")
},
{.name = "holdtime",
.type = VSH_OT_INT,
- .flags = VSH_OFLAG_REQ_OPT,
.help = N_("the time (in milliseconds) how long the keys will be held")
},
{.name = "keycode",
@@ -9436,12 +9429,10 @@ static const vshCmdOptDef opts_domsetlaunchsecstate[] = {
VIRSH_COMMON_OPT_DOMAIN_FULL(0),
{.name = "secrethdr",
.type = VSH_OT_STRING,
- .flags = VSH_OFLAG_REQ_OPT,
.help = N_("path to file containing the secret header"),
},
{.name = "secret",
.type = VSH_OT_STRING,
- .flags = VSH_OFLAG_REQ_OPT,
.help = N_("path to file containing the secret"),
},
{.name = "set-address",
@@ -9613,7 +9604,6 @@ static const vshCmdOptDef opts_qemu_monitor_command[] = {
},
{.name = "pass-fds",
.type = VSH_OT_STRING,
- .flags = VSH_OFLAG_REQ_OPT,
.completer = virshCompleteEmpty,
.help = N_("pass file descriptors N,M,... along with the command")
},
@@ -9995,7 +9985,6 @@ static const vshCmdOptDef opts_qemu_agent_command[] = {
VIRSH_COMMON_OPT_DOMAIN_FULL(VIR_CONNECT_LIST_DOMAINS_ACTIVE),
{.name = "timeout",
.type = VSH_OT_INT,
- .flags = VSH_OFLAG_REQ_OPT,
.help = N_("timeout seconds. must be positive.")
},
{.name = "async",
@@ -10231,7 +10220,6 @@ static const vshCmdOptDef opts_dumpxml[] = {
},
{.name = "xpath",
.type = VSH_OT_STRING,
- .flags = VSH_OFLAG_REQ_OPT,
.completer = virshCompleteEmpty,
.help = N_("xpath expression to filter the XML document")
},
@@ -10341,7 +10329,7 @@ static const vshCmdOptDef opts_domxmltonative[] = {
.required = true,
.help = 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 = "xml",
.type = VSH_OT_STRING,
.completer = virshCompletePathLocalExisting,
@@ -11311,7 +11299,6 @@ static const vshCmdOptDef opts_migrate_compcache[] = {
VIRSH_COMMON_OPT_DOMAIN_FULL(VIR_CONNECT_LIST_DOMAINS_ACTIVE),
{.name = "size",
.type = VSH_OT_INT,
- .flags = VSH_OFLAG_REQ_OPT,
.help = N_("requested size of the cache (in bytes) used for compression")
},
{.name = NULL}
@@ -12964,7 +12951,6 @@ static const vshCmdOptDef opts_guest_agent_timeout[] = {
VIRSH_COMMON_OPT_DOMAIN_FULL(0),
{.name = "timeout",
.type = VSH_OT_INT,
- .flags = VSH_OFLAG_REQ_OPT,
.help = N_("timeout seconds.")
},
{.name = 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 = {
static const vshCmdOptDef opts_capabilities[] = {
{.name = "xpath",
.type = VSH_OT_STRING,
- .flags = VSH_OFLAG_REQ_OPT,
.completer = virshCompleteEmpty,
.help = N_("xpath expression to filter the XML document")
},
@@ -104,7 +103,6 @@ static const vshCmdOptDef opts_domcapabilities[] = {
},
{.name = "xpath",
.type = VSH_OT_STRING,
- .flags = VSH_OFLAG_REQ_OPT,
.completer = virshCompleteEmpty,
.help = 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[] = {
},
{.name = "xpath",
.type = VSH_OT_STRING,
- .flags = VSH_OFLAG_REQ_OPT,
.completer = virshCompleteEmpty,
.help = 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[] = {
},
{.name = "xpath",
.type = VSH_OT_STRING,
- .flags = VSH_OFLAG_REQ_OPT,
.completer = virshCompleteEmpty,
.help = N_("xpath expression to filter the XML document")
},
@@ -1891,7 +1890,6 @@ static const vshCmdOptDef opts_network_port_dumpxml[] = {
VIRSH_COMMON_OPT_NETWORK_PORT(0),
{.name = "xpath",
.type = VSH_OT_STRING,
- .flags = VSH_OFLAG_REQ_OPT,
.completer = virshCompleteEmpty,
.help = 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[] = {
},
{.name = "xpath",
.type = VSH_OT_STRING,
- .flags = VSH_OFLAG_REQ_OPT,
.completer = virshCompleteEmpty,
.help = 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[] = {
},
{.name = "xpath",
.type = VSH_OT_STRING,
- .flags = VSH_OFLAG_REQ_OPT,
.completer = virshCompleteEmpty,
.help = N_("xpath expression to filter the XML document")
},
@@ -577,7 +576,6 @@ static const vshCmdOptDef opts_nwfilter_binding_dumpxml[] = {
},
{.name = "xpath",
.type = VSH_OT_STRING,
- .flags = VSH_OFLAG_REQ_OPT,
.completer = virshCompleteEmpty,
.help = 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[] = {
},
{.name = "xpath",
.type = VSH_OT_STRING,
- .flags = VSH_OFLAG_REQ_OPT,
.completer = virshCompleteEmpty,
.help = 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[] = {
},
{.name = "xpath",
.type = VSH_OT_STRING,
- .flags = VSH_OFLAG_REQ_OPT,
.completer = virshCompleteEmpty,
.help = N_("xpath expression to filter the XML document")
},
@@ -187,7 +186,6 @@ static const vshCmdOptDef opts_secret_set_value[] = {
},
{.name = "file",
.type = VSH_OT_STRING,
- .flags = VSH_OFLAG_REQ_OPT,
.completer = virshCompletePathLocalExisting,
.help = 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[] = {
},
{.name = "memspec",
.type = VSH_OT_STRING,
- .flags = VSH_OFLAG_REQ_OPT,
.help = N_("memory attributes: [file=]name[,snapshot=type]")
},
{.name = "diskspec",
@@ -1579,7 +1578,6 @@ static const vshCmdOptDef opts_snapshot_dumpxml[] = {
},
{.name = "xpath",
.type = VSH_OT_STRING,
- .flags = VSH_OFLAG_REQ_OPT,
.completer = virshCompleteEmpty,
.help = 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[] = {
VIRSH_COMMON_OPT_POOL_OPTIONAL,
{.name = "xpath",
.type = VSH_OT_STRING,
- .flags = VSH_OFLAG_REQ_OPT,
.completer = virshCompleteEmpty,
.help = 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[] = {
.type = VSH_OT_INT,
.required = true,
.help = N_("number of seconds the daemon will run without any active
connection"),
- .flags = VSH_OFLAG_REQ_OPT
},
{.name = 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 == 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 |= 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 = 0, /* without flags */
VSH_OFLAG_EMPTY_OK = (1 << 1), /* empty string option allowed */
- VSH_OFLAG_REQ_OPT = (1 << 2), /* --optionname required */
};
/* forward declarations */
--
2.44.0