virsh: Introduce virshCompleteEmpty and use it for places where we can't suggest anything

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>
This commit is contained in:
Peter Krempa 2021-09-15 17:42:08 +02:00
parent 2732d81984
commit 071bab399a
9 changed files with 74 additions and 0 deletions

View 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",

View 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;
}

View 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);

View 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}

View 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", \
@ -101,6 +103,7 @@
}, \
{.name = "auth-username", \
.type = VSH_OT_STRING, \
.completer = virshCompleteEmpty, \
.help = N_("auth username to be used for underlying storage") \
}, \
{.name = "secret-usage", \
@ -145,6 +148,7 @@
}, \
{.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}

View 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}

View 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",

View 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,

View 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",