summaryrefslogtreecommitdiff
path: root/examples
diff options
context:
space:
mode:
Diffstat (limited to 'examples')
-rw-r--r--examples/bashcompletion/bashcompletion.py14
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)