diff options
author | Nicholas Wiles <nwiles@google.com> | 2017-10-09 18:14:00 -0700 |
---|---|---|
committer | David Lord <davidism@gmail.com> | 2018-09-12 12:05:51 -0700 |
commit | b073abe1cbc67d2a29f13ac757774b49257c494b (patch) | |
tree | 749080e48edb1ecc6eb1239b7cd02628f7a01d99 /examples | |
parent | be28b6c6f9d001f230614b5f9be2c50b30c6cb3a (diff) | |
download | click-b073abe1cbc67d2a29f13ac757774b49257c494b.tar.gz |
Use Python sorting order for ZSH completions. Fixes #1047.
Diffstat (limited to 'examples')
-rw-r--r-- | examples/bashcompletion/bashcompletion.py | 14 |
1 files changed, 9 insertions, 5 deletions
diff --git a/examples/bashcompletion/bashcompletion.py b/examples/bashcompletion/bashcompletion.py index 4d9fdde..1072840 100644 --- a/examples/bashcompletion/bashcompletion.py +++ b/examples/bashcompletion/bashcompletion.py @@ -8,6 +8,7 @@ def cli(): def get_env_vars(ctx, args, incomplete): + # Completions returned as strings do not have a description displayed. for key in os.environ.keys(): if incomplete in key: yield key @@ -26,11 +27,13 @@ def group(): def list_users(ctx, args, incomplete): - # Here you can generate completions dynamically - users = ['bob', 'alice'] - for user in users: - if user.startswith(incomplete): - yield user + # You can generate completions with descriptions by returning + # tuples in the form (completion, description). + users = [('bob', 'butcher'), + ('alice', 'baker'), + ('jerry', 'candlestick maker')] + # Ths will allow completion matches based on matches within the description string too! + return [user for user in users if incomplete in user[0] or incomplete in user[1]] @group.command(help='Choose a user') @@ -38,4 +41,5 @@ def list_users(ctx, args, incomplete): def subcmd(user): click.echo('Chosen user is %s' % user) + cli.add_command(group) |