[PATCH] virsh: Add completer for '--type' option of 'attach-interface' command

Michal Privoznik via Devel posted 1 patch 2 days, 9 hours ago
Patches applied successfully (tree, apply log)
git fetch https://github.com/patchew-project/libvirt tags/patchew/3e0a1eecb109a0080f2df591824d4d9f4b896b3e.1782125760.git.mprivozn@redhat.com
tools/virsh-completer-domain.c | 13 +++++++++++++
tools/virsh-completer-domain.h |  5 +++++
tools/virsh-domain.c           |  1 +
3 files changed, 19 insertions(+)
[PATCH] virsh: Add completer for '--type' option of 'attach-interface' command
Posted by Michal Privoznik via Devel 2 days, 9 hours ago
From: Michal Privoznik <mprivozn@redhat.com>

The '--type' option of 'attach-interface' command is translated
from string into int using virDomainNetTypeFromString(), IOW the
expected value is from virDomainNetType enum.

Signed-off-by: Michal Privoznik <mprivozn@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 912826c434..8bdf68ac09 100644
--- a/tools/virsh-completer-domain.c
+++ b/tools/virsh-completer-domain.c
@@ -35,6 +35,7 @@
 #include "virkeynametable_linux.h"
 #include "virkeynametable_osx.h"
 #include "virkeynametable_win32.h"
+#include "conf/domain_conf.h"
 #include "conf/storage_conf.h"
 #include "conf/numa_conf.h"
 
@@ -1119,3 +1120,15 @@ virshDomainDirtyRateCalcModeCompleter(vshControl *ctl G_GNUC_UNUSED,
     return vshEnumComplete(VIRSH_DOMAIN_DIRTYRATE_CALC_MODE_LAST,
                            virshDomainDirtyRateCalcModeTypeToString);
 }
+
+
+char **
+virshDomainNetTypeCompleter(vshControl *ctl G_GNUC_UNUSED,
+                            const vshCmd *cmd G_GNUC_UNUSED,
+                            unsigned int flags)
+{
+    virCheckFlags(0, NULL);
+
+    return vshEnumComplete(VIR_DOMAIN_NET_TYPE_LAST,
+                           virDomainNetTypeToString);
+}
diff --git a/tools/virsh-completer-domain.h b/tools/virsh-completer-domain.h
index f5cda4dd15..dfbc10acaa 100644
--- a/tools/virsh-completer-domain.h
+++ b/tools/virsh-completer-domain.h
@@ -199,3 +199,8 @@ char **
 virshDomainDirtyRateCalcModeCompleter(vshControl *ctl,
                                       const vshCmd *cmd,
                                       unsigned int flags);
+
+char **
+virshDomainNetTypeCompleter(vshControl *ctl,
+                            const vshCmd *cmd,
+                            unsigned int flags);
diff --git a/tools/virsh-domain.c b/tools/virsh-domain.c
index 8a6f868e34..aa4f2a7a48 100644
--- a/tools/virsh-domain.c
+++ b/tools/virsh-domain.c
@@ -837,6 +837,7 @@ static const vshCmdOptDef opts_attach_interface[] = {
      .type = VSH_OT_STRING,
      .positional = true,
      .required = true,
+     .completer = virshDomainNetTypeCompleter,
      .help = N_("network interface type")
     },
     {.name = "source",
-- 
2.53.0
Re: [PATCH] virsh: Add completer for '--type' option of 'attach-interface' command
Posted by Peter Krempa via Devel 2 days, 9 hours ago
On Mon, Jun 22, 2026 at 12:56:00 +0200, Michal Privoznik via Devel wrote:
> From: Michal Privoznik <mprivozn@redhat.com>
> 
> The '--type' option of 'attach-interface' command is translated
> from string into int using virDomainNetTypeFromString(), IOW the
> expected value is from virDomainNetType enum.
> 
> Signed-off-by: Michal Privoznik <mprivozn@redhat.com>
> ---
>  tools/virsh-completer-domain.c | 13 +++++++++++++
>  tools/virsh-completer-domain.h |  5 +++++
>  tools/virsh-domain.c           |  1 +
>  3 files changed, 19 insertions(+)

Reviewed-by: Peter Krempa <pkrempa@redhat.com>