go-arg icon indicating copy to clipboard operation
go-arg copied to clipboard

Completion support

Open 3noch opened this issue 3 years ago • 20 comments

I love the design of this library. However I could not find any information about generating completion scripts from the reflected CLI. This would be a fantastic addition!

3noch avatar Jul 02 '22 03:07 3noch

Oh this would be great! I will likely look into this in the near future.

alexflint avatar Jul 02 '22 12:07 alexflint

Here is a library that sets up a separate binary that provides completion support for the primary binary: https://github.com/posener/complete/tree/master

Ultimately, completions are installed into bash by appending a complete -C command to .bashrc: https://github.com/posener/complete/blob/master/install/bash.go#L36

Here is how it looks for the go build system: https://github.com/posener/complete/blob/05b68ffc813dd10c420993cb1cf927b346c057b8/gocomplete/complete.go

alexflint avatar Jul 03 '22 16:07 alexflint

I've seen tools add an optional subcommand like app generate-completions that is automatically derived by the CLI library, similar to how --help is derived automatically.

3noch avatar Jul 04 '22 15:07 3noch

Tagging as planned for v2

alexflint avatar Oct 29 '22 16:10 alexflint