-
Notifications
You must be signed in to change notification settings - Fork 10
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
Add support for option groups on cloup.Group
#98
Comments
It's very unusual for me to add options to the root group, because:
What I usually end up to do is defining a class Anyway, I generally don't like too much libraries that tell me what I should or not do, so feel free to open a PR. Nonetheless, note that it's very easy to work around the limitation (which is why I took the liberty of not allowing option groups by default): from cloup import ConstraintMixin, OptionGroupMixin, Group
class MyGroup(OptionGroupMixin, Group):
pass
@cloup.group(cls=MyGroup)
def cmd:
... If we include |
The workaround you proposed indeed does the trick. Thanks for providing a solution! 👍 For the record, this experiments led to the discovery of a bug with command sections that has been filled at #99. |
Yes, please. This is definitely a bug. I'll fix it later in the day. |
Just moved the bug into its own issue at #99. |
Now back to the main topic, a.k.a. option groups on When I started using Click several years ago, I was taken aback by its way of sharing options in a group. As you pointed out in your second argument, the I didn't found an elegant way to allow for arbitrary positions of commands and options, so I followed Click's recommandation called it a day. But maybe we can revisit this limitation and work around it. |
I can't see an easy way. If you want to type options after subcommands, the easiest workaround is what I explained above: reusing options when it's needed. And thinking again about it, I actually prefer this solution to Group parameters:
from functools import partial
class Params:
shared = option('--shared', ...)
common = partial(option, '--common', default=1, ...)
@command()
@Params.shared
@Params.common(required=True)
def foo(shared, common):
...
@command()
@Params.shared
@Params.common()
def bar(shared, common):
... Of course this sharing can be extended to Cloup's option groups. |
Closing as this is a subset of |
This is explicitly mentioned in the documentation as not supported on purpose. But the documentation also ask for feedbacks on potential use-cases. Here is mine.
My
mpm
CLI has a total of 15 common options shared by 10 sub-commands. To reduce code duplication, I naturally used acloup.group
decorator, and it works great.Now, To make things easier to apprehend to users, I'd like to group some of these common options by family. I'd like for instance to regroup
--manager
,--exclude
,--all-managers
and--xkcd
options under the "Package manager selection options" banner. Unfortunately I can't becausecloup.group
does't support option groups.Is this a valid case for considering adding this feature? Note that I do not need to apply any constraint (yet?), so implementation can exclude constraints.
The text was updated successfully, but these errors were encountered: