Skip to content

Issue UserWarning when overriding Parameter name #2396

@edrogers

Description

@edrogers

When a command is given multiple parameters that use the same name, a UserWarning should be fired to highlight the conflict. Currently, the command will quietly allow one parameter to override the names of another.

(This is a slightly different problem than #1465. In that issue, True and False values were given the same names within a single parameter.)

Example of the issue:

@click.command()
@click.option("-a", "--aardvark", is_flag=True)
@click.option("-a", "--avocado", is_flag=True)
def cli(aardvark: bool = False, avocado: bool = False):
    if aardvark:
        print("Animal")
    if avocado:
        print("Fruit")

In this scenario, the short-name, -a, appears ambiguous. A warning would help the user realize the conflict they've introduced.

I'll also provide a pull request for consideration.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions