Skip to content

Mutually exclusive options with the same variable name don't work #11

Open
@craigds

Description

@craigds

If I have two options sharing the same variable name, like this:

#!/usr/bin/env python
import click
from click_option_group import optgroup, MutuallyExclusiveOptionGroup


@click.command()
@click.pass_context
@optgroup.group('Output format', cls=MutuallyExclusiveOptionGroup)
@optgroup.option(
    "--text", "output_format", flag_value="text", default=True,
)
@optgroup.option(
    "--json", "output_format", flag_value="json",
)
def mycommand(ctx, *, output_format, **kwargs):
    print(output_format)


if __name__ == '__main__':
    mycommand()

The mutual exclusive option group doesn't work - whichever option is specified last on the command line wins:

$ python ./mycommand.py --json --text
text

This may be difficult to solve, but here's my completely custom hack for making it work: koordinates/kart#106

Maybe elements of that solution could be incorporated into this project?

Metadata

Metadata

Assignees

No one assigned

    Labels

    enhancementNew feature or requesthelp wantedExtra attention is neededincompatibilityIncompatibility with other functions and plugins

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions