How can I create a mutually exclusive option group in Click? I want to either accept the flag "--all" or take an option with a parameter like "--color red".
相关问题
- how to define constructor for Python's new Nam
- streaming md5sum of contents of a large remote tar
- How to get the background from multiple images by
- Evil ctypes hack in python
- Correctly parse PDF paragraphs with Python
I ran into this same use case recently; this is what I came up with. For each option, you can give a list of conflicting options.
Then use the regular
option
decorator but pass thecls
argument:Here's a gist that includes the code above and shows the output from running it.
If that won't work for you, there's also a few (closed) issues mentioning this on the click github page with a couple of ideas that you may be able to use.
You could use the following package: https://github.com/espdev/click-option-group
app help: