3 ms·
what i have yet to figure out is how i can make the commands that i build work with auto-completion. i have never been able to find a good guide. anyone have a
by nkcmr 8y ago
what i have yet to figure out is how i can make the commands that i build work with auto-completion. i have never been able to find a good guide. anyone have a good resource/library (in Go) that can help me with this?
- fouc 8y agoIt is actually done with bash or zsh extensions that you'll need to make for that to happen.
- jorge-fundido 8y agoMy approach is to copy, paste, & tailor the programmable completion for a command that has similar interface to my mine. Can try browsing /usr/local/share/bash-completions/completions or `set` & search for _FOO. Hopefully the special variables like COMPREPLY will be self-explanatory. Also `help compgen`. I'm assuming bash, by the way.
- TheAndruu 8y agoAdd an environment variable for `GOBIN`, like this in `~/.bashrc` export GOBIN=$GOPATH/bin export PATH=$PATH:$GOBIN Now, whenever you run `go install filename.go`, you'll automatically be able to run it anywhere on your machine.
- pgwhalen 8y agoAre you familiar with https://github.com/spf13/cobra https://github.com/spf13/cobra? It's used by a few heavy hitters (kubernetes's kubectl) and it provides you a bit of help with bash completion: https://github.com/spf13/cobra/blob/master/bash_completions.md https://github.com/spf13/cobra/blob/master/bash_completions.... I just added bash completion to a few internal tools that work with kafka, basically just autocompleting topics. It was a little harder than I would have liked (who wants to write all that bash), and I had to fix a bug in Cobra, but overall it wasn't that bad. I'm actually at Gophercon right now, if anyone wants to hack on Cobra at the community day on Thursday to make this easier, shoot me an email (@gmail).