Re: [PATCHv3 5/6] virsh: Add vshSuspendTargetCompleter

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



On 26/08/13 at 02:43pm, Eric Blake wrote:
> 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);
> }

Yeah, this is much better. I will definitely use this.

-- 
Tomas Meszaros

--
libvir-list mailing list
libvir-list@xxxxxxxxxx
https://www.redhat.com/mailman/listinfo/libvir-list




[Index of Archives]     [Virt Tools]     [Libvirt Users]     [Lib OS Info]     [Fedora Users]     [Fedora Desktop]     [Fedora SELinux]     [Big List of Linux Books]     [Yosemite News]     [KDE Users]     [Fedora Tools]