From: Lin Ma Date: Wed, 23 May 2018 06:32:40 +0000 (+0800) Subject: virsh: Add event name completion to 'secret-event' command X-Git-Tag: v4.4.0-rc1~82 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=266965452ac3ab28304798dd84de99d588545dc0;p=thirdparty%2Flibvirt.git virsh: Add event name completion to 'secret-event' command The patch code originally authored by Michal Privoznik, Please refer to https://www.redhat.com/archives/libvir-list/2018-May/msg01022.html Signed-off-by: Lin Ma Signed-off-by: Michal Privoznik --- diff --git a/tools/virsh-completer.c b/tools/virsh-completer.c index cbd5326d0f..da9d636c76 100644 --- a/tools/virsh-completer.c +++ b/tools/virsh-completer.c @@ -26,6 +26,7 @@ #include "virsh.h" #include "virsh-pool.h" #include "virsh-util.h" +#include "virsh-secret.h" #include "internal.h" #include "virutil.h" #include "viralloc.h" @@ -649,3 +650,29 @@ virshAllocpagesPagesizeCompleter(vshControl *ctl, VIR_FREE(ret); goto cleanup; } + + +char ** +virshSecretEventNameCompleter(vshControl *ctl ATTRIBUTE_UNUSED, + const vshCmd *cmd ATTRIBUTE_UNUSED, + unsigned int flags) +{ + size_t i; + char **ret = NULL; + + virCheckFlags(0, NULL); + + if (VIR_ALLOC_N(ret, VIR_SECRET_EVENT_ID_LAST) < 0) + goto error; + + for (i = 0; i < VIR_SECRET_EVENT_ID_LAST; i++) { + if (VIR_STRDUP(ret[i], virshSecretEventCallbacks[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 c7b181879e..c662267882 100644 --- a/tools/virsh-completer.h +++ b/tools/virsh-completer.h @@ -78,4 +78,8 @@ char ** virshAllocpagesPagesizeCompleter(vshControl *ctl, const vshCmd *cmd, unsigned int flags); +char ** virshSecretEventNameCompleter(vshControl *ctl, + const vshCmd *cmd, + unsigned int flags); + #endif diff --git a/tools/virsh-secret.c b/tools/virsh-secret.c index f4dd83b981..670beea706 100644 --- a/tools/virsh-secret.c +++ b/tools/virsh-secret.c @@ -671,6 +671,7 @@ static const vshCmdOptDef opts_secret_event[] = { }, {.name = "event", .type = VSH_OT_STRING, + .completer = virshSecretEventNameCompleter, .help = N_("which event type to wait for") }, {.name = "loop",