Mutually exclusive required options
ror6ax opened this issue · 4 comments
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.
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.)
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?
I use this in several projects https://gist.github.com/jacobtolar/fb80d5552a9a9dfc32b12a829fa21c0c
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?