Skip to content

Commit

Permalink
complete commands using registered names
Browse files Browse the repository at this point in the history
  • Loading branch information
jkowalleck authored and davidism committed Oct 3, 2020
1 parent 3498c60 commit 6e0af87
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 6 deletions.
12 changes: 6 additions & 6 deletions src/click/core.py
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ def _complete_visible_commands(ctx, incomplete):
command = ctx.command.get_command(ctx, name)

if not command.hidden:
yield command
yield name, command


def _check_multicommand(base_command, cmd_name, cmd, register=False):
Expand Down Expand Up @@ -885,9 +885,9 @@ def shell_complete(self, ctx, args, incomplete):

if isinstance(ctx.command, MultiCommand) and ctx.command.chain:
results.extend(
("plain", command.name, command.get_short_help_str())
for command in _complete_visible_commands(ctx, incomplete)
if command.name not in ctx.protected_args
("plain", name, command.get_short_help_str())
for name, command in _complete_visible_commands(ctx, incomplete)
if name not in ctx.protected_args
)

return results
Expand Down Expand Up @@ -1577,8 +1577,8 @@ def shell_complete(self, ctx, args, incomplete):
.. versionadded:: 8.0
"""
results = [
("plain", command.name, command.get_short_help_str())
for command in _complete_visible_commands(ctx, incomplete)
("plain", name, command.get_short_help_str())
for name, command in _complete_visible_commands(ctx, incomplete)
]
results.extend(super().shell_complete(ctx, args, incomplete))
return results
Expand Down
7 changes: 7 additions & 0 deletions tests/test_shell_completion.py
Original file line number Diff line number Diff line change
Expand Up @@ -203,6 +203,13 @@ def test_hidden():
assert _get_words(cli, ["hidden", "-b"], "") == ["a", "b"]


def test_add_different_name():
cli = Group("cli", commands={"renamed": Command("original")})
words = _get_words(cli, [], "")
assert "renamed" in words
assert "original" not in words


@pytest.fixture()
def _patch_for_completion(monkeypatch):
monkeypatch.setattr("click.core._fast_exit", sys.exit)
Expand Down

0 comments on commit 6e0af87

Please sign in to comment.