Closed tiangolo closed 1 year ago
nice 👍
Out of curiosity, is this PR still relevant? I have the feeling that this is now done on click.
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!
:sparkles: Add support for user
autocompletion
functions.The current implementation provides completion for options, arguments, and sub-commands with help strings. But if the user provides an
autocompletion
function 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_choices
return 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.toml
with:And a file
typertest/__init__.py
Then you can install it with:
With that, you can test with: