[PATCH 05/14] vsh: Introduce '--completers-missing' for 'self-test' command
Peter Krempa
pkrempa at redhat.com
Fri Sep 17 07:36:35 UTC 2021
On Fri, Sep 17, 2021 at 09:31:13 +0200, Michal Prívozník wrote:
> On 9/16/21 7:10 PM, Peter Krempa wrote:
> > Make it simple to spot which options of which commands are missing
> > autocompletion functions by introducing this hidden option.
> >
> > In the future when we'll have completers for everything this can be also
> > used as a hard fail so that completers are always added.
> >
> > Signed-off-by: Peter Krempa <pkrempa at redhat.com>
> > ---
> > tools/vsh.c | 28 ++++++++++++++++++++++++----
> > tools/vsh.h | 3 ++-
> > 2 files changed, 26 insertions(+), 5 deletions(-)
> >
> > diff --git a/tools/vsh.c b/tools/vsh.c
> > index 05da50eace..9c6783dad1 100644
> > --- a/tools/vsh.c
> > +++ b/tools/vsh.c
> > @@ -261,11 +261,13 @@ vshCmddefGetInfo(const vshCmdDef * cmd, const char *name)
> > /* Check if the internal command definitions are correct */
> > static int
> > vshCmddefCheckInternals(vshControl *ctl,
> > - const vshCmdDef *cmd)
> > + const vshCmdDef *cmd,
> > + bool missingCompleters)
> > {
> > size_t i;
> > const char *help = NULL;
> > bool seenOptionalOption = false;
> > + g_auto(virBuffer) complbuf = VIR_BUFFER_INITIALIZER;
> >
> > /* in order to perform the validation resolve the alias first */
> > if (cmd->flags & VSH_CMD_FLAG_ALIAS) {
> > @@ -309,6 +311,11 @@ vshCmddefCheckInternals(vshControl *ctl,
> > return -1; /* too many options */
> > }
> >
> > + if (missingCompleters &&
> > + (opt->type == VSH_OT_STRING || opt->type == VSH_OT_DATA) &&
>
> Technically, only VSH_OT_BOOL options can't have a completer because
> bool --options don't accept any argument. For everything else the
> completer callback is called (if defined), see vshReadlineParse().
>
> But we can start small and expand later. There is plenty of say
> VSH_OT_ARGV/VSH_OT_INT arguments that can't have completer because their
> value don't depend on anything domain/network/nwfilter/... related. Mind
> you, some DO depend and have completers already:
> virshKeycodeNameCompleter() or virshDomainVcpuCompleter().
Hmm, yeah I kind of forgot about VSH_OT_ARGV. I've specifically omitted
VSH_OT_INT as in most cases it's just taking an arbitrary number form a
range not tied to an object but to a user configuration.
I'll perhaps do another round later.
More information about the libvir-list
mailing list