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

Mutually exclusive required options #1137

Closed
ror6ax opened this issue Oct 8, 2018 · 4 comments
Closed

Mutually exclusive required options #1137

ror6ax opened this issue Oct 8, 2018 · 4 comments

Comments

@ror6ax
Copy link

ror6ax commented Oct 8, 2018

Hi.

I have a situation where there's 3 ways a subcommand can go and each has a distinct option assigned to it. One of 3 has to be picked, but never in a combination with others.

Is there a way to achieve native click required=True- type of functionality(prompts, errors etc) in such case? So far I'm left with forest of ugly ifs.

@jcrotts
Copy link
Contributor

jcrotts commented Oct 20, 2018

Hi,

You could try making a subclass of option as suggested here:
https://stackoverflow.com/questions/37310718/mutually-exclusive-option-groups-in-python-click

Also see these issues for related discussion:
#257
#509

I am going to close this since something similar has been proposed and rejected in the past. However if you have a strong case for including something like this in click feel free to continue discussing it here. (Or if I've misunderstood what you're asking for.)

@jcrotts jcrotts closed this as completed Oct 20, 2018
@sizur
Copy link

sizur commented Nov 10, 2018

This feature has been requested 4 years ago. It has been requested multiple times. It is listed as missing functionality on multiple blogs. Is the basis of rejections a combination of (1) having to modify interface and (2) you can implement it yourself? Or am I misunderstanding something here?

@whwright
Copy link

I use this in several projects https://gist.github.com/jacobtolar/fb80d5552a9a9dfc32b12a829fa21c0c

@jcrotts
Copy link
Contributor

jcrotts commented Nov 16, 2018

Based on the original rejection, it looks like Armin didn't think there was a clean way to implement this. It is also fairly easy to subclass option and get the requested behavior, which I think is a compelling reason to not add it to Click unless there is a really clean API for it.

Alternatively maybe we could add a section of some more subclass examples to the docs?

@pallets pallets deleted a comment from gsemet Feb 27, 2019
@pallets pallets deleted a comment from mjscosta Feb 27, 2019
@pallets pallets locked as resolved and limited conversation to collaborators Feb 27, 2019
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

4 participants