Skip to content
Myr

bashcompletion.py

This file

Path

examples/bashcompletion/bashcompletion.py

41 lines · 820 bytes · Python

Last changed by

Fix test for delayed progress bar displayJan Christoph Bischkobefore adoption82f9c62

History of this file

Take it

Fix test for delayed progress bar displayJan Christoph Bischkobefore adoption82f9c62

lines 1–41why, one step back
1import click
2import os345@click.group()6def cli():7 pass8910def get_env_vars(ctx, args, incomplete):11 for key in os.environ.keys():12 if incomplete in key:13 yield key141516@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])212223@click.group()24def group():25 pass262728def list_users(ctx, args, incomplete):29 # Here you can generate completions dynamically30 users = ['bob', 'alice']31 for user in users:32 if user.startswith(incomplete):33 yield user343536@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)