-
-
Notifications
You must be signed in to change notification settings - Fork 1.4k
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
With argument autocompletion, context is not passed properly #942
Comments
Im currently not able to test my idea, so please excuse me if for just thinking out loud. 😉 Instead of passing the settings dict to Refer to the documentation for details: |
@LuckyJosh: Thanks for the hint, but that won’t suffice as a workaround. In the above example, I provided completions as a static dictionary just for the sake of simplicity. In my case, a network connection object would be passed via the context, and the |
Alright, in that case I have another idea: After having a glimps at the implementation of The source code I am refering to is in |
I don't understand what LuckyJosh is trying to say. The custom context with It looks to me like we want BaseCommand.main() to create its context in all circumstances, and pass it to _bashcomplete(). Would there be any drawbacks to this? Possibly related: #930 +1 on this issue. I, too, am trying to get autocomplete working with completions that come from network calls. |
To be clear, this issue limits the utility of #755. Until it is fixed, autocompletion callbacks have no clean way to access shared network resources. |
anyone found a workaround on this ? for now i'm doing things like this to at least init state based on env variables before calling out:
this lets the autocompletion work but its unforunate I have to relist the defaults and env parameters here. would be so much nicer if there was a way click could pass the right context or i at least could call something to generate the proper config/context. thx! |
This comment has been minimized.
This comment has been minimized.
I'm facing this issue too. For now, my workaround is to factor out the # cli() function
@click.group
@click.pass_context
def cli(ctx):
ctx.obj = create_context_object()
# example autocomplete function
def get_completion(ctx, args, incomplete):
if ctx.obj is None:
ctx.obj = create_context_object() |
I used the current master revision:
and an executable file
testclick
:and enabled bash completion with
Now I am getting an error when trying to use autocompletion:
Expected behavior was to get a list of completions
abc def ghi
.I am using Python 3.6.4
The text was updated successfully, but these errors were encountered: