Skip to content
Myr

bashcompletion.py

This file

Path

examples/bashcompletion/bashcompletion.py

31 lines · 688 bytes · Python

Last changed by

Update completion exampleNicholas Wilesbefore adoption33cd869

History of this file

Take it

Merge branch 'feature/parameter_autocompletion' of github.com:bb4242/click into feature/bash_completion_6.6Ibefore adoption483e943

lines 1–7why, one step back
1import click
2import os34@click.group()5def cli():6 pass7

Updated tests for autocompletionNicholas Wilesbefore adoptiondcc0719

line 8why, one step back
8def get_env_vars(ctx, args, incomplete):

Merge branch 'feature/parameter_autocompletion' of github.com:bb4242/click into feature/bash_completion_6.6Ibefore adoption483e943

lines 9–12why, one step back
9 return os.environ.keys()
1011@cli.command()12@click.argument("envvar", type=click.STRING, autocompletion=get_env_vars)

Merge branch 'master' into feature/bash_autocompletion_6.6Nicholas Wilesbefore adoption014ce7c

line 13why, one step back
13def cmd1(envvar):

Merge branch 'feature/parameter_autocompletion' of github.com:bb4242/click into feature/bash_completion_6.6Ibefore adoption483e943

lines 14–16why, one step back
14 click.echo('Environment variable: %s' % envvar)
15 click.echo('Value: %s' % os.environ[envvar])16

Fix bug preventing completion on subcommandsNic Wilesbefore adoption1d0b394

lines 17–20why, one step back
17@click.group()
18def group():19 pass20

Update completion exampleNicholas Wilesbefore adoption33cd869

lines 21–24why, one step back
21def list_users(ctx, args, incomplete):
22 # Here you can generate completions dynamically23 users = ['bob', 'alice']24 return users

Merge branch 'master' into feature/bash_autocompletion_6.6Nicholas Wilesbefore adoption014ce7c

line 25why, one step back
25

Fix bug preventing completion on subcommandsNic Wilesbefore adoption1d0b394

line 26why, one step back
26@group.command()

Update completion exampleNicholas Wilesbefore adoption33cd869

lines 27–29why, one step back
27@click.argument("user", type=click.STRING, autocompletion=list_users)
28def subcmd(user):29 click.echo('Chosen user is %s' % user)

Fix bug preventing completion on subcommandsNic Wilesbefore adoption1d0b394

lines 30–31why, one step back
30
31cli.add_command(group)