Re: [PATCH 05/14] vsh: Introduce '--completers-missing' for 'self-test' command

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

 



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@xxxxxxxxxx>
> ---
>  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().

> +            !opt->completer)
> +            virBufferStrcat(&complbuf, opt->name, ", ", NULL);
> +
>          switch (opt->type) {
>          case VSH_OT_STRING:
>          case VSH_OT_BOOL:

Michal




[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]

  Powered by Linux