bashcompletion.py
This file
Path
examples/bashcompletion/bashcompletion.py
46 lines · 1.2 KiB · Python
Last changed by
apply reorder-python-importsDavid Lordbefore adoption488739d
History of this fileTake it
The walk stopped after 200 commits: lines older than 92532b5 point at it.
Merge branch '6.x-maintenance'Armin Ronacherbefore adoption92532b5
line 1why, one step back1import osapply reorder-python-importsDavid Lordbefore adoption488739d
lines 2–3why, one step back23import clickMerge branch '6.x-maintenance'Armin Ronacherbefore adoption92532b5
lines 4–11why, one step back456@click.group()7def cli():8 pass91011def get_env_vars(ctx, args, incomplete):Merge pull request #1059 from stopthatcow/feature/1047David Lordbefore adoptiondf0f81d
line 12why, one step back12 # Completions returned as strings do not have a description displayed.Merge branch '6.x-maintenance'Armin Ronacherbefore adoption92532b5
lines 13–17why, one step back13 for key in os.environ.keys():14 if incomplete in key:15 yield key1617Merge pull request #869 from stopthatcow/feature/866David Lordbefore adoptiond37ff75
line 18why, one step back18@cli.command(help='A command to print environment variables')Merge branch '6.x-maintenance'Armin Ronacherbefore adoption92532b5
lines 19–24why, one step back19@click.argument("envvar", type=click.STRING, autocompletion=get_env_vars)20def cmd1(envvar):21 click.echo('Environment variable: %s' % envvar)22 click.echo('Value: %s' % os.environ[envvar])2324Merge pull request #869 from stopthatcow/feature/866David Lordbefore adoptiond37ff75
line 25why, one step back25@click.group(help='A group that holds a subcommand')Merge branch '6.x-maintenance'Armin Ronacherbefore adoption92532b5
lines 26–30why, one step back26def group():27 pass282930def list_users(ctx, args, incomplete):Merge pull request #1059 from stopthatcow/feature/1047David Lordbefore adoptiondf0f81d
lines 31–37why, one step back31 # You can generate completions with descriptions by returning32 # tuples in the form (completion, description).33 users = [('bob', 'butcher'),34 ('alice', 'baker'),35 ('jerry', 'candlestick maker')]36 # Ths will allow completion matches based on matches within the description string too!37 return [user for user in users if incomplete in user[0] or incomplete in user[1]]Merge branch '6.x-maintenance'Armin Ronacherbefore adoption92532b5
lines 38–39why, one step back3839Merge pull request #869 from stopthatcow/feature/866David Lordbefore adoptiond37ff75
line 40why, one step back40@group.command(help='Choose a user')Merge branch '6.x-maintenance'Armin Ronacherbefore adoption92532b5
lines 41–43why, one step back41@click.argument("user", type=click.STRING, autocompletion=list_users)42def subcmd(user):43 click.echo('Chosen user is %s' % user)Merge pull request #1059 from stopthatcow/feature/1047David Lordbefore adoptiondf0f81d
line 44why, one step back44Merge branch '6.x-maintenance'Armin Ronacherbefore adoption92532b5
lines 45–46why, one step back4546cli.add_command(group)