Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

show correct auto complete value for nargs option in combination with flag option #2816

Open
wants to merge 5 commits into
base: main
Choose a base branch
from
Open
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
4 changes: 3 additions & 1 deletion CHANGES.rst
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
Version 8.2.0
-------------

Unreleased
Released 2025-01-12

- Drop support for Python 3.7. :pr:`2588`
- Use modern packaging metadata with ``pyproject.toml`` instead of ``setup.cfg``.
Expand Down Expand Up @@ -98,6 +98,8 @@ Unreleased
- ``Choice`` is now generic and supports any iterable value.
This allows you to use enums and other non-``str`` values. :pr:`2796`
:issue:`605`
- show correct auto complete value for nargs option in combination with
flag option :issue:`2813`

Version 8.1.8
-------------
Expand Down
2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[project]
name = "click"
version = "8.2.0.dev"
version = "8.2.0"
description = "Composable command line interface toolkit"
readme = "README.md"
license = {file = "LICENSE.txt"}
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 @@ -525,6 +525,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 @@ -188,6 +188,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