Skip to content
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

Customizing --help command for default groups #14

Open
viscrisn opened this issue Sep 1, 2020 · 1 comment
Open

Customizing --help command for default groups #14

viscrisn opened this issue Sep 1, 2020 · 1 comment

Comments

@viscrisn
Copy link

viscrisn commented Sep 1, 2020

Is there a way I can redirect one of the subcommand --help output to the group command's --help?
For example:

@click.group(cls=DefaultGroup, default='foo', default_if_no_args=True)
def cli():
    pass

@cli.command()
def foo():
    click.echo('foo')

cli --help should output foo --help description.

Is this possible to customize --help in this way?

@jpsnyder
Copy link

jpsnyder commented Sep 3, 2020

You can hack this in by inheriting from DefaultGroup and then overwrite the parse_arg() function like so:

    def parse_args(self, ctx, args):
        if (not args or args in (["-h"], ["--help"])) and self.default_if_no_args:
            args.insert(0, self.default_cmd_name)
        return super(DefaultGroup, self).parse_args(ctx, args)

However, this will make it impossible to get the original help messaging containing all the subcommands. So your users will be unaware of the other commands available.

The ideal solution would be to somehow merge the help messages from both the default command and main group. But I'm not sure how to do that...

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants