]> xenbits.xensource.com Git - libvirt.git/commitdiff
virsh: Add event name completion to 'network-event' command
authorLin Ma <lma@suse.com>
Tue, 5 Mar 2019 03:17:39 +0000 (11:17 +0800)
committerMichal Privoznik <mprivozn@redhat.com>
Tue, 5 Mar 2019 08:09:48 +0000 (09:09 +0100)
Signed-off-by: Lin Ma <lma@suse.com>
tools/virsh-completer.c
tools/virsh-completer.h
tools/virsh-network.c

index 7c68e2e832e2d4b26f900bc4953da658a0d5c5ee..c4adbb70d09ca1c396e22ea4857df673d9ddce2c 100644 (file)
@@ -27,6 +27,7 @@
 #include "virsh-nodedev.h"
 #include "virsh-util.h"
 #include "virsh-secret.h"
+#include "virsh-network.h"
 #include "internal.h"
 #include "virutil.h"
 #include "viralloc.h"
@@ -415,6 +416,32 @@ virshNetworkNameCompleter(vshControl *ctl,
 }
 
 
+char **
+virshNetworkEventNameCompleter(vshControl *ctl ATTRIBUTE_UNUSED,
+                               const vshCmd *cmd ATTRIBUTE_UNUSED,
+                               unsigned int flags)
+{
+    size_t i = 0;
+    char **ret = NULL;
+
+    virCheckFlags(0, NULL);
+
+    if (VIR_ALLOC_N(ret, VIR_NETWORK_EVENT_ID_LAST + 1) < 0)
+        goto error;
+
+    for (i = 0; i < VIR_NETWORK_EVENT_ID_LAST; i++) {
+        if (VIR_STRDUP(ret[i], virshNetworkEventCallbacks[i].name) < 0)
+            goto error;
+    }
+
+    return ret;
+
+ error:
+    virStringListFree(ret);
+    return NULL;
+}
+
+
 char **
 virshNodeDeviceNameCompleter(vshControl *ctl,
                              const vshCmd *cmd ATTRIBUTE_UNUSED,
index 4563fd76ac70b81cc05c9cde06932f264b5958e1..2e2e1edafb58691c6f9c8ba711dad925eb4b61e5 100644 (file)
@@ -55,6 +55,10 @@ char ** virshNetworkNameCompleter(vshControl *ctl,
                                   const vshCmd *cmd,
                                   unsigned int flags);
 
+char ** virshNetworkEventNameCompleter(vshControl *ctl,
+                                       const vshCmd *cmd,
+                                       unsigned int flags);
+
 char ** virshNodeDeviceNameCompleter(vshControl *ctl,
                                      const vshCmd *cmd,
                                      unsigned int flags);
index d5b3649050ef7bfb7f4367b3bc2199eb3e23bc44..9adc63a8fa442432a4a029924e82fae057412c46 100644 (file)
@@ -1216,6 +1216,7 @@ static const vshCmdOptDef opts_network_event[] = {
     VIRSH_COMMON_OPT_NETWORK_OT_STRING(N_("filter by network name or uuid"), 0),
     {.name = "event",
      .type = VSH_OT_STRING,
+     .completer = virshNetworkEventNameCompleter,
      .help = N_("which event type to wait for")
     },
     {.name = "loop",