summaryrefslogtreecommitdiff
path: root/docs/bashcomplete.rst
diff options
context:
space:
mode:
authorNicholas Wiles <nwiles@google.com>2017-10-09 18:00:53 -0700
committerDavid Lord <davidism@gmail.com>2018-05-18 09:09:14 -0700
commit6c7276b5db80dff9310f6b76dd9fac985eb4a246 (patch)
treefb9c720fdf3f7171dc8878a146e74b961dace8d3 /docs/bashcomplete.rst
parentbefb77bfe4b814687d9bd8e15c59ae64f579967c (diff)
downloadclick-6c7276b5db80dff9310f6b76dd9fac985eb4a246.tar.gz
support descriptions for zsh completions
use associative array for zsh completion response add documentation for completion help strings fix missing short_help on commands that broke ZSH auto documentation
Diffstat (limited to 'docs/bashcomplete.rst')
-rw-r--r--docs/bashcomplete.rst34
1 files changed, 30 insertions, 4 deletions
diff --git a/docs/bashcomplete.rst b/docs/bashcomplete.rst
index 1cbf4a5..bff38fa 100644
--- a/docs/bashcomplete.rst
+++ b/docs/bashcomplete.rst
@@ -12,9 +12,8 @@ Limitations
Bash completion is only available if a script has been installed properly,
and not executed through the ``python`` command. For information about
-how to do that, see :ref:`setuptools-integration`. Also, Click currently
-only supports completion for Bash. Zsh support is available through Zsh's
-bash completion compatibility mode.
+how to do that, see :ref:`setuptools-integration`. Click currently
+only supports completion for Bash and Zsh.
What it Completes
-----------------
@@ -47,7 +46,7 @@ Here is an example of using a callback function to generate dynamic suggestions:
import os
def get_env_vars(ctx, args, incomplete):
- return os.environ.keys()
+ return [k for k in os.environ.keys() if incomplete in k]
@click.command()
@click.argument("envvar", type=click.STRING, autocompletion=get_env_vars)
@@ -56,6 +55,33 @@ Here is an example of using a callback function to generate dynamic suggestions:
click.echo('Value: %s' % os.environ[envvar])
+Completion help strings (ZSH only)
+----------------------------------
+
+ZSH supports showing documentation strings for completions. These are taken
+from the help parameters of options and subcommands. For dynamically generated
+completions a help string can be provided by returning a tuple instead of a
+string. The first element of the tuple is the completion and the second is the
+help string to display.
+
+Here is an example of using a callback function to generate dynamic suggestions with help strings:
+
+.. click:example::
+
+ import os
+
+ def get_colors(ctx, args, incomplete):
+ colors = [('red', 'help string for the color red'),
+ ('blue', 'help string for the color blue'),
+ ('green', 'help string for the color green')]
+ return [c for c in colors if incomplete in c[0]]
+
+ @click.command()
+ @click.argument("color", type=click.STRING, autocompletion=get_colors)
+ def cmd1(color):
+ click.echo('Chosen color is %s' % color)
+
+
Activation
----------