-
Notifications
You must be signed in to change notification settings - Fork 14
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
Would it be possible to support arguments in addtion to options? #26
Comments
click-option-group only works with options. It is currently not possible to mix mutually exclusive options and arguments inside an option group. It's hard to say right now if this feature is possible at all. I need to experiment with this. |
That's what I figured but was hoping it'd be "Oh yeah, that's easy!" :) Our internal dev has standardized on Click and I'm working updating some older tooling. I'll look for an alternative setup but think this would still be a nice feature to have. BTW, loving the your package so far. |
Things get complicated if we try to do something non-standard in Click. :)
An arbitrary number of positional arguments can be replaced to option with
Yes, I know, it looks verbose, but this is the only way to set an arbitrary number of option values in Click except maybe this (with additional parsing):
|
I created an almost working version for it based on latest pip package. Checking with MutuallyExclusiveGroup it's clear that there are missing parts. |
I think the 2nd solution suggested by @espdev is pretty reasonable. Otherwise, [shameless plug] you may consider using Cloup (a set of click extensions): from pathlib import Path
import cloup
from cloup.constraints import mutually_exclusive
@cloup.command()
@cloup.argument("items", nargs=-1, required=False)
@cloup.option("-f", "--file-path", type=cloup.file_path(exists=True))
@cloup.constraint(mutually_exclusive, ["items", "file_path"])
def cmd(items: Tuple[str], file_path: Path):
... If at least one of the parameters has to be provided, you should use the |
I have a use case where I'd like to accept a list of items contained in a file given by -f or an arbitrary number of positional arguments. Unfortunately Click only allows this on arguments rather than options. So would it be possible to support a mix of mutually exclusive options and arguments?
The text was updated successfully, but these errors were encountered: