-
Notifications
You must be signed in to change notification settings - Fork 33
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
Is click.MultiCommand
supported?
#38
Comments
click.MultiCommand
supported?
Rich-click works by overwriting the default You can explicitly use the rich-click classes to get around this (see example) but yeah - we don't have a I guess it should be possible to add support for this though. Need to do something similar to the |
Any ETA on this? Would love to use rick-click but can't use it without |
No ETA sorry, no. Happy to accept PRs to tackle this though. |
According to click docs click.Command.format_help() method calls .format_usage(), .format_help_text(), .format_options() and .format_epilog() for the actual output. In contrast, rich_format_help(), which is used in RichCommand, appears to be a a single block of code. class click.MultiCommand(Command) overrides .format_options() which calls the parent's .format_options() and then its own .format_commands() which does three things when outputting the subcommands:
Perhaps 1. and 2. can/should be added to rich_format_help() (unless the logic already exists), but it seems that it works fine on MultiCommands as it is. A simple solution to @nilsvu's problem seems to be overriding the .format_help() of MultiCommand by the same code used in rich_click.Command (as suggested by @ewels). This solution works fine for me. class Cli(click.MultiCommand):
...
def format_help(self, ctx: click.Context, formatter: click.HelpFormatter):
rich_format_help(self, ctx, formatter) |
Thanks @hsunner, that's very helpful and works well! Sounds like simply subclassing |
We can have a slightly better and more "official" solution for this shortly. TLDR: it should be straightforward to add a |
Here's a minimal example using
click.MultiCommand
for lazy loading of subcommands. Is this already supported and I just haven't figured out how to use it, or is this not supported yet?The text was updated successfully, but these errors were encountered: