Skip to content
Myr

Use already-parsed values of aruments to see whether they should be completed.

Before adoption: this commit came in with the history the project adopted, so no landing records it.

authored by Brett Bethke · committed by Brett Bethke · parent e27493b · Browse files · 2 files+9 added−5 removed
This commit

State

Before adoption: this commit came in with the history the project adopted, so no landing records it.

Diff stats

2 files+9 added−5 removed

  • other:+9 added−5 removed

2 files+9 added−5 removed

modified:click/_bashcomplete.py+3 added-2 removed
61 unmodified lines
62 choices.extend(ctx.command.list_commands(ctx))63 else:64 for param in ctx.command.params:65 if isinstance(param, Argument):66 arguments = [k for k in args if k != ctx.command.name]67 if len(arguments) <= param.nargs or param.nargs == -1:66 value = ctx.params[param.name]67 if (value == None) or (isinstance(value, tuple) and (len(value) < param.nargs or param.nargs == -1)):68 try:69 if callable(param.autocompletion):70 choices.extend(param.autocompletion(ctx=ctx,71 incomplete=incomplete,
2 unmodified lines
74 else:75 choices.extend(param.autocompletion)76 except AttributeError:77 pass78 break7980 for item in choices:81 if item.startswith(incomplete):82 echo(item)
11 unmodified lines
modified:examples/bashcompletion/bashcompletion.py+6 added-3 removed
4 unmodified lines
5def cli():6 pass78@cli.command()9@click.argument("name", type=click.STRING, autocompletion=["John", "Simon", "Doe"])10def cmd1(name):11 click.echo('Name: %s' % name)9@click.option('-c', '--count', type=click.INT, default=1)10@click.argument("first", type=click.STRING, autocompletion=["John", "Bob", "Fred"])11@click.argument("last", type=click.STRING, autocompletion=["Smith", "Simon", "Doe"])12def cmd1(count, first, last):13 for c in range(count):14 click.echo('Name: %s %s' % (first, last))1516def get_env_vars(ctx, incomplete, cwords, cword):17 return os.environ.keys()18
10 unmodified lines