[libvirt] [PATCH] virsh: Add a completer for `domifaddr` --source parameter.

Julio Faracco jcfaracco at gmail.com
Fri Jan 3 15:56:09 UTC 2020


Michal,

This case of comma separated options, can we include a comma after
completion by default?
I.e.:

virsh # domifaddr 1 --source [TAB]
agent  arp    lease
virsh # domifaddr 1 --source ar[TAB]
virsh # domifaddr 1 --source arp,

This is easy to test and avoid mistakes.

--
Julio Cesar Faracco

Em sex., 3 de jan. de 2020 às 12:45, Michal Prívozník
<mprivozn at redhat.com> escreveu:
>
> On 1/2/20 4:07 PM, Julio Faracco wrote:
> > The command `domifaddr` can use three different sources to grab IP
> > address of a Virtual Machine: lease, agent and arp. This parameter does
> > not have a completer function to return source options.
> >
> > Signed-off-by: Julio Faracco <jcfaracco at gmail.com>
> > ---
> >  tools/virsh-completer-domain.c | 17 +++++++++++++++++
> >  tools/virsh-completer-domain.h |  5 +++++
> >  tools/virsh-domain-monitor.c   |  1 +
> >  3 files changed, 23 insertions(+)
> >
> > diff --git a/tools/virsh-completer-domain.c b/tools/virsh-completer-domain.c
> > index 0311ee50d0..c8709baa38 100644
> > --- a/tools/virsh-completer-domain.c
> > +++ b/tools/virsh-completer-domain.c
> > @@ -296,3 +296,20 @@ virshDomainShutdownModeCompleter(vshControl *ctl,
> >
> >      return virshCommaStringListComplete(mode, modes);
> >  }
> > +
> > +
> > +char **
> > +virshDomainIfAddrSourceCompleter(vshControl *ctl,
> > +                                 const vshCmd *cmd,
> > +                                 unsigned int flags)
> > +{
> > +    const char *sources[] = {"lease", "agent", "arp", NULL};
> > +    const char *source = NULL;
> > +
> > +    virCheckFlags(0, NULL);
> > +
> > +    if (vshCommandOptStringQuiet(ctl, cmd, "source", &source) < 0)
> > +        return NULL;
> > +
> > +    return virshCommaStringListComplete(source, sources);
>
> Actually, I don't think this is coorect. This helper completes a string
> list separated by commas, for instance a shutdown mode where more than
> one string (method) can be used:
>
>   virsh shutdown --mode acpi,agent,signal
>
> But this is not the case for domifaddr --source, is it? It accepts
> exactly one string. I know Erik pushed this, so I will post a fix up
> later. Stay tuned.
>
> Michal
>





More information about the libvir-list mailing list