Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add completer for tox 4 #2415

Merged
merged 18 commits into from
Jul 8, 2024
Merged

Add completer for tox 4 #2415

merged 18 commits into from
Jul 8, 2024

Conversation

samuelallan72
Copy link
Contributor

@samuelallan72 samuelallan72 commented Jun 19, 2024

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

Add completions for https://tox.wiki/

WIP, there are many completions to add.
Also need to consider how to support tox3 vs tox4.
@samuelallan72
Copy link
Contributor Author

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
Copy link
Member

rsteube commented Jun 20, 2024

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

- pipe all the 'tox subcommand --help' outputs to carapace-parse
- some minor manual editing
@samuelallan72
Copy link
Contributor Author

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

@samuelallan72 samuelallan72 marked this pull request as ready for review July 8, 2024 11:52
@samuelallan72 samuelallan72 changed the title WIP: add completer for tox Add completer for tox 4 Jul 8, 2024
@samuelallan72
Copy link
Contributor Author

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

Copy link
Member

@rsteube rsteube left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

  • common.go

Files in cmd generally represent a (sub)command.
Moved functions to root.go for consistency since they are small enough.
In another case I've put these in a common subfolder (alternative).

  • snake_case

Go uses camelCase.

  • verbose/quiet

Cobra has Count for this kind of flags.

  • Common Flags

Seems these are used in every command.
Cobra has PersistentFlags which passes them on to subcommands.
It also hides them for subcommands when they are already set on the parent.

  • Files / Folder

File completion is explicit in Carapace and needs to be set.
So there is no fallback as shells normally do.
The venv folder name is arbitrary, but it can be an absolute path so folder completion is still beneficial.

  • discover, f, m

This is a weird (bad) pattern in some python commands where flags can consume multiple arguments.
I've got basic support for it with Nargs.

  • StyleF(style.ForKeyword)

No need for this, but highlights positive/negative/arbitrary keywords (like true/false) in colors.

  • PreInvoke

This changes the workdir for all actions based on the workdir flag value.
(Assuming this is what the flag is meant for)

@rsteube rsteube merged commit 3dab9d3 into carapace-sh:master Jul 8, 2024
3 checks passed
@rsteube
Copy link
Member

rsteube commented Jul 8, 2024

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

Thanks!

@samuelallan72
Copy link
Contributor Author

Thanks for your feedback and the merge! 😁

@samuelallan72 samuelallan72 deleted the tox branch July 9, 2024 00:00
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants