-
-
Notifications
You must be signed in to change notification settings - Fork 1.4k
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
Adding group to CommandCollection loses group options #347
Comments
This comment was marked as off-topic.
This comment was marked as off-topic.
Same here, completely broken.
the above code ONLY outputs "test" |
This comment was marked as off-topic.
This comment was marked as off-topic.
the two referenced issues don't help with the above situation where the options are on one of the command groups being specified in the collection. For example: @click.group()
@click.option(
'--profile',
required=True,
type=str,
)
@click.pass_context
def with_profile(ctx, profile):
ctx.obj = {"profile": profile}
@click.group()
def without_profile():
pass
@click.command(cls=click.CommandCollection, sources=[with_profile, without_profile])
def cli():
pass
if __name__ == '__main__':
cli() Doesn't work. Neither does doing |
I don't know if I'm rationalizing but to me this is actually expected behaviour: you are taking commands from one or more groups, and making the cli group pretend that they are in its group, thus the original groups are no longer in the picture... so why would their options still be used? You could say that the options should be used but that would mean the original groups are still present which is not the case I think, as it would imply each command of the original groups are getting a second parent. Is it not possible to put those options on the command collection itself? If not, or if not all groups added to the command collection use the special options, you could also just refactor the group option code into your own decorator like |
@schollii It depends a bit on how you frame the usecase of the command collection. I think of it as a way to merge two groups. You could put the two groups side by side as sub commands, but maybe for usability reasons you'd rather have all the commands at the same level, so you merge the groups instead. |
I have found a workaround for this, you will need to extend
|
I hit this issue today. Mentally, In my case, the purpose is to merge built-in commands with custom subcommands (similar to git). All the built-in commands need the same setup. |
This issue is ready to be documented or closed now that changes to command collection have been merged. |
Goal:
init
command that creates a valid config file.Attempt
Problem
The file parameter (and any other parameters/options on the
cli_main
group) get dropped/ignored when the commands are accessed via the CommandCollection.Not sure if this is a bug (it's certainly unobvious), and I'm curious as to what other approaches could solve my problem? Looks like I can't override a group parameter for a specific command either, right? And validation callbacks don't appear to get passed context or anything else I can use to figure out which command is being run...
The text was updated successfully, but these errors were encountered: