Search code examples
pythonclickmutex

Click: how to make Argument mutex


I'm writing a CLI using the beautiful click library

the use case i want to implement is something like this:

cmd <arg> <option --list>

arg: required
--list: optional

rationale

But... the --list show only the available arg so my purpose is to make all arguments optional in this use case.

I'm started from this request on the official repo, and a previous similar question very similar but it works only on Options.

I've not found an elegant solution because Arguments works differently, In my real case I have a lot of arguments and options, so is not possible to reduce all Arguments into Options.


Solution

  • From the click point of view, this is the wrong way to tackle these kind of problem. The right way is to works with the options priority as described here

    in this manner the --list options will be treated as the --version.