From 79060f17c691d4f4321a9e389192ad7c28a4e1b6 Mon Sep 17 00:00:00 2001 From: Lucien A Date: Wed, 12 Jul 2023 17:03:16 +0200 Subject: [PATCH] Fix values shown for wrong option (#106) * fix values for wrong option * add unit test --- click_repl/_completer.py | 1 + .../test_common_tests/test_option_completion.py | 4 ++++ 2 files changed, 5 insertions(+) diff --git a/click_repl/_completer.py b/click_repl/_completer.py index 08ef106..e16a4a9 100644 --- a/click_repl/_completer.py +++ b/click_repl/_completer.py @@ -230,6 +230,7 @@ def _get_completion_for_cmd_args( choices = self._get_completion_from_params( autocomplete_ctx, args, param, incomplete ) + break elif isinstance(param, click.Argument): choices.extend( diff --git a/tests/test_completion/test_common_tests/test_option_completion.py b/tests/test_completion/test_common_tests/test_option_completion.py index 38bf34e..c91f05c 100644 --- a/tests/test_completion/test_common_tests/test_option_completion.py +++ b/tests/test_completion/test_common_tests/test_option_completion.py @@ -14,12 +14,16 @@ def root_command(): def test_option_choices(): @root_command.command() @click.option("--handler", type=click.Choice(("foo", "bar"))) + @click.option("--wrong", type=click.Choice(("bogged", "bogus"))) def option_choices(handler): pass completions = list(c.get_completions(Document("option-choices --handler "))) assert {x.text for x in completions} == {"foo", "bar"} + completions = list(c.get_completions(Document("option-choices --wrong "))) + assert {x.text for x in completions} == {"bogged", "bogus"} + def test_boolean_option(): @root_command.command()