From 397369853d51951d25ee7f8236d656ae4672c818 Mon Sep 17 00:00:00 2001 From: Lin Ma Date: Tue, 5 Mar 2019 11:17:39 +0800 Subject: [PATCH] virsh: Add event name completion to 'network-event' command Signed-off-by: Lin Ma --- tools/virsh-completer.c | 27 +++++++++++++++++++++++++++ tools/virsh-completer.h | 4 ++++ tools/virsh-network.c | 1 + 3 files changed, 32 insertions(+) diff --git a/tools/virsh-completer.c b/tools/virsh-completer.c index 7c68e2e832..c4adbb70d0 100644 --- a/tools/virsh-completer.c +++ b/tools/virsh-completer.c @@ -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, diff --git a/tools/virsh-completer.h b/tools/virsh-completer.h index 4563fd76ac..2e2e1edafb 100644 --- a/tools/virsh-completer.h +++ b/tools/virsh-completer.h @@ -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); diff --git a/tools/virsh-network.c b/tools/virsh-network.c index d5b3649050..9adc63a8fa 100644 --- a/tools/virsh-network.c +++ b/tools/virsh-network.c @@ -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",