bashcompletion.py
This file
Path
examples/bashcompletion/bashcompletion.py
45 lines · 1.2 KiB · Python
Last changed by
Merge pull request #1532 from pallets/drop-python2David Lordbefore adoption97de2c9
History of this fileTake it
The walk stopped after 200 commits: lines older than c8db9db point at it.
Merge pull request #828 from eli-b/patch-1David Lordbefore adoptionc8db9db
lines 1–2why, one step back1import os2Merge branch '7.x'David Lordbefore adoption7239794
line 3why, one step back3import clickMerge pull request #806 from stopthatcow/feature/790Markus Unterwaditzerbefore adoption5210849
line 4why, one step back4Merge branch '7.x'David Lordbefore adoption7239794
line 5why, one step back5Merge pull request #828 from eli-b/patch-1David Lordbefore adoptionc8db9db
lines 6–9why, one step back6@click.group()7def cli():8 pass9Merge pull request #806 from stopthatcow/feature/790Markus Unterwaditzerbefore adoption5210849
line 10why, one step back10Merge pull request #828 from eli-b/patch-1David Lordbefore adoptionc8db9db
line 11why, one step back11def 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 pull request #806 from stopthatcow/feature/790Markus Unterwaditzerbefore adoption5210849
lines 13–15why, one step back13 for key in os.environ.keys():14 if incomplete in key:15 yield keyMerge pull request #828 from eli-b/patch-1David Lordbefore adoptionc8db9db
line 16why, one step back16Merge pull request #806 from stopthatcow/feature/790Markus Unterwaditzerbefore adoption5210849
line 17why, one step back17Merge branch '7.x'David Lordbefore adoption7239794
line 18why, one step back18@cli.command(help="A command to print environment variables")Merge pull request #828 from eli-b/patch-1David Lordbefore adoptionc8db9db
lines 19–20why, one step back19@click.argument("envvar", type=click.STRING, autocompletion=get_env_vars)20def cmd1(envvar):Merge pull request #1532 from pallets/drop-python2David Lordbefore adoption97de2c9
lines 21–22why, one step back21 click.echo(f"Environment variable: {envvar}")22 click.echo(f"Value: {os.environ[envvar]}")Merge pull request #828 from eli-b/patch-1David Lordbefore adoptionc8db9db
line 23why, one step back23Merge pull request #806 from stopthatcow/feature/790Markus Unterwaditzerbefore adoption5210849
line 24why, one step back24Merge branch '7.x'David Lordbefore adoption7239794
line 25why, one step back25@click.group(help="A group that holds a subcommand")Merge pull request #828 from eli-b/patch-1David Lordbefore adoptionc8db9db
lines 26–28why, one step back26def group():27 pass28Merge pull request #806 from stopthatcow/feature/790Markus Unterwaditzerbefore adoption5210849
line 29why, one step back29Merge pull request #828 from eli-b/patch-1David Lordbefore adoptionc8db9db
line 30why, one step back30def list_users(ctx, args, incomplete):Merge pull request #1059 from stopthatcow/feature/1047David Lordbefore adoptiondf0f81d
lines 31–32why, one step back31 # You can generate completions with descriptions by returning32 # tuples in the form (completion, description).Merge branch '7.x'David Lordbefore adoption7239794
lines 33–35why, one step back33 users = [("bob", "butcher"), ("alice", "baker"), ("jerry", "candlestick maker")]34 # Ths will allow completion matches based on matches within the35 # description string too!Merge pull request #1059 from stopthatcow/feature/1047David Lordbefore adoptiondf0f81d
line 36why, one step back36 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 back37Merge pull request #828 from eli-b/patch-1David Lordbefore adoptionc8db9db
line 38why, one step back38Merge branch '7.x'David Lordbefore adoption7239794
line 39why, one step back39@group.command(help="Choose a user")Merge pull request #828 from eli-b/patch-1David Lordbefore adoptionc8db9db
lines 40–41why, one step back40@click.argument("user", type=click.STRING, autocompletion=list_users)41def subcmd(user):Merge pull request #1532 from pallets/drop-python2David Lordbefore adoption97de2c9
line 42why, one step back42 click.echo(f"Chosen user is {user}")Merge pull request #1059 from stopthatcow/feature/1047David Lordbefore adoptiondf0f81d
line 43why, one step back43Merge pull request #828 from eli-b/patch-1David Lordbefore adoptionc8db9db
lines 44–45why, one step back4445cli.add_command(group)