bashcompletion.py
This file
Path
examples/bashcompletion/bashcompletion.py
45 lines · 1.2 KiB · Python
Last changed by
Merge pull request #1059 from stopthatcow/feature/1047David Lordbefore adoptiondf0f81d
History of this fileTake it
The walk stopped after 200 commits: lines older than 950463b point at it.
Fix typo (#817)scottbeldenbefore adoption950463b
lines 1–3why, one step back1import click2import os3Merge pull request #806 from stopthatcow/feature/790Markus Unterwaditzerbefore adoption5210849
line 4why, one step back4Fix typo (#817)scottbeldenbefore adoption950463b
lines 5–8why, one step back5@click.group()6def cli():7 pass8Merge pull request #806 from stopthatcow/feature/790Markus Unterwaditzerbefore adoption5210849
line 9why, one step back9Fix typo (#817)scottbeldenbefore adoption950463b
line 10why, one step back10def get_env_vars(ctx, args, incomplete):Merge pull request #1059 from stopthatcow/feature/1047David Lordbefore adoptiondf0f81d
line 11why, one step back11 # Completions returned as strings do not have a description displayed.Merge pull request #806 from stopthatcow/feature/790Markus Unterwaditzerbefore adoption5210849
lines 12–14why, one step back12 for key in os.environ.keys():13 if incomplete in key:14 yield keyFix typo (#817)scottbeldenbefore adoption950463b
line 15why, one step back15Merge pull request #806 from stopthatcow/feature/790Markus Unterwaditzerbefore adoption5210849
line 16why, one step back16Merge pull request #869 from stopthatcow/feature/866David Lordbefore adoptiond37ff75
line 17why, one step back17@cli.command(help='A command to print environment variables')Fix typo (#817)scottbeldenbefore adoption950463b
lines 18–22why, one step back18@click.argument("envvar", type=click.STRING, autocompletion=get_env_vars)19def cmd1(envvar):20 click.echo('Environment variable: %s' % envvar)21 click.echo('Value: %s' % os.environ[envvar])22Merge pull request #806 from stopthatcow/feature/790Markus Unterwaditzerbefore adoption5210849
line 23why, one step back23Merge pull request #869 from stopthatcow/feature/866David Lordbefore adoptiond37ff75
line 24why, one step back24@click.group(help='A group that holds a subcommand')Fix typo (#817)scottbeldenbefore adoption950463b
lines 25–27why, one step back25def group():26 pass27Merge pull request #806 from stopthatcow/feature/790Markus Unterwaditzerbefore adoption5210849
line 28why, one step back28Fix typo (#817)scottbeldenbefore adoption950463b
line 29why, one step back29def list_users(ctx, args, incomplete):Merge pull request #1059 from stopthatcow/feature/1047David Lordbefore adoptiondf0f81d
lines 30–36why, one step back30 # You can generate completions with descriptions by returning31 # tuples in the form (completion, description).32 users = [('bob', 'butcher'),33 ('alice', 'baker'),34 ('jerry', 'candlestick maker')]35 # Ths will allow completion matches based on matches within the description string too!36 return [user for user in users if incomplete in user[0] or incomplete in user[1]]Merge pull request #806 from stopthatcow/feature/790Markus Unterwaditzerbefore adoption5210849
line 37why, one step back37Fix typo (#817)scottbeldenbefore adoption950463b
line 38why, one step back38Merge pull request #869 from stopthatcow/feature/866David Lordbefore adoptiond37ff75
line 39why, one step back39@group.command(help='Choose a user')Fix typo (#817)scottbeldenbefore adoption950463b
lines 40–42why, one step back40@click.argument("user", type=click.STRING, autocompletion=list_users)41def subcmd(user):42 click.echo('Chosen user is %s' % user)Merge pull request #1059 from stopthatcow/feature/1047David Lordbefore adoptiondf0f81d
line 43why, one step back43Fix typo (#817)scottbeldenbefore adoption950463b
lines 44–45why, one step back4445cli.add_command(group)