Skip to content

Conditionally apply options to input #2689

@Kieran-Bacon

Description

@Kieran-Bacon

I have outlined an issue I have had on stack overflow here

In it, I am describing a situation where I have two option groups (dynamically loaded) that have an option with the same short-hand flag. This causes an issue because the input is always parsed as one of them and not the other. I need some way of having the options being conditionally used to parse the input based on the value of another option.

Given the nature of the setup, I have little control over the construction of the options in an option group. I control the construction of the selector option, so its possible values relate to the various dynamically loaded option groups. So a solution where I can say something along the lines, apply this option group if my value is set to x would be ideal

Ultimately I think the optiongroup extension is changing the way the help information is displayed and not changing the underlying implementation of option.

so in reality it is probably closer to, enable this list of options (disabling all others) if my value is x

Please let me know how I am meant to achieve this, or can you please add this kind of control as a feature?

@click.group()
@click.option('-m', '--manager', type=click.Choice(['local', 'remote', 'money']))
@click.option('-p', '--path')
@click.option('-p', '--profile', default='default')
@click.option('-p', '--pennies', type=int)
def cli(...):
   ...

@cli.command()
...
$ cli -m local -p /filepath
$ cli -m remote -p profile-name
$ cli -m money - p 160

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions