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

"Name Your Options" docs incorrect #1599

Closed
HunterMcGushion opened this issue Jun 22, 2020 · 2 comments
Closed

"Name Your Options" docs incorrect #1599

HunterMcGushion opened this issue Jun 22, 2020 · 2 comments

Comments

@HunterMcGushion
Copy link

First of all, I love Click, and I want to thank you for taking the time to build and maintain such a fantastic library!

Problem

The Name Your Options documentation seems to be incorrect. The second point in choosing an option's name says,

  1. If there is at least one name prefixed with two dashes, the first one given is used as the name.

However, it seems that instead of the first double-dash-prefixed option, the last is used as the name.

At the bottom of the "Name Your Options" section, bulleted examples showing how names are chosen are given. The second to last bullet point is as follows:

"--f", "--foo-bar", the name is f

This is not what happens, as can be seen from the below snippet that recreates this example.

Expected Behavior

According to the docs linked above, executing the below snippet...

import click

@click.command()
@click.option(
    "--f",
    "--foo-bar",
)
def execute(**kwargs):
    print(kwargs)

if __name__ == "__main__":
    execute()

... should print out...

{'f': None}

Actual Behavior

Instead the following is printed:

{'foo_bar': None}

Environment

  • Python version: 3.6.6
  • Click version: 6.7

Personally, I think that using the first double-dash-prefixed option (as the docs state) makes the most sense. As someone who has never contributed to Click (so take this with a grain of salt), it looks like src.click.core.Option._parse_decls might need to be updated to be brought in line with the docs. I'd be happy to take a look and submit a PR if you're open to it. If you'd instead prefer to change the docs to reflect the actual behavior, I'd also be happy to make a PR.

Thanks for your time and for making such an awesome library!

@davidism
Copy link
Member

This behavior changed in version 7. You're using version 6.7, but reading the docs for version 7.

See previous discussions in #1140, #1420, and #1482.

@HunterMcGushion
Copy link
Author

Hahaha that's embarrassing. Thanks for clearing that up for me!

@github-actions github-actions bot locked as resolved and limited conversation to collaborators Nov 13, 2020
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