mirror of
https://gitlab.com/libvirt/libvirt.git
synced 2024-12-21 21:25:25 +00:00
virsh: Introduce virshEnumComplete()
We have plenty of completers which iterate over all values of given enum and do nothing more than translate every member into string (using corresponding virXXXTypeToString()). Introduce a convenience function so that callers can pass just VIR_XXX_LAST and virXXXTypeToString and the rest is taken care of. Signed-off-by: Michal Privoznik <mprivozn@redhat.com> Reviewed-by: Pavel Hrdina <phrdina@redhat.com>
This commit is contained in:
parent
c21e271d36
commit
d2e8718f3a
@ -57,6 +57,33 @@
|
||||
*/
|
||||
|
||||
|
||||
/**
|
||||
* virshEnumComplete:
|
||||
* @last: The number of element in enum (pass VIR_XXX_LAST)
|
||||
* @intToStr: integer to string conversion (pass virXXXTypeToString)
|
||||
*
|
||||
* Convenient function to generate completions across all values
|
||||
* of given enum. The enum, or values we want to generate, must
|
||||
* start at 0 and be continuous until @last.
|
||||
*
|
||||
* Returns: string list of completions.
|
||||
*/
|
||||
char **
|
||||
virshEnumComplete(unsigned int last,
|
||||
const char *(*intToStr)(int))
|
||||
{
|
||||
char **ret = NULL;
|
||||
size_t i;
|
||||
|
||||
ret = g_new0(char *, last + 1);
|
||||
|
||||
for (i = 0; i < last; i++)
|
||||
ret[i] = g_strdup(intToStr(i));
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* virshCommaStringListComplete:
|
||||
* @input: user input so far
|
||||
|
@ -32,6 +32,10 @@
|
||||
#include "virsh-completer-snapshot.h"
|
||||
#include "virsh-completer-volume.h"
|
||||
|
||||
char **
|
||||
virshEnumComplete(unsigned int last,
|
||||
const char *(*intToStr)(int));
|
||||
|
||||
char **
|
||||
virshCommaStringListComplete(const char *input,
|
||||
const char **options);
|
||||
|
Loading…
Reference in New Issue
Block a user