complete commands using registered names
Before adoption: this commit came in with the history the project adopted, so no landing records it.
authored by Jan Kowalleck · committed by David Lord · parent de75b40 · Browse files · 3 files·+15 added−6 removed
This commit
State
Before adoption: this commit came in with the history the project adopted, so no landing records it.
Diff stats
3 files+15 added−6 removed
- tests:+7 added−0 removed
- other:+8 added−6 removed
Provenance
- Commit
00d5dcc- Tree
be715f2- Author
Jan Kowalleck <jan.kowalleck@gmail.com>- Committer
David Lord <davidism@gmail.com>- Parent
de75b40
3 files changed+15 added−6 removed
modified:src/click/core.py+6 added-6 removed
68 unmodified lines69 if name.startswith(incomplete):70 command = ctx.command.get_command(ctx, name)71 72 if not command.hidden:73- yield command73+ yield name, command74 75 76 def _check_multicommand(base_command, cmd_name, cmd, register=False):77 if not base_command.chain or not isinstance(cmd, MultiCommand):806 unmodified lines884 ctx = ctx.parent885 886 if isinstance(ctx.command, MultiCommand) and ctx.command.chain:887 results.extend(888- ("plain", command.name, command.get_short_help_str())889- for command in _complete_visible_commands(ctx, incomplete)890- if command.name not in ctx.protected_args888+ ("plain", name, command.get_short_help_str())889+ for name, command in _complete_visible_commands(ctx, incomplete)890+ if name not in ctx.protected_args891 )892 893 return results894 694 unmodified lines1589 1590 .. versionadded:: 8.01591 """1592 results = [1593- ("plain", command.name, command.get_short_help_str())1594- for command in _complete_visible_commands(ctx, incomplete)1593+ ("plain", name, command.get_short_help_str())1594+ for name, command in _complete_visible_commands(ctx, incomplete)1595 ]1596 results.extend(super().shell_complete(ctx, args, incomplete))1597 return results1598 856 unmodified linesmodified:tests/test_shell_completion.py+7 added
201 unmodified lines202 assert _get_words(cli, ["hidden"], "-") == ["-a"]203 assert _get_words(cli, ["hidden", "-b"], "") == ["a", "b"]204 205 206+def test_add_different_name():207+ cli = Group("cli", commands={"renamed": Command("original")})208+ words = _get_words(cli, [], "")209+ assert "renamed" in words210+ assert "original" not in words211+212+213 @pytest.fixture()214 def _patch_for_completion(monkeypatch):215 monkeypatch.setattr("click.core._fast_exit", sys.exit)216 monkeypatch.setattr(31 unmodified linesmodified:CHANGES.rst+2 added
94 unmodified lines95 - Support Bash >= 4.4, Zsh, and Fish, with the ability for96 extensions to add support for other shells.97 - Allow commands, groups, parameters, and types to override their98 completions suggestions.99+ - Groups complete the names commands were registered with, which100+ can differ from the name they were created with.101 102 103 Version 7.1.2104 -------------635 unmodified lines