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 full subcommand names when using --help in aliasedgroup #1615

Merged
merged 1 commit into from Jun 30, 2020
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.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
4 changes: 4 additions & 0 deletions CHANGES.rst
Expand Up @@ -24,6 +24,10 @@ Unreleased
raises a ``ValueError``. :issue:`1465`
- ``echo()`` will not fail when using pytest's ``capsys`` fixture on
Windows. :issue:`1590`
- Resolving commands returns the canonical command name instead of the
matched name. This makes behavior such as help text and
``Context.invoked_subcommand`` consistent when using patterns like
``AliasedGroup``. :issue:`1422`


Version 7.1.2
Expand Down
2 changes: 1 addition & 1 deletion src/click/core.py
Expand Up @@ -1346,7 +1346,7 @@ def resolve_command(self, ctx, args):
self.parse_args(ctx, ctx.args)
ctx.fail(f"No such command '{original_cmd_name}'.")

return cmd_name, cmd, args[1:]
return cmd.name, cmd, args[1:]

def get_command(self, ctx, cmd_name):
"""Given a context and a command name, this returns a
Expand Down
16 changes: 16 additions & 0 deletions tests/test_commands.py
Expand Up @@ -258,6 +258,22 @@ def sync():
assert result.output == "no subcommand, use default\nin subcommand\n"


def test_aliased_command_canonical_name(runner):
class AliasedGroup(click.Group):
def get_command(self, ctx, cmd_name):
return push

cli = AliasedGroup()

@cli.command()
def push():
click.echo("push command")

result = runner.invoke(cli, ["pu", "--help"])
assert not result.exception
assert result.output.startswith("Usage: root push [OPTIONS]")


def test_unprocessed_options(runner):
@click.command(context_settings=dict(ignore_unknown_options=True))
@click.argument("args", nargs=-1, type=click.UNPROCESSED)
Expand Down