Closed matheuscscp closed 1 year ago
. I will investigate this further soon
:pray: thx!
Hi @marcosnils, I tried to hackily instantiate the rootCmd
in a init()
function just to see if it would work, but I'm seeing the same behavior as if I just upgraded the version of cobra, so I need more investigation.
In the meantime I also asked a question in the cobra repo to see if I can get some help: https://github.com/spf13/cobra/issues/1915
hi @marcosnils! I got enough help from cobra and was able to add the default completion
command :grin:
➜ bin git:(completion) go build
➜ bin git:(completion) source <(./bin completion zsh); compdef _bin bin
➜ bin git:(completion) ./bin
completion -- Generate the autocompletion script for the specified shell
ensure -- Ensures that all binaries listed in the configuration are present
help -- Help about any command
install -- Installs the specified project from a url
list -- List binaries managed by bin
prune -- Prunes binaries that no longer exist in the system
remove -- Removes binaries managed by bin
update -- Updates one or multiple binaries managed by bin
:tada: thx for the contribution @matheuscscp !
fixes #155
Hi @marcosnils,
First I tried just upgrading the version of cobra, which indeed adds the default
completion
command:However, the command does not seem to work. It invokes
bin
's first command instead (list
):So I followed the instructions here: https://github.com/spf13/cobra/blob/main/shell_completions.md#creating-your-own-completion-command
And added
cmd/completion.go
with pretty much a copy of the example in those instructions, fixing minor differences to fitbin
's command definition style.Now it works:
go run . completion zsh
also seems to print the completion scripts for zsh. However, they don't seem to work. When I press tab, this is what I see:I wonder if this is because of how
bin
sets up the cobra commands, which is slightly different than usual (via Goinit()
functions)... I will investigate this further soon :ok_hand: