Skip to content

Instantly share code, notes, and snippets.

@ali1234
Created August 10, 2022 00:35
Show Gist options
  • Save ali1234/d8cf6eeb2e9c99e881d4bbb2aeb7dcbd to your computer and use it in GitHub Desktop.
Save ali1234/d8cf6eeb2e9c99e881d4bbb2aeb7dcbd to your computer and use it in GitHub Desktop.
Click subcommand recursive help output example
@click.group(invoke_without_command=True, no_args_is_help=True)
@click.version_option()
@click.help_option()
@click.option('--help-all', is_flag=True, help='Show help for all subcommands.')
@click.pass_context
def yourcommand(ctx, help_all):
"""This group will print all help pages for subcommands."""
if help_all:
print(yourcommand.get_help(ctx))
def help_recurse(group, ctx):
for scmd in group.list_commands(ctx):
cmd = group.get_command(ctx, scmd)
nctx = click.Context(cmd, ctx, scmd)
if isinstance(cmd, click.Group):
help_recurse(cmd, nctx)
else:
print()
print(cmd.get_help(nctx))
help_recurse(yourcommand, ctx)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment