garden-rs / garden

Garden grows and cultivates collections of Git trees ~ Official mirror of https://gitlab.com/garden-rs/garden
https://garden-rs.gitlab.io
MIT License
64 stars 9 forks source link

Completion error when no custom commands #10

Closed grymoire7 closed 1 year ago

grymoire7 commented 1 year ago

Errors are returned using tab completion for cmd when no --commands option was provided to garden completion zsh. Other command completions appear to work. Command completion for cmd also appears to work without error after completions are generated with the --commands option. Reproduction steps:

$ uname -mrs
Darwin 21.6.0 x86_64

$ zsh --version
zsh 5.8.1 (x86_64-apple-darwin21.0)

$ garden --version
garden 0.5.0-beta

$ garden completion zsh > $DIR_IN_FPATH/_garden  # no --commands option given

$ garden cmd <tab>
_arguments:comparguments:325: doubled rest argument definition: *::arguments -- Arguments to forward to custom commands:
_arguments:comparguments:325: doubled rest argument definition: *::arguments -- Arguments to forward to custom commands:
_arguments:comparguments:325: doubled rest argument definition: *::arguments -- Arguments to forward to custom commands:

$ garden help <tab>
cmd         -- Run custom commands over gardens
completion  -- Generate shell completions
eval        -- Evaluate garden expressions
exec        -- Run commands inside garden environments
grow        -- Grow garden worktrees into existence
help        -- Print this message or the help of the given subcommand(s)
init        -- Initialize a "garden.yaml" garden configuration file
inspect     -- Query tree status
list        -- List available gardens, groups, trees and commands
plant       -- Add pre-existing worktrees to a garden configuration file
prune       -- Remove unreferenced Git repositories
shell       -- Open a shell in a garden environment
davvid commented 1 year ago

I ran into that bug with the completion for garden cmd as well. I believe this upstream issue is the root cause:

https://github.com/clap-rs/clap/issues/3022

garden cmd is setup the same way as the reproducer in that issue.

When I ran into it I didn't realize that it might be working with --commands so I'll have to give that a try.

If the upstream issues don't get traction then I might just end up manually writing the completions myself, but I've got hope that progress will be made. 🤞

I'll document this shortcoming for now and see if there's anything we can do on our side to deal with it.

davvid commented 1 year ago

https://github.com/clap-rs/clap/issues/3166 looks like it's the headline epic issue that's being used to drive the features forward. We'll have to keep an eye on that one as well.

davvid commented 1 year ago

I was able to come up with a workaround that should hold us over for now. It's not built-in (it requires an extra shell pipeline step) so I documented it and linked to the upstream issue from the documentation.

The fix is simple enough to apply, though. Hope that helps.

https://davvid.github.io/garden/commands.html#zsh

davvid commented 1 year ago

I believe I may have fixed the upstream issue in https://github.com/clap-rs/clap/pull/4612

This would be a great fix to have in place before this feature is released so I'm hoping the fix gets merged soon. Once it's merged we won't need our grep workaround.