[PATCH 0/6] virsh: Add missing TAB completers for several commands
From: Radoslaw Smigielski <rsmigiel@redhat.com> This series adds missing virsh TAB completion callbacks for six command options: - dump --file - blockcopy --dest - detach-interface --type - domdisplay --type - domxml-from-native --format - save --file This is a small step towards closing the missing completers tracked in: https://gitlab.com/libvirt/libvirt/-/work_items/9 As of now there are 29 missing bash completers, the one fixed in this patch is first batch. As some of the patches change only one line, I would apprecate your feedback if these small one should be combined into a single patch? Radoslaw Smigielski (6): virsh: Add completer for '--file' option of 'dump' subcommand virsh: Add completer for '--dest' option of 'blockcopy' command virsh: Add completer for '--type' option of 'detach-interface' command virsh: Add completer for '--type' option of 'domdisplay' command virsh: Add completer for '--format' option of 'domxml-from-native' command virsh: Add completer for '--file' option of 'save' command tools/virsh-completer-domain.c | 49 ++++++++++++++++++++++++++++++++++ tools/virsh-completer-domain.h | 10 +++++++ tools/virsh-domain.c | 6 +++++ 3 files changed, 65 insertions(+) -- 2.54.0
From: Radoslaw Smigielski <rsmigiel@redhat.com> The '--file' option of 'dump' command specifies where to store the core dump file. Partially-fixes: https://gitlab.com/libvirt/libvirt/-/work_items/9 Signed-off-by: Radoslaw Smigielski <rsmigiel@redhat.com> --- tools/virsh-domain.c | 1 + 1 file changed, 1 insertion(+) diff --git a/tools/virsh-domain.c b/tools/virsh-domain.c index aa4f2a7a481b..f466976931c6 100644 --- a/tools/virsh-domain.c +++ b/tools/virsh-domain.c @@ -5911,6 +5911,7 @@ static const vshCmdOptDef opts_dump[] = { .type = VSH_OT_STRING, .positional = true, .required = true, + .completer = vshCompletePathLocalExisting, .help = N_("where to dump the core") }, VIRSH_COMMON_OPT_LIVE(N_("perform a live core dump if supported")), -- 2.54.0
On Thu, Jul 09, 2026 at 15:00:57 +0200, Radosław Śmigielski via Devel wrote:
From: Radoslaw Smigielski <rsmigiel@redhat.com>
The '--file' option of 'dump' command specifies where to store the core dump file.
Partially-fixes: https://gitlab.com/libvirt/libvirt/-/work_items/9 Signed-off-by: Radoslaw Smigielski <rsmigiel@redhat.com> --- tools/virsh-domain.c | 1 + 1 file changed, 1 insertion(+)
diff --git a/tools/virsh-domain.c b/tools/virsh-domain.c index aa4f2a7a481b..f466976931c6 100644 --- a/tools/virsh-domain.c +++ b/tools/virsh-domain.c @@ -5911,6 +5911,7 @@ static const vshCmdOptDef opts_dump[] = { .type = VSH_OT_STRING, .positional = true, .required = true, + .completer = vshCompletePathLocalExisting,
The dump target doesn't exist yet so this completer is not the correct one: /** * vshCompletePathLocalExisting: * * Complete a path to a existing file used as input. The file is used as input ^^^^^^^^ * for virsh so only local files are considered.
.help = N_("where to dump the core") }, VIRSH_COMMON_OPT_LIVE(N_("perform a live core dump if supported")), -- 2.54.0
On Fri, Jul 10, 2026 at 10:05:45 +0200, Peter Krempa via Devel wrote:
On Thu, Jul 09, 2026 at 15:00:57 +0200, Radosław Śmigielski via Devel wrote:
From: Radoslaw Smigielski <rsmigiel@redhat.com>
The '--file' option of 'dump' command specifies where to store the core dump file.
Partially-fixes: https://gitlab.com/libvirt/libvirt/-/work_items/9 Signed-off-by: Radoslaw Smigielski <rsmigiel@redhat.com> --- tools/virsh-domain.c | 1 + 1 file changed, 1 insertion(+)
diff --git a/tools/virsh-domain.c b/tools/virsh-domain.c index aa4f2a7a481b..f466976931c6 100644 --- a/tools/virsh-domain.c +++ b/tools/virsh-domain.c @@ -5911,6 +5911,7 @@ static const vshCmdOptDef opts_dump[] = { .type = VSH_OT_STRING, .positional = true, .required = true, + .completer = vshCompletePathLocalExisting,
The dump target doesn't exist yet so this completer is not the correct one:
/** * vshCompletePathLocalExisting: * * Complete a path to a existing file used as input. The file is used as input
^^^^^^^^
* for virsh so only local files are considered.
To be clear: Any argument that is supposed to point to a file to be created (doesn't exist) should be completed by a separate function (which IIRC doesn't exist yet) even when it will do the exact same thing as vshCompletePathLocalExisting. This is to prevent the need to go trhough everything if we figure out that we want to do something else than the readline default.
From: Radoslaw Smigielski <rsmigiel@redhat.com> The '--dest' option of 'blockcopy' command specifies the path of the copy to create. Partially-fixes: https://gitlab.com/libvirt/libvirt/-/work_items/9 Signed-off-by: Radoslaw Smigielski <rsmigiel@redhat.com> --- tools/virsh-domain.c | 1 + 1 file changed, 1 insertion(+) diff --git a/tools/virsh-domain.c b/tools/virsh-domain.c index f466976931c6..e6f2ca3a449a 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 = vshCompletePathLocalExisting, .help = N_("path of the copy to create") }, {.name = "bandwidth", -- 2.54.0
On Thu, Jul 09, 2026 at 15:00:58 +0200, Radosław Śmigielski via Devel wrote:
From: Radoslaw Smigielski <rsmigiel@redhat.com>
The '--dest' option of 'blockcopy' command specifies the path of the copy to create.
Same as before, this file doesn't exist yet ....
Partially-fixes: https://gitlab.com/libvirt/libvirt/-/work_items/9 Signed-off-by: Radoslaw Smigielski <rsmigiel@redhat.com> --- tools/virsh-domain.c | 1 + 1 file changed, 1 insertion(+)
diff --git a/tools/virsh-domain.c b/tools/virsh-domain.c index f466976931c6..e6f2ca3a449a 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 = vshCompletePathLocalExisting,
... so you shouldn't use the 'Existing' completer.
.help = N_("path of the copy to create") }, {.name = "bandwidth", -- 2.54.0
From: Radoslaw Smigielski <rsmigiel@redhat.com> The '--type' option of 'detach-interface' command specifies the network interface type to detach. Partially-fixes: https://gitlab.com/libvirt/libvirt/-/work_items/9 Signed-off-by: Radoslaw Smigielski <rsmigiel@redhat.com> --- tools/virsh-domain.c | 1 + 1 file changed, 1 insertion(+) diff --git a/tools/virsh-domain.c b/tools/virsh-domain.c index e6f2ca3a449a..79823072ad26 100644 --- a/tools/virsh-domain.c +++ b/tools/virsh-domain.c @@ -12785,6 +12785,7 @@ static const vshCmdOptDef opts_detach_interface[] = { {.name = "type", .type = VSH_OT_STRING, .positional = true, + .completer = virshDomainNetTypeCompleter, .help = N_("network interface type") }, {.name = "mac", -- 2.54.0
On Thu, Jul 09, 2026 at 15:00:59 +0200, Radosław Śmigielski via Devel wrote:
From: Radoslaw Smigielski <rsmigiel@redhat.com>
The '--type' option of 'detach-interface' command specifies the network interface type to detach.
Note that the manpage explicitly mentions only two of the network types but the code as-written supports every type.
Partially-fixes: https://gitlab.com/libvirt/libvirt/-/work_items/9 Signed-off-by: Radoslaw Smigielski <rsmigiel@redhat.com> --- tools/virsh-domain.c | 1 + 1 file changed, 1 insertion(+)
diff --git a/tools/virsh-domain.c b/tools/virsh-domain.c index e6f2ca3a449a..79823072ad26 100644 --- a/tools/virsh-domain.c +++ b/tools/virsh-domain.c @@ -12785,6 +12785,7 @@ static const vshCmdOptDef opts_detach_interface[] = { {.name = "type", .type = VSH_OT_STRING, .positional = true, + .completer = virshDomainNetTypeCompleter, .help = N_("network interface type") }, {.name = "mac", -- 2.54.0
Reviewed-by: Peter Krempa <pkrempa@redhat.com>
From: Radoslaw Smigielski <rsmigiel@redhat.com> The '--type' option of 'domdisplay' command selects a particular graphical display scheme (vnc, spice, rdp, or dbus). Partially-fixes: https://gitlab.com/libvirt/libvirt/-/work_items/9 Signed-off-by: Radoslaw Smigielski <rsmigiel@redhat.com> --- tools/virsh-completer-domain.c | 13 +++++++++++++ tools/virsh-completer-domain.h | 5 +++++ tools/virsh-domain.c | 1 + 3 files changed, 19 insertions(+) diff --git a/tools/virsh-completer-domain.c b/tools/virsh-completer-domain.c index 8bdf68ac091d..4c0ddb01d855 100644 --- a/tools/virsh-completer-domain.c +++ b/tools/virsh-completer-domain.c @@ -1132,3 +1132,16 @@ 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) +{ + static const char *types[] = {"vnc", "spice", "rdp", "dbus", NULL}; + + virCheckFlags(0, NULL); + + return vshCommaStringListComplete(NULL, types); +} 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 79823072ad26..a546532b7dd2 100644 --- a/tools/virsh-domain.c +++ b/tools/virsh-domain.c @@ -12181,6 +12181,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
On Thu, Jul 09, 2026 at 15:01:00 +0200, Radosław Śmigielski via Devel wrote:
From: Radoslaw Smigielski <rsmigiel@redhat.com>
The '--type' option of 'domdisplay' command selects a particular graphical display scheme (vnc, spice, rdp, or dbus).
Partially-fixes: https://gitlab.com/libvirt/libvirt/-/work_items/9 Signed-off-by: Radoslaw Smigielski <rsmigiel@redhat.com> --- tools/virsh-completer-domain.c | 13 +++++++++++++ tools/virsh-completer-domain.h | 5 +++++ tools/virsh-domain.c | 1 + 3 files changed, 19 insertions(+)
diff --git a/tools/virsh-completer-domain.c b/tools/virsh-completer-domain.c index 8bdf68ac091d..4c0ddb01d855 100644 --- a/tools/virsh-completer-domain.c +++ b/tools/virsh-completer-domain.c @@ -1132,3 +1132,16 @@ 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) +{ + static const char *types[] = {"vnc", "spice", "rdp", "dbus", NULL};
This duplicates the list of supported types and is missing some that were added meanwhile. Duplicating it means that it will be forgotten in the future too when some new type is added. Use virDomainGraphicsTypeToString adn VIR_DOMAIN_GRAPHICS_TYPE_LAST via the normal enum completer.
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 4c0ddb01d855..8154ba8d622c 100644 --- a/tools/virsh-completer-domain.c +++ b/tools/virsh-completer-domain.c @@ -1145,3 +1145,39 @@ virshDomainDisplayTypeCompleter(vshControl *ctl G_GNUC_UNUSED, return vshCommaStringListComplete(NULL, types); } + + +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 a546532b7dd2..abe3d0b3451e 100644 --- a/tools/virsh-domain.c +++ b/tools/virsh-domain.c @@ -10916,6 +10916,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> The '--file' option of 'save' command specifies where to store the saved domain state. Partially-fixes: https://gitlab.com/libvirt/libvirt/-/work_items/9 Signed-off-by: Radoslaw Smigielski <rsmigiel@redhat.com> --- tools/virsh-domain.c | 1 + 1 file changed, 1 insertion(+) diff --git a/tools/virsh-domain.c b/tools/virsh-domain.c index abe3d0b3451e..56066edc5b31 100644 --- a/tools/virsh-domain.c +++ b/tools/virsh-domain.c @@ -4652,6 +4652,7 @@ static const vshCmdOptDef opts_save[] = { .type = VSH_OT_STRING, .positional = true, .required = true, + .completer = vshCompletePathLocalExisting, .help = N_("where to save the data") }, {.name = "bypass-cache", -- 2.54.0
participants (2)
-
Peter Krempa -
rsmigiel@redhat.com