bashcompletion.py
This file
Path
examples/bashcompletion/bashcompletion.py
41 lines · 820 bytes · Python
Last changed by
Merge branch 'master' into bright-colorsDan Sullybefore adoptionc0ccf30
History of this fileTake it
Merge pull request #755 from stopthatcow/feature/bash_autocompletion_6.6Markus Unterwaditzerbefore adoption5f2ff4f
lines 1–3why, one step back1import click2import os3Merge branch 'master' into bright-colorsDan Sullybefore adoptionc0ccf30
line 4why, one step back4Merge pull request #755 from stopthatcow/feature/bash_autocompletion_6.6Markus Unterwaditzerbefore adoption5f2ff4f
lines 5–8why, one step back5@click.group()6def cli():7 pass8Merge branch 'master' into bright-colorsDan Sullybefore adoptionc0ccf30
line 9why, one step back9Merge pull request #755 from stopthatcow/feature/bash_autocompletion_6.6Markus Unterwaditzerbefore adoption5f2ff4f
line 10why, one step back10def get_env_vars(ctx, args, incomplete):Merge branch 'master' into bright-colorsDan Sullybefore adoptionc0ccf30
lines 11–13why, one step back11 for key in os.environ.keys():12 if incomplete in key:13 yield keyMerge pull request #755 from stopthatcow/feature/bash_autocompletion_6.6Markus Unterwaditzerbefore adoption5f2ff4f
line 14why, one step back14Merge branch 'master' into bright-colorsDan Sullybefore adoptionc0ccf30
line 15why, one step back15Merge pull request #755 from stopthatcow/feature/bash_autocompletion_6.6Markus Unterwaditzerbefore adoption5f2ff4f
lines 16–21why, one step back16@cli.command()17@click.argument("envvar", type=click.STRING, autocompletion=get_env_vars)18def cmd1(envvar):19 click.echo('Environment variable: %s' % envvar)20 click.echo('Value: %s' % os.environ[envvar])21Merge branch 'master' into bright-colorsDan Sullybefore adoptionc0ccf30
line 22why, one step back22Merge pull request #755 from stopthatcow/feature/bash_autocompletion_6.6Markus Unterwaditzerbefore adoption5f2ff4f
lines 23–26why, one step back23@click.group()24def group():25 pass26Merge branch 'master' into bright-colorsDan Sullybefore adoptionc0ccf30
line 27why, one step back27Merge pull request #755 from stopthatcow/feature/bash_autocompletion_6.6Markus Unterwaditzerbefore adoption5f2ff4f
lines 28–30why, one step back28def list_users(ctx, args, incomplete):29 # Here you can generate completions dynamically30 users = ['bob', 'alice']Merge branch 'master' into bright-colorsDan Sullybefore adoptionc0ccf30
lines 31–34why, one step back31 for user in users:32 if user.startswith(incomplete):33 yield user34Merge pull request #755 from stopthatcow/feature/bash_autocompletion_6.6Markus Unterwaditzerbefore adoption5f2ff4f
lines 35–41why, one step back3536@group.command()37@click.argument("user", type=click.STRING, autocompletion=list_users)38def subcmd(user):39 click.echo('Chosen user is %s' % user)4041cli.add_command(group)