Skip to content

synth_click

Class info

🛈 DocStrings

Module for generating Click CLI implementations from CommandInfo objects.

create_group

create_group(cmd_info: CommandInfo, handler: Handler | None = None) -> Group

Create a Click Group from a CommandInfo object.

Parameters:

Name Type Description Default
cmd_info CommandInfo

The CommandInfo object to convert

required
handler Handler | None

Called with the invoked (sub)command's info and its parsed values. Groups are invoked before their subcommands, as usual for click.

None

Returns:

Type Description
Group

A Click Group object with all commands and subcommands

Source code in src/clinspector/synthesis/synth_click.py
def create_group(cmd_info: CommandInfo, handler: Handler | None = None) -> click.Group:
    """Create a Click Group from a CommandInfo object.

    Args:
        cmd_info: The CommandInfo object to convert
        handler: Called with the invoked (sub)command's info and its parsed values.
                 Groups are invoked before their subcommands, as usual for click.

    Returns:
        A Click Group object with all commands and subcommands
    """
    import click

    group = click.Group(
        name=cmd_info.name,
        help=cmd_info.description,
        params=_create_params(cmd_info),
        callback=_callback(cmd_info, handler),
        hidden=cmd_info.hidden,
        epilog=cmd_info.epilog,
        deprecated=cmd_info.deprecated,
    )

    # Add all subcommands recursively
    for name, subcmd in cmd_info.subcommands.items():
        cmd = (
            create_group(subcmd, handler)
            if subcmd.subcommands
            else _create_command(subcmd, handler)
        )
        group.add_command(cmd, name=name)
    return group