Signed-off-by: Lin Ma <lma@xxxxxxxx> --- tools/virsh-completer.c | 37 +++++++++++++++++++++++++++++++++++++ tools/virsh-completer.h | 3 +++ tools/virsh-domain.c | 1 + 3 files changed, 41 insertions(+) diff --git a/tools/virsh-completer.c b/tools/virsh-completer.c index e3b8234b41..ddf7b17caf 100644 --- a/tools/virsh-completer.c +++ b/tools/virsh-completer.c @@ -522,3 +522,40 @@ virshSnapshotNameCompleter(vshControl *ctl, virshDomainFree(dom); return NULL; } + + +char ** +virshEventNameCompleter(vshControl *ctl, + const vshCmd *cmd ATTRIBUTE_UNUSED, + unsigned int flags) +{ + virshControlPtr priv = ctl->privData; + size_t i = 0; + char **ret = NULL; + + virCheckFlags(0, NULL); + + if (!priv->conn || virConnectIsAlive(priv->conn) <= 0) + return 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++) { + const char *name = virshDomainEventGetName(i); + + if (name == NULL) + goto error; + + if (VIR_STRDUP(ret[i], name) < 0) + goto error; + } + + return ret; + + error: + for (i = 0; i < VIR_DOMAIN_EVENT_ID_LAST; i++) + VIR_FREE(ret[i]); + VIR_FREE(ret); + return NULL; +} diff --git a/tools/virsh-completer.h b/tools/virsh-completer.h index fa443d3ad7..27d78dc7ac 100644 --- a/tools/virsh-completer.h +++ b/tools/virsh-completer.h @@ -69,5 +69,8 @@ char ** virshSecretUUIDCompleter(vshControl *ctl, char ** virshSnapshotNameCompleter(vshControl *ctl, const vshCmd *cmd, unsigned int flags); +char ** virshEventNameCompleter(vshControl *ctl, + const vshCmd *cmd, + unsigned int flags); #endif diff --git a/tools/virsh-domain.c b/tools/virsh-domain.c index 36278ebc1c..0d58c0ff1a 100644 --- a/tools/virsh-domain.c +++ b/tools/virsh-domain.c @@ -13357,6 +13357,7 @@ static const vshCmdOptDef opts_event[] = { }, {.name = "event", .type = VSH_OT_ARGV, + .completer = virshEventNameCompleter, .help = N_("which event type to wait for") }, {.name = NULL} -- 2.15.1 -- libvir-list mailing list libvir-list@xxxxxxxxxx https://www.redhat.com/mailman/listinfo/libvir-list