[PATCH 1/3] virsh: Provide completer for virtualization types

Amneesh Singh posted 3 patches 3 years, 10 months ago
[PATCH 1/3] virsh: Provide completer for virtualization types
Posted by Amneesh Singh 3 years, 10 months ago
Related: https://gitlab.com/libvirt/libvirt/-/issues/9
Signed-off-by: Amneesh Singh <natto@weirdnatto.in>
---
 tools/virsh-completer-host.c | 12 ++++++++++++
 tools/virsh-completer-host.h |  5 +++++
 tools/virsh-host.c           |  4 ++++
 3 files changed, 21 insertions(+)

diff --git a/tools/virsh-completer-host.c b/tools/virsh-completer-host.c
index cbdc3f0..14c68d3 100644
--- a/tools/virsh-completer-host.c
+++ b/tools/virsh-completer-host.c
@@ -27,6 +27,7 @@
 #include "virxml.h"
 #include "virutil.h"
 #include "virsh-host.h"
+#include "conf/domain_conf.h"
 
 static char *
 virshPagesizeNodeToString(xmlNodePtr node)
@@ -180,3 +181,14 @@ virshNodeSuspendTargetCompleter(vshControl *ctl G_GNUC_UNUSED,
     return virshEnumComplete(VIR_NODE_SUSPEND_TARGET_LAST,
                              virshNodeSuspendTargetTypeToString);
 }
+
+char **
+virshVirtTypeCompleter(vshControl *ctl G_GNUC_UNUSED,
+                       const vshCmd *cmd G_GNUC_UNUSED,
+                       unsigned int flags)
+{
+    virCheckFlags(0, NULL);
+
+    return virshEnumComplete(VIR_DOMAIN_VIRT_LAST,
+                             virDomainVirtTypeToString);
+}
diff --git a/tools/virsh-completer-host.h b/tools/virsh-completer-host.h
index e71ccff..372ac14 100644
--- a/tools/virsh-completer-host.h
+++ b/tools/virsh-completer-host.h
@@ -41,3 +41,8 @@ char **
 virshNodeSuspendTargetCompleter(vshControl *ctl,
                                 const vshCmd *cmd,
                                 unsigned int flags);
+
+char **
+virshVirtTypeCompleter(vshControl *ctl,
+                       const vshCmd *cmd,
+                       unsigned int flags);
diff --git a/tools/virsh-host.c b/tools/virsh-host.c
index 1e83d19..664f9fd 100644
--- a/tools/virsh-host.c
+++ b/tools/virsh-host.c
@@ -77,6 +77,7 @@ static const vshCmdInfo info_domcapabilities[] = {
 static const vshCmdOptDef opts_domcapabilities[] = {
     {.name = "virttype",
      .type = VSH_OT_STRING,
+     .completer = virshVirtTypeCompleter,
      .help = N_("virtualization type (/domain/@type)"),
     },
     {.name = "emulatorbin",
@@ -559,6 +560,7 @@ static const vshCmdInfo info_maxvcpus[] = {
 static const vshCmdOptDef opts_maxvcpus[] = {
     {.name = "type",
      .type = VSH_OT_STRING,
+     .completer = virshVirtTypeCompleter,
      .help = N_("domain type")
     },
     {.name = NULL}
@@ -1577,6 +1579,7 @@ static const vshCmdOptDef opts_hypervisor_cpu_compare[] = {
     VIRSH_COMMON_OPT_FILE(N_("file containing an XML CPU description")),
     {.name = "virttype",
      .type = VSH_OT_STRING,
+     .completer = virshVirtTypeCompleter,
      .help = N_("virtualization type (/domain/@type)"),
     },
     {.name = "emulator",
@@ -1686,6 +1689,7 @@ static const vshCmdOptDef opts_hypervisor_cpu_baseline[] = {
     VIRSH_COMMON_OPT_FILE(N_("file containing XML CPU descriptions")),
     {.name = "virttype",
      .type = VSH_OT_STRING,
+     .completer = virshVirtTypeCompleter,
      .help = N_("virtualization type (/domain/@type)"),
     },
     {.name = "emulator",
-- 
2.35.1
Re: [PATCH 1/3] virsh: Provide completer for virtualization types
Posted by Michal Prívozník 3 years, 10 months ago
On 4/2/22 12:31, Amneesh Singh wrote:
> Related: https://gitlab.com/libvirt/libvirt/-/issues/9
> Signed-off-by: Amneesh Singh <natto@weirdnatto.in>
> ---
>  tools/virsh-completer-host.c | 12 ++++++++++++
>  tools/virsh-completer-host.h |  5 +++++
>  tools/virsh-host.c           |  4 ++++
>  3 files changed, 21 insertions(+)
> 
> diff --git a/tools/virsh-completer-host.c b/tools/virsh-completer-host.c
> index cbdc3f0..14c68d3 100644
> --- a/tools/virsh-completer-host.c
> +++ b/tools/virsh-completer-host.c
> @@ -27,6 +27,7 @@
>  #include "virxml.h"
>  #include "virutil.h"
>  #include "virsh-host.h"
> +#include "conf/domain_conf.h"
>  
>  static char *
>  virshPagesizeNodeToString(xmlNodePtr node)
> @@ -180,3 +181,14 @@ virshNodeSuspendTargetCompleter(vshControl *ctl G_GNUC_UNUSED,
>      return virshEnumComplete(VIR_NODE_SUSPEND_TARGET_LAST,
>                               virshNodeSuspendTargetTypeToString);
>  }
> +
> +char **

Notice how the rest of the file uses two empty lines to separate
functions? It's easier to spot the function you're looking for when
scrolling through file that way.

> +virshVirtTypeCompleter(vshControl *ctl G_GNUC_UNUSED,
> +                       const vshCmd *cmd G_GNUC_UNUSED,
> +                       unsigned int flags)
> +{
> +    virCheckFlags(0, NULL);
> +
> +    return virshEnumComplete(VIR_DOMAIN_VIRT_LAST,
> +                             virDomainVirtTypeToString);
> +}

Michal