Skip to content
Myr

Allow dynamic generation of the autocompletion list using a callback.

Before adoption: this commit came in with the history the project adopted, so no landing records it.

The callback receives the following data: - The current click context. This allows the callback to access any parameters that are already present on the command line. - The current word being completed. This may be an empty string. - The bash COMP_CWORDS and COMP_CWORD variables, in case the callback wants to do raw parsing of this data.

authored by Brett Bethke · committed by Brett Bethke · parent 8e35beb · Browse files · 1 file+7 added−1 removed
This commit

State

Before adoption: this commit came in with the history the project adopted, so no landing records it.

Diff stats

1 file+7 added−1 removed

  • other:+7 added−1 removed

1 file+7 added−1 removed

modified:click/_bashcomplete.py+7 added-1 removed
64 unmodified lines
65 if isinstance(param, Argument):66 arguments = [k for k in args if k != ctx.command.name]67 if len(arguments) <= param.nargs or param.nargs == -1:68 try:69 if callable(param.autocompletion):70 choices.extend(param.autocompletion(context=ctx,71 incomplete=incomplete,72 cwords=cwords,73 cword=cword))74 else:69 choices.extend(param.autocompletion)75 choices.extend(param.autocompletion)76 except AttributeError:77 pass7879 for item in choices:
13 unmodified lines