Skip to content

Compilations Commands

CLI commands for managing quantum program compilations.

Compilations CLI presenter - Explicit Typer commands for compilation management.

This module provides the CLI presentation layer for compilations. It uses the StandardCliCommands factory to generate consistent commands with minimal boilerplate.

register_cli

register_cli(app: Typer, ctx_provider: Callable[[], AppContext], logger: Logger) -> None

Register compilations CLI commands with the main app.

This function creates a Typer sub-application for compilations and registers all compilation-related commands. It's called by the plugin loader during application initialization.

:param app: Main Typer application to attach commands to. :param ctx_provider: Callable that returns the current AppContext. :param logger: Logger instance for this plugin.

Source code in qsh/plugins/compilations/cli.py
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
def register_cli(
    app: typer.Typer, ctx_provider: Callable[[], AppContext], logger: logging.Logger
) -> None:
    """Register compilations CLI commands with the main app.

    This function creates a Typer sub-application for compilations and registers
    all compilation-related commands. It's called by the plugin loader during
    application initialization.

    :param app: Main Typer application to attach commands to.
    :param ctx_provider: Callable that returns the current AppContext.
    :param logger: Logger instance for this plugin.
    """
    resource_app = typer.Typer(help="Manage compilations.", no_args_is_help=True)

    def _table_schema_factory() -> TableSchema:
        ctx = ctx_provider()
        resolver = ClientConfigResolver(ctx, plugin_name="compilations")
        if resolver.resolve_visibility() is Visibility.PRIVATE:
            return _PRIVATE_SCHEMA
        return _PUBLIC_SCHEMA

    # Create CLI commands factory
    cli_commands = StandardCliCommands(
        client_class=CompilationsClient,
        ctx_provider=ctx_provider,
        logger=logger,
        resource_name="compilation",
        table_schema_factory=_table_schema_factory,
    )

    # Generate standard commands
    list_cmd = cli_commands.create_list_command()
    create_cmd = cli_commands.create_create_command(V2QpuModeCompilationsPostRequest)

    # Register commands
    resource_app.command("list")(list_cmd)
    resource_app.command("create")(create_cmd)

    # Custom get command with proper parameter name
    @resource_app.command("get")
    def get_cmd(
        qpu_mode: str | None = typer.Option(None, "--qpu-mode", help=QPU_MODE_HELP),
        compilation_id: str = typer.Argument(..., help="Compilation ID"),
        raw: bool = typer.Option(False, "--raw", help=RAW_MODE_RECEIVE_HELP),
        output: str | None = typer.Option(None, "-o", "--output", help=OUTPUT_FORMAT_HELP),
    ) -> None:
        """Get details of a specific compilation."""
        ctx = ctx_provider()
        logger.debug(f"Getting compilation: qpu_mode={qpu_mode}, id={compilation_id}, raw={raw}")

        client = CompilationsClient(ctx)
        result = client.get(qpu_mode=qpu_mode, id=compilation_id, raw=raw)

        # Convert to dict if it's a Pydantic model
        if not raw:
            result = result.model_dump(mode="json")

        render(result, output or ctx.effective_output_format)

    # Aliases
    show_cmd = cli_commands.create_alias_command(get_cmd, "Show")
    resource_app.command("show")(show_cmd)

    # Register the compilations sub-app with the main app
    app.add_typer(resource_app, name="compilations")
    logger.debug("Registered compilations CLI commands")