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

Click 8.0.0 group.add_command(..) does not replace name in description and when looking up defaults #1895

Closed
boidolr opened this issue May 14, 2021 · 1 comment
Milestone

Comments

@boidolr
Copy link

boidolr commented May 14, 2021

With click 8.0.0 click.group.add_command(..) changed the behavior in how new command names are used:
Both the help text for the command as well as when looking up default values in default_map the previous command name instead of the one added by the group are shown.

Minimal example:

# test.py
import click

@click.command()
@click.option(
    "--qux",
    required=True
)
def foo(qux):
    print(qux)

@click.group()
def group():
    pass

group.add_command(foo, "bar")

group(default_map={"bar": {"qux": "val"}})

Run the above:

  • with click 7.x:

$ python3 test.py bar --help
Usage: test.py bar [OPTIONS]
// and
$ python3 test.py bar
val

  • with click 8.0.0:

$ python3 test.py bar --help
Usage: test.py foo [OPTIONS]
// and
$ python3 test.py bar
Usage: test.py foo [OPTIONS]
Try 'test.py foo --help' for help.

Error: Missing option '--qux'.

I would have expected that both the help shows the name of the command as "bar" (as using "foo" will result in an error)
and the lookup for the default using "bar" as a key.

Environment:

  • Python version: 3.9.5
  • Click version: 8.0.0
@boidolr boidolr changed the title Click 8.0.0 group. add_command(..) does not replace name in description and when looking up defaults Click 8.0.0 group.add_command(..) does not replace name in description and when looking up defaults May 14, 2021
@davidism
Copy link
Member

This was due to #1422, which was intended to return the "real" command name when using aliases. However, I think the use case you've shown here is much more common, so I'll revert that change. The aliased command issue can be addressed by updating the docs to override resolve_command and return the desired command name instead.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants