]> git.ipfire.org Git - thirdparty/libvirt.git/commitdiff
virsh: Introduce virshPoolTypeCompleter
authorMichal Privoznik <mprivozn@redhat.com>
Fri, 19 Jul 2019 08:25:19 +0000 (10:25 +0200)
committerMichal Privoznik <mprivozn@redhat.com>
Fri, 9 Aug 2019 07:20:13 +0000 (09:20 +0200)
This completer can be used to complete pool types.

Signed-off-by: Michal Privoznik <mprivozn@redhat.com>
Reviewed-by: Jonathon Jongsma <jjongsma@redhat.com>
tools/virsh-completer-pool.c
tools/virsh-completer-pool.h
tools/virsh-pool.c

index fc01550908f6d7e92c2b3ab3fdd13e5dda9f7b85..9703589522fa9ef3697339d4ab95f883d28d2b7c 100644 (file)
@@ -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);
+}
index 778ab25df2536528d9efb3b5faefb0180c3f83a9..510233fb65e9581cd2e17af8f4d9e167a48af0be 100644 (file)
@@ -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);
index 510d41b508fc50ecfc96ad8292e7d0bff8db2b38..96ef6263469e0f94b0ccb168066b8db48f20da1a 100644 (file)
@@ -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",