Skip to content

Commit

Permalink
use canonical command name instead of matched name
Browse files Browse the repository at this point in the history
  • Loading branch information
ovezovs authored and davidism committed Jun 30, 2020
1 parent f3e55b6 commit 4a337ea
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 1 deletion.
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

0 comments on commit 4a337ea

Please sign in to comment.