carapace-sh / carapace-bin

multi-shell multi-command argument completer
https://carapace.sh
MIT License
861 stars 47 forks source link

Add completer for tox 4 #2415

Closed samuelallan72 closed 2 months ago

samuelallan72 commented 3 months ago

Add completions for https://tox.wiki/ (based on tox 4.13)

samuelallan72 commented 3 months ago

Hi @rsteube , I'm interested in adding support for tox and happy to work on it. I've done some digging into the codebase and started a very basic PoC here. Would you be interested in this feature? I may need some guidance during the process, as this would be the first time working with the project or these Go libraries.

rsteube commented 3 months ago

Probably best to use the parser here to create the initial command structure: https://github.com/carapace-sh/carapace-bin/tree/master/cmd/carapace-parse

I need to update the docs for it but see the first minute for how it works: https://asciinema.org/a/466859

Store the help output (if available) or https://tox.wiki/en/latest/cli_interface.html of a command (root or subcommand) in a text file.

Prepare it a bit for parsing (something like this): -s, --long shorthand singlespace longhand 2+ space then description -v, --value VALUE same but accepts a value (single space and some text) --longonly only longhand -s only shorthand

It can handle some variants, but it's just a simple regex.

cat root.txt | carapace-parse -n tox -s "tox root command" > root.go
cat sub.txt | carapace-parse -n sub -p root -s "subcommand of root" > sub.go
cat susbsub2.txt | carapace-parse -n sub2 -p sub -s "subcommand of sub" > sub_sub2.go
samuelallan72 commented 3 months ago

Thanks for your tip about carapace-parse! :smile: That's jumpstarted it. I also applied your suggestions. Still a work in progress though.

samuelallan72 commented 2 months ago

@rsteube the completer should be complete now, and ready for review. :)

rsteube commented 2 months ago

Made some minor changes. Just open an issue/pr if I botched something.

Thanks!

samuelallan72 commented 2 months ago

Thanks for your feedback and the merge! :grin: