Skip to content

markdown

Class info

🛈 DocStrings

get_cmd_markdown

get_cmd_markdown(
    instance: Any, command: str | None = None, include_subcommands: bool = False
) -> str

Generate markdown documentation for a command.

Hidden parameters and subcommands are left out.

Parameters:

Name Type Description Default
instance Any

A CLI app instance (Typer, Click, etc.)

required
command str | None

Optional specific command to document (supports dot notation)

None
include_subcommands bool

Whether to include documentation for (nested) subcommands

False

Returns:

Type Description
str

Formatted markdown string with command documentation

Source code in src/clinspector/introspect/markdown.py
def get_cmd_markdown(
    instance: Any,
    command: str | None = None,
    include_subcommands: bool = False,
) -> str:
    """Generate markdown documentation for a command.

    Hidden parameters and subcommands are left out.

    Args:
        instance: A CLI app instance (Typer, Click, etc.)
        command: Optional specific command to document (supports dot notation)
        include_subcommands: Whether to include documentation for (nested) subcommands

    Returns:
        Formatted markdown string with command documentation
    """
    info = get_cmd_info(instance, command)
    if not info:
        return ""

    env = _get_jinja_env()
    param_template = env.from_string(_PARAM_TEMPLATE)
    command_template = env.from_string(_COMMAND_TEMPLATE)
    return "\n".join(
        command_template.render(
            info=cmd,
            params=[p for p in cmd.params if not p.hidden],
            param_template=param_template,
        )
        for cmd in _iter_commands(info, include_subcommands)
    )