Add support for user autocompletion functions#34
Closed
tiangolo wants to merge 1 commit intoclick-contrib:masterfrom
tiangolo:support-user-completion
Closed
Add support for user autocompletion functions#34tiangolo wants to merge 1 commit intoclick-contrib:masterfrom tiangolo:support-user-completion
tiangolo wants to merge 1 commit intoclick-contrib:masterfrom
tiangolo:support-user-completion
Conversation
|
nice 👍 |
Collaborator
|
Out of curiosity, is this PR still relevant? I have the feeling that this is now done on click. |
Author
|
Yep, I'm pretty sure this is no longer relevant, implemented in Click directly, and also a bit rewritten in Typer. So I"ll close this PR now. Thanks! |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
✨ Add support for user
autocompletionfunctions.The current implementation provides completion for options, arguments, and sub-commands with help strings. But if the user provides an
autocompletionfunction it is not used. Although it would be used by plain Click (only in Bash and Zsh).This PR continues the idea from @chrisjsewell in #27. And adds the ideas in the review from @Konubinix.
I added comments to the sections I added that are a direct copy from Click, to try and minimize confusion by the duplicate code. I updated a couple of parts with logic from Click that is not yet here.
I made
get_choicesreturn a list instead of usingyield, this allows returning early withget_user_autocompletions.Here's an example small app that I used to test it. I wrote it with Typer but I can adapt it to use Click directly if you prefer, if the Typer parts are confusing, etc.
typertest/main.py:If you create a file
pyproject.tomlwith:And a file
typertest/__init__.pyThen you can install it with:
$ poetry installWith that, you can test with: