[PATCH v2 0/5] virsh: Add missing TAB completers for several commands
From: Radoslaw Smigielski <rsmigiel@redhat.com> These changes add missing virsh TAB completion callbacks for several commands. Fixed or added completers covers command grouped by similar options: output paths: - dump --file - save --file - blockcopy --dest - screenshot --file (fixes pre-existing wrong annotation) display / native format: - domdisplay --type - domxml-from-native --format - domxml-to-native --format storage volume formats: - vol-create-as --format - vol-create-as --backing-vol-format attach-disk: - targetbus, type, cache, io, mode, sourcetype, subdriver - source-host-socket In patch 1/5 added vshCompletePathLocalCreate, a new noop completer for local file paths used as command output where the target file may not exist yet. This is the counterpart to vshCompletePathLocalExisting, which is for existing files used as input. In patch 2/5 adds a completer for domdisplay --type using virDomainGraphicsTypeToString and VIR_DOMAIN_GRAPHICS_TYPE_LAST so the options stays in sync with libvirt graphics types. Replaced the static list from first patch set. In patch 3/5 adds virshDomainXMLNativeFormatCompleter for domxml-from-native --format (hypervisor-dependent native config format list). In virshDomainXMLNativeFormatCompleter() added 4 new "static const char[]" variables, follow the same pattern appears in the same file. Even though these variables could be a non-static local arrays. In patch 4/5 reuses existing completers for domxml-to-native --format and vol-create-as --format / --backing-vol-format. In 5/5 adds few enum and static-list completers for attach-disk options targetbus, type, cache, io, mode, and sourcetype, and reuses the storage file format completer for subdriver. In virshDomainAttachDiskSourceTypeCompleter, I added a static list of element types, I did not find any existing variable with the same list content. Partially-fixes: https://gitlab.com/libvirt/libvirt/-/work_items/9 Radoslaw Smigielski (5): virsh: Add vshCompletePathLocalCreate completer for output paths virsh: Add completer for '--type' option of 'domdisplay' command virsh: Add completer for '--format' option of 'domxml-from-native' command virsh: Add missing TAB completers for several options virsh: Add missing TAB completers for 'attach-disk' command tools/virsh-completer-domain.c | 122 +++++++++++++++++++++++++++++++++ tools/virsh-completer-domain.h | 40 +++++++++++ tools/virsh-domain.c | 16 ++++- tools/virsh-volume.c | 2 + tools/vsh-completer.c | 18 +++++ tools/vsh-completer.h | 5 ++ 6 files changed, 202 insertions(+), 1 deletion(-) -- 2.54.0
From: Radoslaw Smigielski <rsmigiel@redhat.com> Add a completer callback for local file paths used as command output, where the target file may not exist yet. Use it for 'dump', 'save', and 'blockcopy' commands, and fix 'screenshot' to use it instead of vshCompletePathLocalExisting. Partially-fixes: https://gitlab.com/libvirt/libvirt/-/work_items/9 Signed-off-by: Radoslaw Smigielski <rsmigiel@redhat.com> --- tools/virsh-domain.c | 5 ++++- tools/vsh-completer.c | 18 ++++++++++++++++++ tools/vsh-completer.h | 5 +++++ 3 files changed, 27 insertions(+), 1 deletion(-) diff --git a/tools/virsh-domain.c b/tools/virsh-domain.c index aa4f2a7a481b..0a383ea40013 100644 --- a/tools/virsh-domain.c +++ b/tools/virsh-domain.c @@ -2629,6 +2629,7 @@ static const vshCmdOptDef opts_blockcopy[] = { {.name = "dest", .type = VSH_OT_STRING, .unwanted_positional = true, + .completer = vshCompletePathLocalCreate, .help = N_("path of the copy to create") }, {.name = "bandwidth", @@ -4651,6 +4652,7 @@ static const vshCmdOptDef opts_save[] = { .type = VSH_OT_STRING, .positional = true, .required = true, + .completer = vshCompletePathLocalCreate, .help = N_("where to save the data") }, {.name = "bypass-cache", @@ -5911,6 +5913,7 @@ static const vshCmdOptDef opts_dump[] = { .type = VSH_OT_STRING, .positional = true, .required = true, + .completer = vshCompletePathLocalCreate, .help = N_("where to dump the core") }, VIRSH_COMMON_OPT_LIVE(N_("perform a live core dump if supported")), @@ -6081,7 +6084,7 @@ static const vshCmdOptDef opts_screenshot[] = { {.name = "file", .type = VSH_OT_STRING, .unwanted_positional = true, - .completer = vshCompletePathLocalExisting, + .completer = vshCompletePathLocalCreate, .help = N_("where to store the screenshot") }, {.name = "screen", diff --git a/tools/vsh-completer.c b/tools/vsh-completer.c index 8f0376879cdb..ba137ebe6c16 100644 --- a/tools/vsh-completer.c +++ b/tools/vsh-completer.c @@ -172,6 +172,24 @@ vshCompletePathLocalExisting(vshControl *ctl G_GNUC_UNUSED, } +/** + * vshCompletePathLocalCreate: + * + * Complete a path to local file used as output. + * The outout file may not exist yet. + * + * Note: For now this is a no-op. Readline does the correct thing + * and completes local files list. + */ +char ** +vshCompletePathLocalCreate(vshControl *ctl G_GNUC_UNUSED, + const vshCmd *cmd G_GNUC_UNUSED, + unsigned int completerflags G_GNUC_UNUSED) +{ + return NULL; +} + + /** * vshCompleteEmpty: * diff --git a/tools/vsh-completer.h b/tools/vsh-completer.h index b479156062c0..5639974c0b86 100644 --- a/tools/vsh-completer.h +++ b/tools/vsh-completer.h @@ -35,6 +35,11 @@ vshCompletePathLocalExisting(vshControl *ctl, const vshCmd *cmd, unsigned int completerflags); +char ** +vshCompletePathLocalCreate(vshControl *ctl, + const vshCmd *cmd, + unsigned int completerflags); + char ** vshCompleteEmpty(vshControl *ctl, const vshCmd *cmd, -- 2.54.0
From: Radoslaw Smigielski <rsmigiel@redhat.com> The '--type' option of 'domdisplay' command selects a particular graphical display type. Partially-fixes: https://gitlab.com/libvirt/libvirt/-/work_items/9 Signed-off-by: Radoslaw Smigielski <rsmigiel@redhat.com> --- tools/virsh-completer-domain.c | 12 ++++++++++++ tools/virsh-completer-domain.h | 5 +++++ tools/virsh-domain.c | 1 + 3 files changed, 18 insertions(+) diff --git a/tools/virsh-completer-domain.c b/tools/virsh-completer-domain.c index 8bdf68ac091d..afb080b868d7 100644 --- a/tools/virsh-completer-domain.c +++ b/tools/virsh-completer-domain.c @@ -1132,3 +1132,15 @@ virshDomainNetTypeCompleter(vshControl *ctl G_GNUC_UNUSED, return vshEnumComplete(VIR_DOMAIN_NET_TYPE_LAST, virDomainNetTypeToString); } + + +char ** +virshDomainDisplayTypeCompleter(vshControl *ctl G_GNUC_UNUSED, + const vshCmd *cmd G_GNUC_UNUSED, + unsigned int flags) +{ + virCheckFlags(0, NULL); + + return vshEnumComplete(VIR_DOMAIN_GRAPHICS_TYPE_LAST, + virDomainGraphicsTypeToString); +} diff --git a/tools/virsh-completer-domain.h b/tools/virsh-completer-domain.h index dfbc10acaaa8..3aab7bedae20 100644 --- a/tools/virsh-completer-domain.h +++ b/tools/virsh-completer-domain.h @@ -204,3 +204,8 @@ char ** virshDomainNetTypeCompleter(vshControl *ctl, const vshCmd *cmd, unsigned int flags); + +char ** +virshDomainDisplayTypeCompleter(vshControl *ctl, + const vshCmd *cmd, + unsigned int flags); diff --git a/tools/virsh-domain.c b/tools/virsh-domain.c index 0a383ea40013..f15f686c7908 100644 --- a/tools/virsh-domain.c +++ b/tools/virsh-domain.c @@ -12182,6 +12182,7 @@ static const vshCmdOptDef opts_domdisplay[] = { {.name = "type", .type = VSH_OT_STRING, .positional = true, + .completer = virshDomainDisplayTypeCompleter, .help = N_("select particular graphical display " "(e.g. \"vnc\", \"spice\", \"rdp\", \"dbus\")") }, -- 2.54.0
From: Radoslaw Smigielski <rsmigiel@redhat.com> The '--format' option of 'domxml-from-native' command specifies the native guest configuration format to import. Partially-fixes: https://gitlab.com/libvirt/libvirt/-/work_items/9 Signed-off-by: Radoslaw Smigielski <rsmigiel@redhat.com> --- tools/virsh-completer-domain.c | 36 ++++++++++++++++++++++++++++++++++ tools/virsh-completer-domain.h | 5 +++++ tools/virsh-domain.c | 1 + 3 files changed, 42 insertions(+) diff --git a/tools/virsh-completer-domain.c b/tools/virsh-completer-domain.c index afb080b868d7..65b02488bb39 100644 --- a/tools/virsh-completer-domain.c +++ b/tools/virsh-completer-domain.c @@ -1144,3 +1144,39 @@ virshDomainDisplayTypeCompleter(vshControl *ctl G_GNUC_UNUSED, return vshEnumComplete(VIR_DOMAIN_GRAPHICS_TYPE_LAST, virDomainGraphicsTypeToString); } + + +char ** +virshDomainXMLNativeFormatCompleter(vshControl *ctl, + const vshCmd *cmd G_GNUC_UNUSED, + unsigned int flags) +{ + virshControl *priv = ctl->privData; + const char *hvType = NULL; + const char **formats = NULL; + static const char *xenFormats[] = {"xen-xl", "xen-xm", NULL}; + static const char *lxcFormats[] = {"lxc-tools", NULL}; + static const char *vmxFormats[] = {"vmware-vmx", NULL}; + static const char *bhyveFormats[] = {"bhyve-argv", NULL}; + + virCheckFlags(0, NULL); + + if (!priv->conn || virConnectIsAlive(priv->conn) <= 0) + return NULL; + + if (!(hvType = virConnectGetType(priv->conn))) + return NULL; + + if (STREQ(hvType, "Xen")) + formats = xenFormats; + else if (STREQ(hvType, "LXC")) + formats = lxcFormats; + else if (STREQ(hvType, "VMware") || STREQ(hvType, "ESX")) + formats = vmxFormats; + else if (STREQ(hvType, "BHYVE")) + formats = bhyveFormats; + else + return NULL; + + return vshCommaStringListComplete(NULL, formats); +} diff --git a/tools/virsh-completer-domain.h b/tools/virsh-completer-domain.h index 3aab7bedae20..40de90afb79f 100644 --- a/tools/virsh-completer-domain.h +++ b/tools/virsh-completer-domain.h @@ -209,3 +209,8 @@ char ** virshDomainDisplayTypeCompleter(vshControl *ctl, const vshCmd *cmd, unsigned int flags); + +char ** +virshDomainXMLNativeFormatCompleter(vshControl *ctl, + const vshCmd *cmd, + unsigned int flags); diff --git a/tools/virsh-domain.c b/tools/virsh-domain.c index f15f686c7908..c1c27433b0bf 100644 --- a/tools/virsh-domain.c +++ b/tools/virsh-domain.c @@ -10917,6 +10917,7 @@ static const vshCmdOptDef opts_domxmlfromnative[] = { .type = VSH_OT_STRING, .positional = true, .required = true, + .completer = virshDomainXMLNativeFormatCompleter, .help = N_("source config data format") }, {.name = "config", -- 2.54.0
From: Radoslaw Smigielski <rsmigiel@redhat.com> Wire existing completers for 'domxml-to-native --format', 'vol-create-as --format', 'vol-create-as --backing-vol-format', and 'attach-disk --source-host-socket'. Partially-fixes: https://gitlab.com/libvirt/libvirt/-/work_items/9 Signed-off-by: Radoslaw Smigielski <rsmigiel@redhat.com> --- tools/virsh-domain.c | 2 ++ tools/virsh-volume.c | 2 ++ 2 files changed, 4 insertions(+) diff --git a/tools/virsh-domain.c b/tools/virsh-domain.c index c1c27433b0bf..bd6c877b4521 100644 --- a/tools/virsh-domain.c +++ b/tools/virsh-domain.c @@ -521,6 +521,7 @@ static const vshCmdOptDef opts_attach_disk[] = { }, {.name = "source-host-socket", .type = VSH_OT_STRING, + .completer = vshCompletePathLocalExisting, .help = N_("host socket for source of disk device") }, {.name = "throttle-groups", @@ -10968,6 +10969,7 @@ static const vshCmdOptDef opts_domxmltonative[] = { .type = VSH_OT_STRING, .positional = true, .required = true, + .completer = virshDomainXMLNativeFormatCompleter, .help = N_("target config data type format") }, {.name = "domain", diff --git a/tools/virsh-volume.c b/tools/virsh-volume.c index 7346d628d55d..21471e0496e9 100644 --- a/tools/virsh-volume.c +++ b/tools/virsh-volume.c @@ -197,6 +197,7 @@ static const vshCmdOptDef opts_vol_create_as[] = { {.name = "format", .type = VSH_OT_STRING, .unwanted_positional = true, + .completer = virshDomainStorageFileFormatCompleter, .help = N_("file format type raw,bochs,qcow,qcow2,qed,vmdk") }, {.name = "backing-vol", @@ -207,6 +208,7 @@ static const vshCmdOptDef opts_vol_create_as[] = { {.name = "backing-vol-format", .type = VSH_OT_STRING, .unwanted_positional = true, + .completer = virshDomainStorageFileFormatCompleter, .help = N_("format of backing volume if taking a snapshot") }, {.name = "prealloc-metadata", -- 2.54.0
From: Radoslaw Smigielski <rsmigiel@redhat.com> Add enum and static-list completers for 'attach-disk' options targetbus, type, cache, io, mode, and sourcetype, and reuse the existing storage file format completer for subdriver. Partially-fixes: https://gitlab.com/libvirt/libvirt/-/work_items/9 Signed-off-by: Radoslaw Smigielski <rsmigiel@redhat.com> --- tools/virsh-completer-domain.c | 74 ++++++++++++++++++++++++++++++++++ tools/virsh-completer-domain.h | 30 ++++++++++++++ tools/virsh-domain.c | 7 ++++ 3 files changed, 111 insertions(+) diff --git a/tools/virsh-completer-domain.c b/tools/virsh-completer-domain.c index 65b02488bb39..7251d70e997e 100644 --- a/tools/virsh-completer-domain.c +++ b/tools/virsh-completer-domain.c @@ -1180,3 +1180,77 @@ virshDomainXMLNativeFormatCompleter(vshControl *ctl, return vshCommaStringListComplete(NULL, formats); } + + +char ** +virshDomainDiskBusCompleter(vshControl *ctl G_GNUC_UNUSED, + const vshCmd *cmd G_GNUC_UNUSED, + unsigned int flags) +{ + virCheckFlags(0, NULL); + + return vshEnumComplete(VIR_DOMAIN_DISK_BUS_LAST, + virDomainDiskBusTypeToString); +} + + +char ** +virshDomainDiskDeviceTypeCompleter(vshControl *ctl G_GNUC_UNUSED, + const vshCmd *cmd G_GNUC_UNUSED, + unsigned int flags) +{ + virCheckFlags(0, NULL); + + return vshEnumComplete(VIR_DOMAIN_DISK_DEVICE_LAST, + virDomainDiskDeviceTypeToString); +} + + +char ** +virshDomainDiskCacheCompleter(vshControl *ctl G_GNUC_UNUSED, + const vshCmd *cmd G_GNUC_UNUSED, + unsigned int flags) +{ + virCheckFlags(0, NULL); + + return vshEnumComplete(VIR_DOMAIN_DISK_CACHE_LAST, + virDomainDiskCacheTypeToString); +} + + +char ** +virshDomainDiskIoCompleter(vshControl *ctl G_GNUC_UNUSED, + const vshCmd *cmd G_GNUC_UNUSED, + unsigned int flags) +{ + virCheckFlags(0, NULL); + + return vshEnumComplete(VIR_DOMAIN_DISK_IO_LAST, + virDomainDiskIoTypeToString); +} + + +char ** +virshDomainAttachDiskModeCompleter(vshControl *ctl G_GNUC_UNUSED, + const vshCmd *cmd G_GNUC_UNUSED, + unsigned int flags) +{ + static const char *modes[] = {"readonly", "shareable", NULL}; + + virCheckFlags(0, NULL); + + return vshCommaStringListComplete(NULL, modes); +} + + +char ** +virshDomainAttachDiskSourceTypeCompleter(vshControl *ctl G_GNUC_UNUSED, + const vshCmd *cmd G_GNUC_UNUSED, + unsigned int flags) +{ + static const char *types[] = {"file", "block", "network", NULL}; + + virCheckFlags(0, NULL); + + return vshCommaStringListComplete(NULL, types); +} diff --git a/tools/virsh-completer-domain.h b/tools/virsh-completer-domain.h index 40de90afb79f..aa2e82649071 100644 --- a/tools/virsh-completer-domain.h +++ b/tools/virsh-completer-domain.h @@ -214,3 +214,33 @@ char ** virshDomainXMLNativeFormatCompleter(vshControl *ctl, const vshCmd *cmd, unsigned int flags); + +char ** +virshDomainDiskBusCompleter(vshControl *ctl, + const vshCmd *cmd, + unsigned int flags); + +char ** +virshDomainDiskDeviceTypeCompleter(vshControl *ctl, + const vshCmd *cmd, + unsigned int flags); + +char ** +virshDomainDiskCacheCompleter(vshControl *ctl, + const vshCmd *cmd, + unsigned int flags); + +char ** +virshDomainDiskIoCompleter(vshControl *ctl, + const vshCmd *cmd, + unsigned int flags); + +char ** +virshDomainAttachDiskModeCompleter(vshControl *ctl, + const vshCmd *cmd, + unsigned int flags); + +char ** +virshDomainAttachDiskSourceTypeCompleter(vshControl *ctl, + const vshCmd *cmd, + unsigned int flags); diff --git a/tools/virsh-domain.c b/tools/virsh-domain.c index bd6c877b4521..ca35e3b7b214 100644 --- a/tools/virsh-domain.c +++ b/tools/virsh-domain.c @@ -435,6 +435,7 @@ static const vshCmdOptDef opts_attach_disk[] = { }, {.name = "targetbus", .type = VSH_OT_STRING, + .completer = virshDomainDiskBusCompleter, .help = N_("target bus of disk device") }, {.name = "driver", @@ -443,6 +444,7 @@ static const vshCmdOptDef opts_attach_disk[] = { }, {.name = "subdriver", .type = VSH_OT_STRING, + .completer = virshDomainStorageFileFormatCompleter, .help = N_("subdriver of disk device") }, {.name = "iothread", @@ -452,14 +454,17 @@ static const vshCmdOptDef opts_attach_disk[] = { }, {.name = "cache", .type = VSH_OT_STRING, + .completer = virshDomainDiskCacheCompleter, .help = N_("cache mode of disk device") }, {.name = "io", .type = VSH_OT_STRING, + .completer = virshDomainDiskIoCompleter, .help = N_("io policy of disk device") }, {.name = "type", .type = VSH_OT_STRING, + .completer = virshDomainDiskDeviceTypeCompleter, .help = N_("target device type") }, {.name = "shareable", @@ -468,10 +473,12 @@ static const vshCmdOptDef opts_attach_disk[] = { }, {.name = "mode", .type = VSH_OT_STRING, + .completer = virshDomainAttachDiskModeCompleter, .help = N_("mode of device reading and writing") }, {.name = "sourcetype", .type = VSH_OT_STRING, + .completer = virshDomainAttachDiskSourceTypeCompleter, .help = N_("type of source (block|file|network)") }, {.name = "serial", -- 2.54.0
participants (1)
-
rsmigiel@redhat.com