[libvirt] [PATCHv3 2/6] virsh: Add vshCmdCompleter and vshOptCompleter

Eric Blake eblake at redhat.com
Mon Aug 26 17:47:26 UTC 2013


On 08/26/2013 06:36 AM, Tomas Meszaros wrote:
> completer and completer_flags added to the _vshCmdDef and _vshCmdOptDef
> structures so it will be possible for completion generators to
> conveniently call completer functions with desired flags.
> ---
>  tools/virsh.h | 7 +++++++
>  1 file changed, 7 insertions(+)

In isolation, this patch looks reasonable, but I want to see how it gets
used before acking it.

> 
> diff --git a/tools/virsh.h b/tools/virsh.h
> index 466ca2d..064acde 100644
> --- a/tools/virsh.h
> +++ b/tools/virsh.h
> @@ -147,6 +147,9 @@ typedef struct _vshCmdOptDef vshCmdOptDef;
>  typedef struct _vshControl vshControl;
>  typedef struct _vshCtrlData vshCtrlData;
>  
> +typedef char **(*vshCmdCompleter)(unsigned int flags);
> +typedef char **(*vshOptCompleter)(unsigned int flags);

Do we need two typedefs, or is (*vshCompleter) a sufficient reusable name?

> +
>  /*
>   * vshCmdInfo -- name/value pair for information about command
>   *
> @@ -168,6 +171,8 @@ struct _vshCmdOptDef {
>      unsigned int flags;         /* flags */
>      const char *help;           /* non-NULL help string; or for VSH_OT_ALIAS
>                                   * the name of a later public option */
> +    vshOptCompleter completer;  /* option completer */
> +    unsigned int completer_flags;   /* option completer flags */

Per-option completions make sense.  For example, 'virsh vol-key --pool
<TAB>' wants to use a pool completer, while 'virsh vol-key --vol <TAB>'
wants to use a volume completer; furthermore, 'virsh vol-key <TAB>'
should be the combination of the option completer (showing --vol and
--pool) AND the volume completer filtered to names not starting with '-'
(since virsh has the semantics that arguments are positional, where the
option '--vol' is implied if the argument that appears in that position
does not resemble an option).

>  };
>  
>  /*
> @@ -199,6 +204,8 @@ struct _vshCmdDef {
>      const vshCmdOptDef *opts;   /* definition of command options */
>      const vshCmdInfo *info;     /* details about command */
>      unsigned int flags;         /* bitwise OR of VSH_CMD_FLAG */
> +    vshCmdCompleter completer;  /* command completer */
> +    unsigned int completer_flags;   /* command completer flags */
>  };

I'm not so sure about per-command completers, though.  What can a
command complete differently than per-option completers would already
provide?  Maybe this argues that you need more rationale in the commit
message about how this will be used.  Or maybe I'll figure it out by the
time I get to the end of your series.

-- 
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/067c296e/attachment-0001.sig>


More information about the libvir-list mailing list