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
2 changes: 1 addition & 1 deletion click_repl/_completer.py
Original file line number Diff line number Diff line change
Expand Up @@ -234,7 +234,7 @@ def _get_completion_for_cmd_args(
self.shortest_only
and not incomplete # just typed a space
# not selecting a value for a longer version of this option
and args[-1] not in opts
and (not args or args[-1] not in opts)
):
opts = [min(opts, key=len)]

Expand Down
16 changes: 16 additions & 0 deletions tests/test_completion/test_common_tests/test_option_completion.py
Original file line number Diff line number Diff line change
Expand Up @@ -133,3 +133,19 @@ def shortest_only(foo, bar, foobar):

completions = list(c.get_completions(Document("shortest-only ")))
assert {x.text for x in completions} == {"-f", "--foo", "-b", "--bar", "--foobar"}


def test_shortest_only_at_empty_root_prompt(capsys):
@click.group()
@click.option("--verbose", "-v", is_flag=True)
def root(verbose):
pass

@root.command()
def child():
pass

completer = ClickCompleter(root, click.Context(root), shortest_only=True)
completions = list(completer.get_completions(Document("")))
assert {item.text for item in completions} == {"-v", "child"}
assert capsys.readouterr().out == ""
Loading