[PATCH 2/2] tools: Introduce virshNodedevCapabilityNameCompleter

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



This is a very simple completer for completing --cap argument of
nodedev-list command.

Signed-off-by: Michal Privoznik <mprivozn@xxxxxxxxxx>
---
 tools/virsh-completer.c | 27 +++++++++++++++++++++++++++
 tools/virsh-completer.h |  4 ++++
 tools/virsh-nodedev.c   |  1 +
 3 files changed, 32 insertions(+)

diff --git a/tools/virsh-completer.c b/tools/virsh-completer.c
index ef2f39320e..37f946d4b6 100644
--- a/tools/virsh-completer.c
+++ b/tools/virsh-completer.c
@@ -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,
diff --git a/tools/virsh-completer.h b/tools/virsh-completer.h
index cd3cc9ecae..d6da6e69f3 100644
--- a/tools/virsh-completer.h
+++ b/tools/virsh-completer.h
@@ -107,6 +107,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);
diff --git a/tools/virsh-nodedev.c b/tools/virsh-nodedev.c
index 0dfefe3a2f..e8372a4daf 100644
--- a/tools/virsh-nodedev.c
+++ b/tools/virsh-nodedev.c
@@ -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}
-- 
2.21.0

--
libvir-list mailing list
libvir-list@xxxxxxxxxx
https://www.redhat.com/mailman/listinfo/libvir-list



[Index of Archives]     [Virt Tools]     [Libvirt Users]     [Lib OS Info]     [Fedora Users]     [Fedora Desktop]     [Fedora SELinux]     [Big List of Linux Books]     [Yosemite News]     [KDE Users]     [Fedora Tools]

  Powered by Linux