]> git.ipfire.org Git - thirdparty/libvirt.git/commitdiff
tools: Introduce virshNodedevCapabilityNameCompleter
authorMichal Privoznik <mprivozn@redhat.com>
Fri, 14 Jun 2019 12:27:13 +0000 (14:27 +0200)
committerMichal Privoznik <mprivozn@redhat.com>
Thu, 18 Jul 2019 14:53:33 +0000 (16:53 +0200)
This is a very simple completer for completing --cap argument of
nodedev-list command.

Signed-off-by: Michal Privoznik <mprivozn@redhat.com>
Reviewed-by: Ján Tomko <jtomko@redhat.com>
Reviewed-by: Erik Skultety <eskultet@redhat.com>
tools/virsh-completer.c
tools/virsh-completer.h
tools/virsh-nodedev.c

index ef2f39320e016b24aefdde1ac9a082c8329654ca..37f946d4b60dd0f15214f88002707b634147b7d4 100644 (file)
@@ -34,6 +34,7 @@
 #include "virmacaddr.h"
 #include "virstring.h"
 #include "virxml.h"
+#include "conf/node_device_conf.h"
 
 
 /**
@@ -975,6 +976,32 @@ virshNodedevEventNameCompleter(vshControl *ctl ATTRIBUTE_UNUSED,
 }
 
 
+char **
+virshNodedevCapabilityNameCompleter(vshControl *ctl,
+                                    const vshCmd *cmd,
+                                    unsigned int flags)
+{
+    VIR_AUTOSTRINGLIST tmp = NULL;
+    const char *cap_str = NULL;
+    size_t i = 0;
+
+    virCheckFlags(0, NULL);
+
+    if (vshCommandOptStringQuiet(ctl, cmd, "cap", &cap_str) < 0)
+        return NULL;
+
+    if (VIR_ALLOC_N(tmp, VIR_NODE_DEV_CAP_LAST + 1) < 0)
+        return NULL;
+
+    for (i = 0; i < VIR_NODE_DEV_CAP_LAST; i++) {
+        if (VIR_STRDUP(tmp[i], virNodeDevCapTypeToString(i)) < 0)
+            return NULL;
+    }
+
+    return virshCommaStringListComplete(cap_str, (const char **)tmp);
+}
+
+
 char **
 virshCellnoCompleter(vshControl *ctl,
                      const vshCmd *cmd ATTRIBUTE_UNUSED,
index 9b3951f4fdbe1a43d50b3829922c236d78b51774..cb7aafcc8c2f343493cfcc105491f39df3e98607 100644 (file)
@@ -106,6 +106,10 @@ char ** virshNodedevEventNameCompleter(vshControl *ctl,
                                        const vshCmd *cmd,
                                        unsigned int flags);
 
+char ** virshNodedevCapabilityNameCompleter(vshControl *ctl,
+                                            const vshCmd *cmd,
+                                            unsigned int flags);
+
 char ** virshDomainDeviceAliasCompleter(vshControl *ctl,
                                         const vshCmd *cmd,
                                         unsigned int flags);
index 0dfefe3a2fe3a188997c7713fa78c7778bb4bf8b..e8372a4daf5f3761584b2932edb12dd9474a775e 100644 (file)
@@ -375,6 +375,7 @@ static const vshCmdOptDef opts_node_list_devices[] = {
     },
     {.name = "cap",
      .type = VSH_OT_STRING,
+     .completer = virshNodedevCapabilityNameCompleter,
      .help = N_("capability names, separated by comma")
     },
     {.name = NULL}