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

[libvirt] [PATCH v2 15/15] virsh: Introduce virshPoolTypeCompleter



This completer can be used to complete pool types.

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

diff --git a/tools/virsh-completer-pool.c b/tools/virsh-completer-pool.c
index fc01550908..9703589522 100644
--- a/tools/virsh-completer-pool.c
+++ b/tools/virsh-completer-pool.c
@@ -21,6 +21,7 @@
 #include <config.h>
 
 #include "virsh-completer-pool.h"
+#include "conf/storage_conf.h"
 #include "viralloc.h"
 #include "virsh-pool.h"
 #include "virsh.h"
@@ -91,3 +92,29 @@ virshPoolEventNameCompleter(vshControl *ctl ATTRIBUTE_UNUSED,
     VIR_STEAL_PTR(ret, tmp);
     return ret;
 }
+
+
+char **
+virshPoolTypeCompleter(vshControl *ctl,
+                       const vshCmd *cmd,
+                       unsigned int flags)
+{
+    VIR_AUTOSTRINGLIST tmp = NULL;
+    const char *type_str = NULL;
+    size_t i = 0;
+
+    virCheckFlags(0, NULL);
+
+    if (vshCommandOptStringQuiet(ctl, cmd, "type", &type_str) < 0)
+        return NULL;
+
+    if (VIR_ALLOC_N(tmp, VIR_STORAGE_POOL_LAST + 1) < 0)
+        return NULL;
+
+    for (i = 0; i < VIR_STORAGE_POOL_LAST; i++) {
+        if (VIR_STRDUP(tmp[i], virStoragePoolTypeToString(i)) < 0)
+            return NULL;
+    }
+
+    return virshCommaStringListComplete(type_str, (const char **)tmp);
+}
diff --git a/tools/virsh-completer-pool.h b/tools/virsh-completer-pool.h
index 778ab25df2..510233fb65 100644
--- a/tools/virsh-completer-pool.h
+++ b/tools/virsh-completer-pool.h
@@ -29,3 +29,7 @@ char ** virshStoragePoolNameCompleter(vshControl *ctl,
 char ** virshPoolEventNameCompleter(vshControl *ctl,
                                     const vshCmd *cmd,
                                     unsigned int flags);
+
+char ** virshPoolTypeCompleter(vshControl *ctl,
+                               const vshCmd *cmd,
+                               unsigned int flags);
diff --git a/tools/virsh-pool.c b/tools/virsh-pool.c
index 510d41b508..96ef626346 100644
--- a/tools/virsh-pool.c
+++ b/tools/virsh-pool.c
@@ -1095,6 +1095,7 @@ static const vshCmdOptDef opts_pool_list[] = {
     },
     {.name = "type",
      .type = VSH_OT_STRING,
+     .completer = virshPoolTypeCompleter,
      .help = N_("only list pool of specified type(s) (if supported)")
     },
     {.name = "details",
-- 
2.21.0


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