Suggestions for autocompletion behavior #1
Closed
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.
Implementations of suggestions noted here, with a few differences.
This PR does 3 things:
Allows autocompletion functions to accept a
param: click.core.Parameter
argument. I think this is necessary because without it you can't define generic completer functions that don't know what CLI options or arguments they may be attached to and that need to alter their behavior based on how click has processed the arguments before the incomplete argument. Concrete example: you have an option or argument that accepts multiple values but you do not wish those values to be repeated.Allows CompletionItems to be returned in addition to strings and 2-tuples from autocompletion functions.
Fixes
arg: List[str]
parameter to be passed what it used to be given in click 7 (i.e. the raw command line string minus the script and incomplete string). In click 7 this parameter was being set to the arguments passed in the environment variables via the completion scripts installed on the system that are invoked when you hittab
. These parameters do not show up in ctx.args or sys.argv. Click has a general purpose obj attribute on the context that is available for downstream use. This PR sets that object to a dictionary in the completer classes and attaches the args from the environment variables to it. If obj is already defined it'll just not do that and nothing will break accept the args will be passed as an empty list to the autocompletion functions.I think numbers 1 and 2 are important. Number 3 is mostly for backwards compatibility but I don't think its that critical - I just wanted to show that there is a way to do it.
I did not update the docs but would be happy to if ya'll are inclined to accept this PR.