1

I have two options that are interdependent. That is, the value selected for one constrains the valid options for the other.

What is best way to enforce this with the click library? Is there a built-in mechanism for this?

I want to take advantage of the built-in parameter error checks if possible. At the moment I've fallen back to checking the variables once they have been passed into my code.

imbuedHope
  • 508
  • 3
  • 14
  • This is not a duplicate, as it is a generalization of the mentioned narrow questions. Click doesn't offer any specific mechanism besides callbacks and Option subclassing. There's nothing wrong in checking stuff inside the command callback. Nonetheless, I wrote a package called [Cloup](https://cloup.readthedocs.io/en/stable/) that may help you. It allows to define option groups and apply constraints, including [conditional constraints](https://cloup.readthedocs.io/en/stable/pages/constraints.html#conditional-constraints). – janluke Feb 19 '21 at 18:46
  • 1
    I wrote Cloup primarily because I wanted to add support to option groups. I added the possibility to define "constraints" later, mainly for "completeness" and as an exercise, not because I really needed them. In fact, I think that a well-designed CLI should not have many constrained options and Click, with subcommands and Choice options, already handles the cases where it's legit to have dependencies. So, before introducing interdependencies, think if they are really needed or if instead you can rethink you CLI. – janluke Feb 19 '21 at 18:54

0 Answers0