Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions CHANGES.rst
Original file line number Diff line number Diff line change
@@ -1,5 +1,12 @@
.. currentmodule:: click

Version 8.2.x
-------------

Unreleased

- show correct auto complete value for nargs option in combination with flag option :issue:`2813`

Version 8.2.2
-------------

Expand Down
1 change: 1 addition & 0 deletions src/click/shell_completion.py
Original file line number Diff line number Diff line change
Expand Up @@ -552,6 +552,7 @@ def _is_incomplete_option(ctx: Context, args: list[str], param: Parameter) -> bo

if _start_of_option(ctx, arg):
last_option = arg
break

return last_option is not None and last_option in param.opts

Expand Down
13 changes: 13 additions & 0 deletions tests/test_shell_completion.py
Original file line number Diff line number Diff line change
Expand Up @@ -220,6 +220,19 @@ def test_option_flag():
assert _get_words(cli, ["--on"], "a") == ["a1", "a2"]


def test_flag_option_with_nargs_option():
cli = Command(
"cli",
add_help_option=False,
params=[
Argument(["a"], type=Choice(["a1", "a2", "b"])),
Option(["--flag"], is_flag=True),
Option(["-c"], type=Choice(["p", "q"]), nargs=2),
],
)
assert _get_words(cli, ["a1", "--flag", "-c"], "") == ["p", "q"]


def test_option_custom():
def custom(ctx, param, incomplete):
return [incomplete.upper()]
Expand Down
Loading