Skip to content

Commit 4f936ac

Browse files
authored
show correct auto complete value for nargs option in combination with flag option (#2816)
2 parents 1c68e53 + c03b461 commit 4f936ac

3 files changed

Lines changed: 21 additions & 0 deletions

File tree

CHANGES.rst

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,12 @@
11
.. currentmodule:: click
22

3+
Version 8.2.x
4+
-------------
5+
6+
Unreleased
7+
8+
- show correct auto complete value for nargs option in combination with flag option :issue:`2813`
9+
310
Version 8.2.2
411
-------------
512

src/click/shell_completion.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -552,6 +552,7 @@ def _is_incomplete_option(ctx: Context, args: list[str], param: Parameter) -> bo
552552

553553
if _start_of_option(ctx, arg):
554554
last_option = arg
555+
break
555556

556557
return last_option is not None and last_option in param.opts
557558

tests/test_shell_completion.py

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -220,6 +220,19 @@ def test_option_flag():
220220
assert _get_words(cli, ["--on"], "a") == ["a1", "a2"]
221221

222222

223+
def test_flag_option_with_nargs_option():
224+
cli = Command(
225+
"cli",
226+
add_help_option=False,
227+
params=[
228+
Argument(["a"], type=Choice(["a1", "a2", "b"])),
229+
Option(["--flag"], is_flag=True),
230+
Option(["-c"], type=Choice(["p", "q"]), nargs=2),
231+
],
232+
)
233+
assert _get_words(cli, ["a1", "--flag", "-c"], "") == ["p", "q"]
234+
235+
223236
def test_option_custom():
224237
def custom(ctx, param, incomplete):
225238
return [incomplete.upper()]

0 commit comments

Comments
 (0)