[PATCH 12/12] virsh: Add event name completion to 'event' command

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

 



Signed-off-by: Lin Ma <lma@xxxxxxxx>
---
 tools/virsh-completer.c | 36 ++++++++++++++++++++++++++++++++++++
 tools/virsh-completer.h |  3 +++
 tools/virsh-domain.c    |  1 +
 3 files changed, 40 insertions(+)

diff --git a/tools/virsh-completer.c b/tools/virsh-completer.c
index e3b8234b41..a188a8d7ab 100644
--- a/tools/virsh-completer.c
+++ b/tools/virsh-completer.c
@@ -30,6 +30,7 @@
 #include "viralloc.h"
 #include "virstring.h"
 #include "virxml.h"
+extern const char *virDomainEventGetName(int event);
 
 
 char **
@@ -522,3 +523,38 @@ virshSnapshotNameCompleter(vshControl *ctl,
     virshDomainFree(dom);
     return NULL;
 }
+
+
+char **
+virshEventNameCompleter(vshControl *ctl,
+                        const vshCmd *cmd ATTRIBUTE_UNUSED,
+                        unsigned int flags)
+{
+    virshControlPtr priv = ctl->privData;
+    size_t i = 0;
+    char **ret = NULL;
+
+    virCheckFlags(0, NULL);
+
+    if (!priv->conn || virConnectIsAlive(priv->conn) <= 0)
+        return NULL;
+
+    if (VIR_ALLOC_N(ret, VIR_DOMAIN_EVENT_ID_LAST + 1) < 0)
+        goto error;
+
+    for (i = 0; i < VIR_DOMAIN_EVENT_ID_LAST; i++) {
+        const char *name = virDomainEventGetName(i);
+
+        if (name == NULL)
+            goto error;
+
+        if (VIR_STRDUP(ret[i], name) < 0)
+            goto error;
+    }
+
+    return ret;
+
+error:
+    VIR_FREE(ret);
+    return NULL;
+}
diff --git a/tools/virsh-completer.h b/tools/virsh-completer.h
index fa443d3ad7..27d78dc7ac 100644
--- a/tools/virsh-completer.h
+++ b/tools/virsh-completer.h
@@ -69,5 +69,8 @@ char ** virshSecretUUIDCompleter(vshControl *ctl,
 char ** virshSnapshotNameCompleter(vshControl *ctl,
                                    const vshCmd *cmd,
                                    unsigned int flags);
+char ** virshEventNameCompleter(vshControl *ctl,
+                                const vshCmd *cmd,
+                                unsigned int flags);
 
 #endif
diff --git a/tools/virsh-domain.c b/tools/virsh-domain.c
index e21ba0117b..ce72d414b9 100644
--- a/tools/virsh-domain.c
+++ b/tools/virsh-domain.c
@@ -13369,6 +13369,7 @@ static const vshCmdOptDef opts_event[] = {
     },
     {.name = "event",
      .type = VSH_OT_ARGV,
+     .completer = virshEventNameCompleter,
      .help = N_("which event type to wait for")
     },
     {.name = NULL}
-- 
2.15.1

--
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