display_help

safir.click.display_help(main, ctx, topic=None, subtopic=None)

Show help for a Click command.

This function implements a help command for command-line interfaces using Click. It supports commands and subcommands, displaying the same information as would be shown by --help. The resulting help text is displayed with click.echo.

Parameters:
  • main (Group) – Top-level Click command group.

  • ctx (Context) – Click context.

  • topic (str | None, default: None) – Command for which to get help.

  • subtopic (str | None, default: None) – Subcommand of that command for which to get help.

Raises:
  • click.UsageError – Raised if the given help topic or subtopic does not correspond to a registered Click command.

  • RuntimeError – Raised if the Click context has no parent, meaning that this was called with an invalid context or from the top-level Click command.

Return type:

None

Examples

This function should normally be called from a top-level help command. Assuming that the top-level Click group is named main, here is the typical usage:

@main.command()
@click.argument("topic", default=None, required=False, nargs=1)
@click.argument("subtopic", default=None, required=False, nargs=1)
@click.pass_context
def help(
    ctx: click.Context, topic: str | None, subtopic: str | None
) -> None:
    display_help(main, ctx, topic, subtopic)