]> git.ipfire.org Git - thirdparty/libvirt.git/commitdiff
virsh: Introduce virshCompleteEmpty and use it for places where we can't suggest...
authorPeter Krempa <pkrempa@redhat.com>
Wed, 15 Sep 2021 15:42:08 +0000 (17:42 +0200)
committerPeter Krempa <pkrempa@redhat.com>
Fri, 17 Sep 2021 07:40:46 +0000 (09:40 +0200)
For now this serves just as an annotation because readline and also the
bash completion script insist on completing local paths when an empty
list is returned.

This will serve for future reference once we'll be able to properly
refuse to suggest anything.

The completer is used for fields such as names for new objects,
description strings, password strings etc, URIs and hostnames which we
can't feasibly autocomplete.

Signed-off-by: Peter Krempa <pkrempa@redhat.com>
Reviewed-by: Michal Privoznik <mprivozn@redhat.com>
tools/virsh-checkpoint.c
tools/virsh-completer.c
tools/virsh-completer.h
tools/virsh-domain.c
tools/virsh-pool.c
tools/virsh-secret.c
tools/virsh-snapshot.c
tools/virsh-volume.c
tools/virsh.c

index 78272b43c4b7cfe42c348c36609699cc514427b1..8ad37ece69c3aa06002b9ffc8a807a9b674ef361 100644 (file)
@@ -200,10 +200,12 @@ static const vshCmdOptDef opts_checkpoint_create_as[] = {
     VIRSH_COMMON_OPT_DOMAIN_FULL(VIR_CONNECT_LIST_DOMAINS_ACTIVE),
     {.name = "name",
      .type = VSH_OT_STRING,
+     .completer = virshCompleteEmpty,
      .help = N_("name of checkpoint")
     },
     {.name = "description",
      .type = VSH_OT_STRING,
+     .completer = virshCompleteEmpty,
      .help = N_("description of checkpoint")
     },
     {.name = "print-xml",
index 100f2065985f240cbfe2a01b35d4e6dda6a9b639..3d77be31219e5cdd84ecee556a3f099272eed698 100644 (file)
@@ -145,3 +145,21 @@ virshCompletePathLocalExisting(vshControl *ctl G_GNUC_UNUSED,
 {
     return NULL;
 }
+
+
+/**
+ * virshCompleteEmpty:
+ *
+ * Complete nothing. For cases where an user input is required and we can't
+ * suggest anything.
+ *
+ * TODO: This is currently just an annotation, readline still completes local
+ * file list.
+ */
+char **
+virshCompleteEmpty(vshControl *ctl G_GNUC_UNUSED,
+                   const vshCmd *cmd G_GNUC_UNUSED,
+                   unsigned int completerflags G_GNUC_UNUSED)
+{
+    return NULL;
+}
index 9a77aa117f4955c47fd4ff687ca2d20542970361..1d7affbb23b350d63220ca628571ea86f9ec2b60 100644 (file)
@@ -40,3 +40,8 @@ char **
 virshCompletePathLocalExisting(vshControl *ctl,
                                const vshCmd *cmd,
                                unsigned int completerflags);
+
+char **
+virshCompleteEmpty(vshControl *ctl,
+                   const vshCmd *cmd,
+                   unsigned int completerflags);
index d23a30949887c6dd739b153dfed2d4cf1b9dfe75..c1e4498f22d3f495ed792a030eb1e1abd1dc91e6 100644 (file)
@@ -395,6 +395,7 @@ static const vshCmdOptDef opts_attach_disk[] = {
     {.name = "target",
      .type = VSH_OT_DATA,
      .flags = VSH_OFLAG_REQ,
+     .completer = virshCompleteEmpty,
      .help = N_("target of disk device")
     },
     {.name = "targetbus",
@@ -440,14 +441,17 @@ static const vshCmdOptDef opts_attach_disk[] = {
     },
     {.name = "serial",
      .type = VSH_OT_STRING,
+     .completer = virshCompleteEmpty,
      .help = N_("serial of disk device")
     },
     {.name = "wwn",
      .type = VSH_OT_STRING,
+     .completer = virshCompleteEmpty,
      .help = N_("wwn of disk device")
     },
     {.name = "alias",
      .type = VSH_OT_STRING,
+     .completer = virshCompleteEmpty,
      .help = N_("custom alias name of disk device")
     },
     {.name = "rawio",
@@ -456,6 +460,7 @@ static const vshCmdOptDef opts_attach_disk[] = {
     },
     {.name = "address",
      .type = VSH_OT_STRING,
+     .completer = virshCompleteEmpty,
      .help = N_("address of disk device")
     },
     {.name = "multifunction",
@@ -472,6 +477,7 @@ static const vshCmdOptDef opts_attach_disk[] = {
     },
     {.name = "source-host-name",
      .type = VSH_OT_STRING,
+     .completer = virshCompleteEmpty,
      .help = N_("host name for source of disk device")
     },
     {.name = "source-host-transport",
@@ -793,10 +799,12 @@ static const vshCmdOptDef opts_attach_interface[] = {
     },
     {.name = "target",
      .type = VSH_OT_STRING,
+     .completer = virshCompleteEmpty,
      .help = N_("target network name")
     },
     {.name = "mac",
      .type = VSH_OT_STRING,
+     .completer = virshCompleteEmpty,
      .help = N_("MAC address")
     },
     {.name = "script",
@@ -809,14 +817,17 @@ static const vshCmdOptDef opts_attach_interface[] = {
     },
     {.name = "alias",
      .type = VSH_OT_STRING,
+     .completer = virshCompleteEmpty,
      .help = N_("custom alias name of interface device")
     },
     {.name = "inbound",
      .type = VSH_OT_STRING,
+     .completer = virshCompleteEmpty,
      .help = N_("control domain's incoming traffics")
     },
     {.name = "outbound",
      .type = VSH_OT_STRING,
+     .completer = virshCompleteEmpty,
      .help = N_("control domain's outgoing traffics")
     },
     VIRSH_COMMON_OPT_DOMAIN_PERSISTENT,
@@ -1277,6 +1288,7 @@ static const vshCmdOptDef opts_blkdeviotune[] = {
     },
     {.name = "group-name",
      .type = VSH_OT_STRING,
+     .completer = virshCompleteEmpty,
      .help = N_("group name to share I/O quota between multiple drives")
     },
     {.name = "total_bytes_sec_max_length",
@@ -1493,22 +1505,27 @@ static const vshCmdOptDef opts_blkiotune[] = {
     },
     {.name = "device-weights",
      .type = VSH_OT_STRING,
+     .completer = virshCompleteEmpty,
      .help = N_("per-device IO Weights, in the form of /path/to/device,weight,...")
     },
     {.name = "device-read-iops-sec",
      .type = VSH_OT_STRING,
+     .completer = virshCompleteEmpty,
      .help = N_("per-device read I/O limit per second, in the form of /path/to/device,read_iops_sec,...")
     },
     {.name = "device-write-iops-sec",
      .type = VSH_OT_STRING,
+     .completer = virshCompleteEmpty,
      .help = N_("per-device write I/O limit per second, in the form of /path/to/device,write_iops_sec,...")
     },
     {.name = "device-read-bytes-sec",
      .type = VSH_OT_STRING,
+     .completer = virshCompleteEmpty,
      .help = N_("per-device bytes read per second, in the form of /path/to/device,read_bytes_sec,...")
     },
     {.name = "device-write-bytes-sec",
      .type = VSH_OT_STRING,
+     .completer = virshCompleteEmpty,
      .help = N_("per-device bytes wrote per second, in the form of /path/to/device,write_bytes_sec,...")
     },
     VIRSH_COMMON_OPT_DOMAIN_CONFIG,
@@ -3210,10 +3227,12 @@ static const vshCmdOptDef opts_domiftune[] = {
     },
     {.name = "inbound",
      .type = VSH_OT_STRING,
+     .completer = virshCompleteEmpty,
      .help = N_("control domain's incoming traffics")
     },
     {.name = "outbound",
      .type = VSH_OT_STRING,
+     .completer = virshCompleteEmpty,
      .help = N_("control domain's outgoing traffics")
     },
     VIRSH_COMMON_OPT_DOMAIN_CONFIG,
@@ -3991,6 +4010,7 @@ static const vshCmdOptDef opts_start[] = {
     },
     {.name = "pass-fds",
      .type = VSH_OT_STRING,
+     .completer = virshCompleteEmpty,
      .help = N_("pass file descriptors N,M,... to the guest")
     },
     {.name = NULL}
@@ -5742,6 +5762,7 @@ static const vshCmdOptDef opts_set_user_password[] = {
     {.name = "password",
      .type = VSH_OT_DATA,
      .flags = VSH_OFLAG_REQ,
+     .completer = virshCompleteEmpty,
      .help = N_("the new password")
     },
     {.name = "encrypted",
@@ -8101,6 +8122,7 @@ static const vshCmdOptDef opts_create[] = {
     },
     {.name = "pass-fds",
      .type = VSH_OT_STRING,
+     .completer = virshCompleteEmpty,
      .help = N_("pass file descriptors N,M,... to the guest")
     },
     {.name = "validate",
@@ -8458,6 +8480,7 @@ static const vshCmdOptDef opts_metadata[] = {
     },
     {.name = "set",
      .type = VSH_OT_STRING,
+     .completer = virshCompleteEmpty,
      .help = N_("new metadata to set"),
     },
     {.name = "remove",
@@ -8719,6 +8742,7 @@ static const vshCmdOptDef opts_send_process_signal[] = {
     {.name = "pid",
      .type = VSH_OT_DATA,
      .flags = VSH_OFLAG_REQ,
+     .completer = virshCompleteEmpty,
      .help = N_("the process ID")
     },
     {.name = "signame",
@@ -9660,6 +9684,7 @@ static const vshCmdOptDef opts_qemu_attach[] = {
     {.name = "pid",
      .type = VSH_OT_DATA,
      .flags = VSH_OFLAG_REQ,
+     .completer = virshCompleteEmpty,
      .help = N_("pid")
     },
     {.name = NULL}
@@ -10174,6 +10199,7 @@ static const vshCmdOptDef opts_domrename[] = {
     {.name = "new-name",
      .type = VSH_OT_DATA,
      .flags = VSH_OFLAG_REQ,
+     .completer = virshCompleteEmpty,
      .help = N_("new domain name")
     },
     {.name = NULL}
@@ -10290,6 +10316,7 @@ static const vshCmdOptDef opts_migrate[] = {
     {.name = "desturi",
      .type = VSH_OT_DATA,
      .flags = VSH_OFLAG_REQ,
+     .completer = virshCompleteEmpty,
      .help = N_("connection URI of the destination host as seen from the client(normal migration) or source(p2p migration)")
     },
     VIRSH_COMMON_OPT_LIVE(N_("live migration")),
@@ -10371,18 +10398,22 @@ static const vshCmdOptDef opts_migrate[] = {
     },
     {.name = "migrateuri",
      .type = VSH_OT_STRING,
+     .completer = virshCompleteEmpty,
      .help = N_("migration URI, usually can be omitted")
     },
     {.name = "graphicsuri",
      .type = VSH_OT_STRING,
+     .completer = virshCompleteEmpty,
      .help = N_("graphics URI to be used for seamless graphics migration")
     },
     {.name = "listen-address",
      .type = VSH_OT_STRING,
+     .completer = virshCompleteEmpty,
      .help = N_("listen address that destination should bind to for incoming migration")
     },
     {.name = "dname",
      .type = VSH_OT_STRING,
+     .completer = virshCompleteEmpty,
      .help = N_("rename to new name during migration (if supported)")
     },
     {.name = "timeout",
@@ -10414,6 +10445,7 @@ static const vshCmdOptDef opts_migrate[] = {
     },
     {.name = "disks-uri",
      .type = VSH_OT_STRING,
+     .completer = virshCompleteEmpty,
      .help = N_("URI to use for disks migration (overrides --disks-port)")
     },
     {.name = "comp-methods",
@@ -10472,6 +10504,7 @@ static const vshCmdOptDef opts_migrate[] = {
     },
     {.name = "tls-destination",
      .type = VSH_OT_STRING,
+     .completer = virshCompleteEmpty,
      .help = N_("override the destination host name used for TLS verification")
     },
     {.name = NULL}
index 9ad7cbe4666c228538f29b7cda6d84582bbd5053..fd9d5ead638c1337fe52da59c8c16bace0b70ea9 100644 (file)
@@ -59,6 +59,7 @@
     {.name = "name", \
      .type = VSH_OT_DATA, \
      .flags = VSH_OFLAG_REQ, \
+     .completer = virshCompleteEmpty, \
      .help = N_("name of the pool") \
     }, \
     {.name = "type", \
@@ -73,6 +74,7 @@
     }, \
     {.name = "source-host", \
      .type = VSH_OT_STRING, \
+     .completer = virshCompleteEmpty, \
      .help = N_("source-host for underlying storage") \
     }, \
     {.name = "source-path", \
     }, \
     {.name = "auth-username", \
      .type = VSH_OT_STRING, \
+     .completer = virshCompleteEmpty, \
      .help = N_("auth username to be used for underlying storage") \
     }, \
     {.name = "secret-usage", \
     }, \
     {.name = "source-initiator", \
      .type = VSH_OT_STRING, \
+     .completer = virshCompleteEmpty, \
      .help = N_("initiator iqn for underlying storage") \
     }
 
@@ -1417,14 +1421,17 @@ static const vshCmdOptDef opts_find_storage_pool_sources_as[] = {
     },
     {.name = "host",
      .type = VSH_OT_STRING,
+     .completer = virshCompleteEmpty,
      .help = N_("optional host to query")
     },
     {.name = "port",
      .type = VSH_OT_STRING,
+     .completer = virshCompleteEmpty,
      .help = N_("optional port to query")
     },
     {.name = "initiator",
      .type = VSH_OT_STRING,
+     .completer = virshCompleteEmpty,
      .help = N_("optional initiator IQN to use for query")
     },
     {.name = NULL}
index d23cbf04bf16f2c7418c5f5d47bc708c69ffb911..dff2710928e668bcc5e01244764c673de5b54443 100644 (file)
@@ -199,6 +199,7 @@ static const vshCmdOptDef opts_secret_set_value[] = {
     },
     {.name = "base64",
      .type = VSH_OT_STRING,
+     .completer = virshCompleteEmpty,
      .help = N_("base64-encoded secret value")
     },
     {.name = NULL}
index 5a3c468c533360b85d2bfd134932e15fd887327e..2659b4340d97ead459068664609b3e75f952a9ad 100644 (file)
@@ -324,10 +324,12 @@ static const vshCmdOptDef opts_snapshot_create_as[] = {
     VIRSH_COMMON_OPT_DOMAIN_FULL(0),
     {.name = "name",
      .type = VSH_OT_STRING,
+     .completer = virshCompleteEmpty,
      .help = N_("name of snapshot")
     },
     {.name = "description",
      .type = VSH_OT_STRING,
+     .completer = virshCompleteEmpty,
      .help = N_("description of snapshot")
     },
     {.name = "print-xml",
index b73837f4c876b24501a4060f15e11b9cec71ada9..103a9b9237d8b3d59f17ee694c665539957154d6 100644 (file)
@@ -185,15 +185,18 @@ static const vshCmdOptDef opts_vol_create_as[] = {
     {.name = "name",
      .type = VSH_OT_DATA,
      .flags = VSH_OFLAG_REQ,
+     .completer = virshCompleteEmpty,
      .help = N_("name of the volume")
     },
     {.name = "capacity",
      .type = VSH_OT_DATA,
      .flags = VSH_OFLAG_REQ,
+     .completer = virshCompleteEmpty,
      .help = N_("size of the vol, as scaled integer (default bytes)")
     },
     {.name = "allocation",
      .type = VSH_OT_STRING,
+     .completer = virshCompleteEmpty,
      .help = N_("initial allocation size, as scaled integer (default bytes)")
     },
     {.name = "format",
@@ -561,6 +564,7 @@ static const vshCmdOptDef opts_vol_clone[] = {
     {.name = "newname",
      .type = VSH_OT_DATA,
      .flags = VSH_OFLAG_REQ,
+     .completer = virshCompleteEmpty,
      .help = N_("clone name")
     },
     VIRSH_COMMON_OPT_POOL_OPTIONAL,
@@ -1131,6 +1135,7 @@ static const vshCmdOptDef opts_vol_resize[] = {
     {.name = "capacity",
      .type = VSH_OT_DATA,
      .flags = VSH_OFLAG_REQ,
+     .completer = virshCompleteEmpty,
      .help = N_("new capacity for the vol, as scaled integer (default bytes)")
     },
     VIRSH_COMMON_OPT_POOL_OPTIONAL,
index 3c6f60f17629ca359903a0f0cdb0faa1d3f04968..b9f3f851d3ec39baf0b39ad1b2f0dfc8fe36a604 100644 (file)
@@ -252,6 +252,7 @@ static const vshCmdOptDef opts_connect[] = {
     {.name = "name",
      .type = VSH_OT_STRING,
      .flags = VSH_OFLAG_EMPTY_OK,
+     .completer = virshCompleteEmpty,
      .help = N_("hypervisor connection URI")
     },
     {.name = "readonly",