From cac6d413f9c6ab4b32d3cf506bad1e233d087fbd Mon Sep 17 00:00:00 2001 From: Lin Ma Date: Thu, 24 May 2018 15:16:26 +0200 Subject: [PATCH] virsh: Add event name completion to 'pool-event' command Signed-off-by: Lin Ma Signed-off-by: Michal Privoznik --- tools/virsh-completer.c | 26 ++++++++++++++++++++++++++ tools/virsh-completer.h | 4 ++++ tools/virsh-pool.c | 1 + 3 files changed, 31 insertions(+) diff --git a/tools/virsh-completer.c b/tools/virsh-completer.c index 6fb56ebfdc..0502782033 100644 --- a/tools/virsh-completer.c +++ b/tools/virsh-completer.c @@ -703,3 +703,29 @@ virshDomainEventNameCompleter(vshControl *ctl ATTRIBUTE_UNUSED, virStringListFree(ret); return NULL; } + + +char ** +virshPoolEventNameCompleter(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_STORAGE_POOL_EVENT_ID_LAST) < 0) + goto error; + + for (i = 0; i < VIR_STORAGE_POOL_EVENT_ID_LAST; i++) { + if (VIR_STRDUP(ret[i], virshPoolEventCallbacks[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 8763c4e2ed..b02b49ce4a 100644 --- a/tools/virsh-completer.h +++ b/tools/virsh-completer.h @@ -86,4 +86,8 @@ char ** virshDomainEventNameCompleter(vshControl *ctl, const vshCmd *cmd, unsigned int flags); +char ** virshPoolEventNameCompleter(vshControl *ctl, + const vshCmd *cmd, + unsigned int flags); + #endif diff --git a/tools/virsh-pool.c b/tools/virsh-pool.c index 0145b4430b..cc49a5b96d 100644 --- a/tools/virsh-pool.c +++ b/tools/virsh-pool.c @@ -2098,6 +2098,7 @@ static const vshCmdOptDef opts_pool_event[] = { }, {.name = "event", .type = VSH_OT_STRING, + .completer = virshPoolEventNameCompleter, .help = N_("which event type to wait for") }, {.name = "loop", -- 2.39.5