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
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207 | 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
cli_commands = StandardCliCommands(
client_class=DefinitionsClient,
ctx_provider=ctx_provider,
logger=logger,
resource_name="definition",
table_schema_factory=_table_schema_factory,
)
list_cmd = create_group_list_command(
ctx_provider=ctx_provider,
client_factory=lambda ctx: DefinitionsClient(ctx),
logger=logger,
resource_name="definition",
table_schema_factory=_table_schema_factory,
renderer=lambda payload, output: render(payload, output),
table_renderer=lambda payload, schema, **kwargs: render_payload_table(
format_group_summary_table_payload(payload), schema, **kwargs
),
)
create_cmd = create_group_create_command(
ctx_provider=ctx_provider,
client_factory=lambda ctx: DefinitionsClient(ctx),
logger=logger,
resource_name="definition",
plugin_name="definitions",
request_model=TaskDefinitionRequest,
renderer=lambda payload, output: render(payload, output),
)
resource_app.command("list")(list_cmd)
resource_app.command("create")(create_cmd)
submit_cmd = cli_commands.create_alias_command(create_cmd, "Submit")
resource_app.command("submit")(submit_cmd)
@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)
if not raw:
result = result.model_dump(mode="json")
render(result, output or ctx.effective_output_format)
show_cmd = cli_commands.create_alias_command(get_cmd, "Show")
resource_app.command("show")(show_cmd)
app.add_typer(resource_app, name="definitions")
logger.debug("Registered definitions CLI commands")
|