]> git.ipfire.org Git - thirdparty/libvirt.git/commitdiff
virsh: Add event name completion to 'secret-event' command
authorLin Ma <lma@suse.com>
Wed, 23 May 2018 06:32:40 +0000 (14:32 +0800)
committerMichal Privoznik <mprivozn@redhat.com>
Thu, 24 May 2018 11:34:18 +0000 (13:34 +0200)
The patch code originally authored by Michal Privoznik, Please refer to
https://www.redhat.com/archives/libvir-list/2018-May/msg01022.html

Signed-off-by: Lin Ma <lma@suse.com>
Signed-off-by: Michal Privoznik <mprivozn@redhat.com>
tools/virsh-completer.c
tools/virsh-completer.h
tools/virsh-secret.c

index cbd5326d0f4cb612136db7879f42826989bfaa40..da9d636c76e68a46cc9754a2397d0a1cbd4d1d3d 100644 (file)
@@ -26,6 +26,7 @@
 #include "virsh.h"
 #include "virsh-pool.h"
 #include "virsh-util.h"
+#include "virsh-secret.h"
 #include "internal.h"
 #include "virutil.h"
 #include "viralloc.h"
@@ -649,3 +650,29 @@ virshAllocpagesPagesizeCompleter(vshControl *ctl,
     VIR_FREE(ret);
     goto cleanup;
 }
+
+
+char **
+virshSecretEventNameCompleter(vshControl *ctl ATTRIBUTE_UNUSED,
+                              const vshCmd *cmd ATTRIBUTE_UNUSED,
+                              unsigned int flags)
+{
+    size_t i;
+    char **ret = NULL;
+
+    virCheckFlags(0, NULL);
+
+    if (VIR_ALLOC_N(ret, VIR_SECRET_EVENT_ID_LAST) < 0)
+        goto error;
+
+    for (i = 0; i < VIR_SECRET_EVENT_ID_LAST; i++) {
+        if (VIR_STRDUP(ret[i], virshSecretEventCallbacks[i].name) < 0)
+            goto error;
+    }
+
+    return ret;
+
+ error:
+    virStringListFree(ret);
+    return NULL;
+}
index c7b181879eb75980bc7afbdc79520d86c87ac0dc..c662267882d1ae7b50685bacd2d4000d9048d485 100644 (file)
@@ -78,4 +78,8 @@ char ** virshAllocpagesPagesizeCompleter(vshControl *ctl,
                                     const vshCmd *cmd,
                                     unsigned int flags);
 
+char ** virshSecretEventNameCompleter(vshControl *ctl,
+                                      const vshCmd *cmd,
+                                      unsigned int flags);
+
 #endif
index f4dd83b9811c8fefd024b952c525657bfaec5f86..670beea706ad39989137828a66210d3a999d3f1a 100644 (file)
@@ -671,6 +671,7 @@ static const vshCmdOptDef opts_secret_event[] = {
     },
     {.name = "event",
      .type = VSH_OT_STRING,
+     .completer = virshSecretEventNameCompleter,
      .help = N_("which event type to wait for")
     },
     {.name = "loop",