Skip to content
Myr

Merge pull request #1937 from pallets/completion-example

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

fix completion example

authored by David Lord · committed by GitHub · parents 1517c6b, 48cb86d · Browse files · 2 files+7 added−4 removed
This commit

State

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

Diff stats

2 files+7 added−4 removed

  • other:+7 added−4 removed

2 files+7 added−4 removed

modified:examples/completion/completion.py+4 added-1 removed
36 unmodified lines
37 # You can generate completions with help strings by returning a list38 # of CompletionItem. You can match on whatever you want, including39 # the help.40 items = [("bob", "butcher"), ("alice", "baker"), ("jerry", "candlestick maker")]41 out = []4243 for value, help in items:44 if incomplete in value or incomplete in help:44 yield CompletionItem(value, help=help)45 out.append(CompletionItem(value, help=help))4647 return out484950@group.command(help="Choose a user")51@click.argument("user", shell_complete=list_users)52def select_user(user):53 click.echo(f"Chosen user is {user}")
3 unmodified lines
modified:examples/completion/README+3 added-3 removed
9 unmodified lines
10For Bash:1112.. code-block:: bash1314 eval "$(_COMPLETION_COMPLETE=source_bash completion)"14 eval "$(_COMPLETION_COMPLETE=bash_source completion)"1516For Zsh:1718.. code-block:: zsh1920 eval "$(_COMPLETION_COMPLETE=source_zsh completion)"20 eval "$(_COMPLETION_COMPLETE=zsh_source completion)"2122For Fish:2324.. code-block:: fish2526 eval (env _COMPLETION_COMPLETE=source_fish completion)26 eval (env _COMPLETION_COMPLETE=fish_source completion)2728Now press tab (maybe twice) after typing something to see completions.