~emersion/hut-dev

3 2

Handling auto-completion

Details
Message ID
<20211229012903.wgkrjvjiwszea4e6@xenrox.net>
DKIM signature
missing
Download raw message
One user of the hut aur package has asked me today to ship
auto-completions with the PKGBUILD [1]. As Simon has written [2] the
default auto-completion is quite faulty and writing it by hand would be
better so I am not sure about following that request.

There is an alternative I have used for srhtctl. We can fine tune
the completion with e.g. ValidArgsFunction to only allow specific files
[3] [4] or disable file completion for certain flags [5].
While this adds a bit of complexity to the code, the resulting
completion is quite good from my experience and we could ship
completions sooner than if we completely write them by hand.

[1]: https://aur.archlinux.org/packages/hut-git/
[2]: https://lists.sr.ht/~emersion/public-inbox/%3C20211219181302.32435-1-mail%40hmachet.com%3E
[3]: https://git.xenrox.net/~xenrox/srhtctl/tree/master/item/cmd/builds.go#L23
[4]: https://git.xenrox.net/~xenrox/srhtctl/tree/master/item/cmd/completion.go#L32
[5]: https://git.xenrox.net/~xenrox/srhtctl/tree/master/item/cmd/git.go#L29
Details
Message ID
<myjB29f-Urg20FUVhMCKHEdJQaMODXqmIyYtvJ5GZZnzETDUCA-Hyq2YI57l_Kqnv9JG1-kGKUuTsF65ulgXzbNOI06yO6bpeB3tYKxamXA=@emersion.fr>
In-Reply-To
<20211229012903.wgkrjvjiwszea4e6@xenrox.net> (view parent)
DKIM signature
missing
Download raw message
On Wednesday, December 29th, 2021 at 02:29, Thorben Günther <admin@xenrox.net> wrote:

> One user of the hut aur package has asked me today to ship
> auto-completions with the PKGBUILD [1]. As Simon has written [2] the
> default auto-completion is quite faulty and writing it by hand would be
> better so I am not sure about following that request.
>
> There is an alternative I have used for srhtctl. We can fine tune
> the completion with e.g. ValidArgsFunction to only allow specific files
> [3] [4] or disable file completion for certain flags [5].
> While this adds a bit of complexity to the code, the resulting
> completion is quite good from my experience and we could ship
> completions sooner than if we completely write them by hand.

This is still not enough IMHO. When typing --visibility<tab> a good
auto-completion would suggest public/private/unlisted. When typing --repo<tab>
a good auto-completion would list recently used repositories. When typing
--rev<tab> a good auto-completion would list Git tags.

The fish completions can do this for most git commands at least. Is it possible
to do similar things while relying only on cobra's stuff?

(Another thing is that I'm not 100% sure I want to stick with cobra on the long
term. But let's keep this for later.)
Details
Message ID
<20211229113254.jzjtkps5fcuxfiwc@xenrox.net>
In-Reply-To
<myjB29f-Urg20FUVhMCKHEdJQaMODXqmIyYtvJ5GZZnzETDUCA-Hyq2YI57l_Kqnv9JG1-kGKUuTsF65ulgXzbNOI06yO6bpeB3tYKxamXA=@emersion.fr> (view parent)
DKIM signature
missing
Download raw message
On Wed, Dec 29, 2021 at 11:16:39AM +0000, Simon Ser wrote:
> This is still not enough IMHO. When typing --visibility<tab> a good
> auto-completion would suggest public/private/unlisted. When typing --repo<tab>
> a good auto-completion would list recently used repositories. When typing
> --rev<tab> a good auto-completion would list Git tags.
>
> The fish completions can do this for most git commands at least. Is it possible
> to do similar things while relying only on cobra's stuff?

At least visibility and rev completion are easily doable:
http://minio.xenrox.net/uploads/86208fbd-1eb3-4207-9b82-dcfd98f39cb5.gif
(expiration completes tags for demo purposes, was just too lazy to
rename here).
Details
Message ID
<EYTzjqqne9h0bjU8xlTORo1e5OgSUlJuUAASwBR6WGfEVFdxTh1qlee-sosc4g7WTbu3tfvCRFNUDC6h69IPgvE2M7yq61PfQfzXZtQG4nk=@emersion.fr>
In-Reply-To
<20211229113254.jzjtkps5fcuxfiwc@xenrox.net> (view parent)
DKIM signature
missing
Download raw message
On Wednesday, December 29th, 2021 at 12:32, Thorben Günther <admin@xenrox.net> wrote:

> On Wed, Dec 29, 2021 at 11:16:39AM +0000, Simon Ser wrote:
> > This is still not enough IMHO. When typing --visibility<tab> a good
> > auto-completion would suggest public/private/unlisted. When typing --repo<tab>
> > a good auto-completion would list recently used repositories. When typing
> > --rev<tab> a good auto-completion would list Git tags.
> >
> > The fish completions can do this for most git commands at least. Is it possible
> > to do similar things while relying only on cobra's stuff?
>
> At least visibility and rev completion are easily doable:
> http://minio.xenrox.net/uploads/86208fbd-1eb3-4207-9b82-dcfd98f39cb5.gif
> (expiration completes tags for demo purposes, was just too lazy to
> rename here).

Oh, I didn't realize that cobra allowed registering a callback for completions.
I thought the callback was a one-off static thing.

Then yeah that sounds good.
Reply to thread Export thread (mbox)