From 66d66081487f0579cb5f61343b231a5615a54e8f Mon Sep 17 00:00:00 2001 From: Lin Ma Date: Wed, 23 May 2018 14:32:42 +0800 Subject: [PATCH] virsh: Add event name completion to 'event' command Signed-off-by: Lin Ma Signed-off-by: Michal Privoznik --- tools/virsh-completer.c | 27 +++++++++++++++++++++++++++ tools/virsh-completer.h | 4 ++++ tools/virsh-domain.c | 1 + 3 files changed, 32 insertions(+) diff --git a/tools/virsh-completer.c b/tools/virsh-completer.c index da9d636c76..6fb56ebfdc 100644 --- a/tools/virsh-completer.c +++ b/tools/virsh-completer.c @@ -23,6 +23,7 @@ #include #include "virsh-completer.h" +#include "virsh-domain.h" #include "virsh.h" #include "virsh-pool.h" #include "virsh-util.h" @@ -676,3 +677,29 @@ virshSecretEventNameCompleter(vshControl *ctl ATTRIBUTE_UNUSED, virStringListFree(ret); return NULL; } + + +char ** +virshDomainEventNameCompleter(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_DOMAIN_EVENT_ID_LAST + 1) < 0) + goto error; + + for (i = 0; i < VIR_DOMAIN_EVENT_ID_LAST; i++) { + if (VIR_STRDUP(ret[i], virshDomainEventCallbacks[i].name) < 0) + goto error; + } + + return ret; + + error: + virStringListFree(ret); + return NULL; +} diff --git a/tools/virsh-completer.h b/tools/virsh-completer.h index c662267882..8763c4e2ed 100644 --- a/tools/virsh-completer.h +++ b/tools/virsh-completer.h @@ -82,4 +82,8 @@ char ** virshSecretEventNameCompleter(vshControl *ctl, const vshCmd *cmd, unsigned int flags); +char ** virshDomainEventNameCompleter(vshControl *ctl, + const vshCmd *cmd, + unsigned int flags); + #endif diff --git a/tools/virsh-domain.c b/tools/virsh-domain.c index 202b7406e2..465574198a 100644 --- a/tools/virsh-domain.c +++ b/tools/virsh-domain.c @@ -13339,6 +13339,7 @@ static const vshCmdOptDef opts_event[] = { 0), {.name = "event", .type = VSH_OT_STRING, + .completer = virshDomainEventNameCompleter, .help = N_("which event type to wait for") }, {.name = "all", -- GitLab