From 83f1e64dd3288dfa6823a77b2f72d65e57355cde Mon Sep 17 00:00:00 2001 From: Lin Ma Date: Wed, 23 May 2018 14:32:46 +0800 Subject: [PATCH] virsh: Add event name completion to 'nodedev-event' command Signed-off-by: Lin Ma Signed-off-by: Michal Privoznik --- tools/virsh-completer.c | 27 +++++++++++++++++++++++++++ tools/virsh-completer.h | 4 ++++ tools/virsh-nodedev.c | 1 + 3 files changed, 32 insertions(+) diff --git a/tools/virsh-completer.c b/tools/virsh-completer.c index 0502782033..07dccb11e4 100644 --- a/tools/virsh-completer.c +++ b/tools/virsh-completer.c @@ -26,6 +26,7 @@ #include "virsh-domain.h" #include "virsh.h" #include "virsh-pool.h" +#include "virsh-nodedev.h" #include "virsh-util.h" #include "virsh-secret.h" #include "internal.h" @@ -729,3 +730,29 @@ virshPoolEventNameCompleter(vshControl *ctl ATTRIBUTE_UNUSED, virStringListFree(ret); return NULL; } + + +char ** +virshNodedevEventNameCompleter(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_NODE_DEVICE_EVENT_ID_LAST) < 0) + goto error; + + for (i = 0; i < VIR_NODE_DEVICE_EVENT_ID_LAST; i++) { + if (VIR_STRDUP(ret[i], virshNodedevEventCallbacks[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 b02b49ce4a..61dd7e7484 100644 --- a/tools/virsh-completer.h +++ b/tools/virsh-completer.h @@ -90,4 +90,8 @@ char ** virshPoolEventNameCompleter(vshControl *ctl, const vshCmd *cmd, unsigned int flags); +char ** virshNodedevEventNameCompleter(vshControl *ctl, + const vshCmd *cmd, + unsigned int flags); + #endif diff --git a/tools/virsh-nodedev.c b/tools/virsh-nodedev.c index b26cd5cec9..e6f963ea66 100644 --- a/tools/virsh-nodedev.c +++ b/tools/virsh-nodedev.c @@ -870,6 +870,7 @@ static const vshCmdOptDef opts_node_device_event[] = { }, {.name = "event", .type = VSH_OT_STRING, + .completer = virshNodedevEventNameCompleter, .help = N_("which event type to wait for") }, {.name = "loop", -- GitLab