register_cli(app: Typer, ctx_provider: Callable[[], AppContext], logger: Logger) -> None
Register definitions CLI commands with the main app.
This function creates a Typer sub-application for definitions and registers
all definition-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/definitions/cli.py
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
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 | def register_cli(
app: typer.Typer, ctx_provider: Callable[[], AppContext], logger: logging.Logger
) -> None:
"""Register definitions CLI commands with the main app.
This function creates a Typer sub-application for definitions and registers
all definition-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 task definitions.", no_args_is_help=True)
def _table_schema_factory() -> TableSchema:
ctx = ctx_provider()
resolver = ClientConfigResolver(ctx, plugin_name="definitions")
if resolver.resolve_visibility() is Visibility.PRIVATE:
return _PRIVATE_SCHEMA
return _PUBLIC_SCHEMA
# Create CLI commands factory
cli_commands = StandardCliCommands(
client_class=DefinitionsClient,
ctx_provider=ctx_provider,
logger=logger,
resource_name="definition",
table_schema_factory=_table_schema_factory,
)
# Generate standard commands
list_cmd = cli_commands.create_list_command()
create_cmd = cli_commands.create_create_command(TaskDefinitionRequest)
# 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),
definition_id: str = typer.Argument(..., help="Definition 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 definition."""
ctx = ctx_provider()
logger.debug(f"Getting definition: qpu_mode={qpu_mode}, id={definition_id}, raw={raw}")
client = DefinitionsClient(ctx)
result = client.get(qpu_mode=qpu_mode, id=definition_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 definitions sub-app with the main app
app.add_typer(resource_app, name="definitions")
logger.debug("Registered definitions CLI commands")
|