[libvirt] [PATCHv3 5/6] virsh: Add vshSuspendTargetCompleter
Eric Blake
eblake at redhat.com
Mon Aug 26 20:43:30 UTC 2013
On 08/26/2013 06:36 AM, Tomas Meszaros wrote:
> vshSuspendTargetCompleter returns targets available for suspend.
>
> This completer can be used for the command option completion
> (for dompmsuspend, etc.).
>
> virsh> dompmsuspend --target <TAB>
> mem disk hybrid
> virsh> dompmsuspend --target h<TAB>
> virsh> dompmsuspend --target hybrid
> ---
> v2
> * label cleanup renamed to error
> * vshSuspendTargetCompleter added to opts_dom_pm_suspend
>
> v3
> * removed useless if
> * used virStringFreeList() instead of iteration
>
> tools/virsh-domain.c | 3 ++-
> tools/virsh.c | 23 +++++++++++++++++++++++
> tools/virsh.h | 1 +
> 3 files changed, 26 insertions(+), 1 deletion(-)
This patch looks pretty decent, especially since it is installed as a
per-option handler.
>
> +char **
> +vshSuspendTargetCompleter(unsigned int unused_flags ATTRIBUTE_UNUSED)
> +{
> + const char *targets[] = {"mem", "disk", "hybrid"};
> + const unsigned int targets_size = ARRAY_CARDINALITY(targets);
> + char **names = NULL;
> + size_t i;
> +
> + names = vshMalloc(NULL, sizeof(char *) * (targets_size + 1));
> +
> + for (i = 0; i < targets_size; i++) {
> + if (VIR_STRDUP(names[i], targets[i]) < 0)
> + goto error;
> + }
> +
> + names[i] = NULL;
> + return names;
Call me a hacker, but what's wrong with this equivalent implementation
done by reusing existing code:
char **
vshSuspendTargetCompleter(unsigned int ignored ATTRIBUTE_UNUSED)
{
return virStringSplit("mem disk hybrid", " ", 0);
}
--
Eric Blake eblake redhat com +1-919-301-3266
Libvirt virtualization library http://libvirt.org
-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 621 bytes
Desc: OpenPGP digital signature
URL: <http://listman.redhat.com/archives/libvir-list/attachments/20130826/e91ade4a/attachment-0001.sig>
More information about the libvir-list
mailing list