tools: Introduce virshNodedevCapabilityNameCompleter

This is a very simple completer for completing --cap argument of
nodedev-list command.

Signed-off-by: Michal Privoznik <mprivozn@redhat.com>
Reviewed-by: Ján Tomko <jtomko@redhat.com>
Reviewed-by: Erik Skultety <eskultet@redhat.com>
This commit is contained in:
Michal Privoznik 2019-06-14 14:27:13 +02:00
parent 9ef216ce2d
commit 3f9d0d97a7
3 changed files with 32 additions and 0 deletions

View File

@ -34,6 +34,7 @@
#include "virmacaddr.h"
#include "virstring.h"
#include "virxml.h"
#include "conf/node_device_conf.h"
/**
@ -975,6 +976,32 @@ virshNodedevEventNameCompleter(vshControl *ctl ATTRIBUTE_UNUSED,
}
char **
virshNodedevCapabilityNameCompleter(vshControl *ctl,
const vshCmd *cmd,
unsigned int flags)
{
VIR_AUTOSTRINGLIST tmp = NULL;
const char *cap_str = NULL;
size_t i = 0;
virCheckFlags(0, NULL);
if (vshCommandOptStringQuiet(ctl, cmd, "cap", &cap_str) < 0)
return NULL;
if (VIR_ALLOC_N(tmp, VIR_NODE_DEV_CAP_LAST + 1) < 0)
return NULL;
for (i = 0; i < VIR_NODE_DEV_CAP_LAST; i++) {
if (VIR_STRDUP(tmp[i], virNodeDevCapTypeToString(i)) < 0)
return NULL;
}
return virshCommaStringListComplete(cap_str, (const char **)tmp);
}
char **
virshCellnoCompleter(vshControl *ctl,
const vshCmd *cmd ATTRIBUTE_UNUSED,

View File

@ -106,6 +106,10 @@ char ** virshNodedevEventNameCompleter(vshControl *ctl,
const vshCmd *cmd,
unsigned int flags);
char ** virshNodedevCapabilityNameCompleter(vshControl *ctl,
const vshCmd *cmd,
unsigned int flags);
char ** virshDomainDeviceAliasCompleter(vshControl *ctl,
const vshCmd *cmd,
unsigned int flags);

View File

@ -375,6 +375,7 @@ static const vshCmdOptDef opts_node_list_devices[] = {
},
{.name = "cap",
.type = VSH_OT_STRING,
.completer = virshNodedevCapabilityNameCompleter,
.help = N_("capability names, separated by comma")
},
{.name = NULL}