virsh: Add event name completion to 'event' command

Signed-off-by: Lin Ma <lma@suse.com>
Signed-off-by: Michal Privoznik <mprivozn@redhat.com>
This commit is contained in:
Lin Ma 2018-05-23 14:32:42 +08:00 committed by Michal Privoznik
parent 05642e8bd1
commit 66d6608148
3 changed files with 32 additions and 0 deletions

View File

@ -23,6 +23,7 @@
#include <config.h>
#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;
}

View File

@ -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

View File

@ -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",