virsh: Introduce virshPoolTypeCompleter

This completer can be used to complete pool types.

Signed-off-by: Michal Privoznik <mprivozn@redhat.com>
Reviewed-by: Jonathon Jongsma <jjongsma@redhat.com>
This commit is contained in:
Michal Privoznik 2019-07-19 10:25:19 +02:00
parent 37dbf05f28
commit a9e8f7f63d
3 changed files with 32 additions and 0 deletions

View File

@ -21,6 +21,7 @@
#include <config.h>
#include "virsh-completer-pool.h"
#include "conf/storage_conf.h"
#include "viralloc.h"
#include "virsh-pool.h"
#include "virsh.h"
@ -91,3 +92,29 @@ virshPoolEventNameCompleter(vshControl *ctl ATTRIBUTE_UNUSED,
VIR_STEAL_PTR(ret, tmp);
return ret;
}
char **
virshPoolTypeCompleter(vshControl *ctl,
const vshCmd *cmd,
unsigned int flags)
{
VIR_AUTOSTRINGLIST tmp = NULL;
const char *type_str = NULL;
size_t i = 0;
virCheckFlags(0, NULL);
if (vshCommandOptStringQuiet(ctl, cmd, "type", &type_str) < 0)
return NULL;
if (VIR_ALLOC_N(tmp, VIR_STORAGE_POOL_LAST + 1) < 0)
return NULL;
for (i = 0; i < VIR_STORAGE_POOL_LAST; i++) {
if (VIR_STRDUP(tmp[i], virStoragePoolTypeToString(i)) < 0)
return NULL;
}
return virshCommaStringListComplete(type_str, (const char **)tmp);
}

View File

@ -29,3 +29,7 @@ char ** virshStoragePoolNameCompleter(vshControl *ctl,
char ** virshPoolEventNameCompleter(vshControl *ctl,
const vshCmd *cmd,
unsigned int flags);
char ** virshPoolTypeCompleter(vshControl *ctl,
const vshCmd *cmd,
unsigned int flags);

View File

@ -1095,6 +1095,7 @@ static const vshCmdOptDef opts_pool_list[] = {
},
{.name = "type",
.type = VSH_OT_STRING,
.completer = virshPoolTypeCompleter,
.help = N_("only list pool of specified type(s) (if supported)")
},
{.name = "details",