click
click copied to clipboard
Click option completion callback doesn't have access to context.params for parsed values of already typed arguments.
Click option completion callback doesn't have access to context.params for parsed values of already typed arguments during shell completion:
import click
def test_completer(ctx, param, incomplete):
import sys
print(f"1: {param= }", file=sys.stderr)
print(f"2: {incomplete= }", file=sys.stderr)
print(f"3: {ctx.params = }", file=sys.stderr)
return []
@click.command()
@click.argument('type', shell_complete=test_completer)
@click.option('--test', shell_complete=test_completer)
def app(type, count):
pass
Output:
app foo --test [TAB] [TAB]
1: param= <Option test>
2: incomplete= ''
3: ctx.params = {'type': None, 'test': None}
Thus the context inside option callback does not have access to already typed argument.
But vice versa works:
app --test bar [TAB] [TAB]
1: param= <Argument type>
2: incomplete= ''
3: ctx.params = {'test': 'bar', 'type': None}
The context inside argument callback have access to already typed option.
I think it should be the same in both cases.
Environment:
- Python version: 3.8
- Click version: 8.0.3
Came here with the same problem myself. I still don't know why they are not populated in params but you can access them with ctx.args. I think there's a bug somewhere to map them back into params but at least this unblocked me and hope it will unblock some others.