CLI App
Main CLI application entry point.
Main CLI application entry point.
This module defines the qsh command-line application, its top-level callback,
and a set of built-in commands. Plugins are discovered and loaded lazily to
keep startup fast.
Examples: Running the CLI and showing help::
qsh --help
Starting the REPL with a specific context and JSON output::
qsh --context prod --output json repl
Printing shell completion for zsh::
qsh completion zsh > ~/.zsh/completions/_qsh
OutputFormat
Bases: str, Enum
flowchart TD
qsh.cli.app.OutputFormat[OutputFormat]
click qsh.cli.app.OutputFormat href "" "qsh.cli.app.OutputFormat"
Output format options for the CLI.
app_callback
app_callback(context: Annotated[str | None, Option('--context', help='Select context from config')] = None, output: Annotated[OutputFormat | None, Option('-o', '--output', help='Output format: table|json')] = None, verbose: Annotated[bool, Option('--verbose', '-v', help='Enable verbose logging')] = False, wrap: Annotated[bool, Option('--wrap', help='Allow multiline wrapping in table output')] = False, private: Annotated[bool, Option('--private', help='Use private API endpoints (requires super admin access)')] = False) -> None
CLI for QuEra's Quantum Computing Service.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
context
|
Annotated[str | None, Option('--context', help='Select context from config')]
|
Optional config context to use for this invocation. |
None
|
output
|
Annotated[OutputFormat | None, Option('-o', '--output', help='Output format: table|json')]
|
Optional output format override ("table" or "json"). |
None
|
verbose
|
Annotated[bool, Option('--verbose', '-v', help='Enable verbose logging')]
|
Enable verbose logging for diagnostics. |
False
|
wrap
|
Annotated[bool, Option('--wrap', help='Allow multiline wrapping in table output')]
|
Allow multiline wrapping in table output. |
False
|
private
|
Annotated[bool, Option('--private', help='Use private API endpoints (requires super admin access)')]
|
Use private API endpoints (requires super admin access). |
False
|
Source code in qsh/cli/app.py
216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 | |
clear_app_context_cache
clear_app_context_cache() -> None
Clear the cached AppContext and config to force reload next time.
Source code in qsh/cli/app.py
315 316 317 318 319 320 | |
clear_context_bound_auth_providers
clear_context_bound_auth_providers() -> None
Drop in-memory auth providers so the next use rebuilds from the active context.
Providers are keyed only by name in the process-global registry. After a context switch, stale instances retain the previous context's audience and other settings. Unregistering discards in-memory objects only; it does not call logout or delete context-isolated credential caches.
Source code in qsh/cli/app.py
323 324 325 326 327 328 329 330 331 332 333 334 | |
cli_main
cli_main() -> None
Main entry point that loads plugins only when needed.
This function may terminate the process with a non-zero exit code on error.
Source code in qsh/cli/app.py
512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 | |
completion_command
completion_command(shell: Annotated[str, Argument(help='Shell type: bash, zsh, fish, or powershell')]) -> None
Generate shell completion scripts for the given shell.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
shell
|
Annotated[str, Argument(help='Shell type: bash, zsh, fish, or powershell')]
|
Target shell ( |
required |
Raises:
| Type | Description |
|---|---|
typer.Exit
|
If the shell is unsupported. Examples: qsh completion bash > ~/.qsh_completion source ~/.qsh_completion qsh completion zsh > ~/.zsh/completions/_qsh qsh completion fish > ~/.config/fish/completions/qsh.fish |
Source code in qsh/cli/app.py
458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 | |
context_list
context_list(output: str | None = typer.Option(None, '-o', '--output', help='Output format (json, table).')) -> None
List all configured contexts.
Source code in qsh/cli/app.py
393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 | |
context_set
context_set(name: str = typer.Argument(..., help='Context name to set as active.')) -> None
Set the active context in config and the current process.
Updates sticky session state (including a startup --context override)
and clears cached AppContext config. When the effective context changes,
it unregisters in-memory auth providers so the next auth use rebuilds from
the new context without logout.
Source code in qsh/cli/app.py
354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 | |
context_show
context_show(output: str | None = typer.Option(None, '-o', '--output', help='Output format (json, table).')) -> None
Display the current active context name.
Source code in qsh/cli/app.py
342 343 344 345 346 347 348 349 350 351 | |
create_app_context
create_app_context() -> 'AppContext'
Create and cache an AppContext populated from current CLI state.
The context and settings are cached across invocations during a single process run to avoid repeated disk I/O.
Returns:
| Type | Description |
|---|---|
'AppContext'
|
Initialized |
Source code in qsh/cli/app.py
257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 | |
help_command
help_command(ctx: Context) -> None
Show help for QSH commands (equivalent to qsh --help).
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
ctx
|
Context
|
Typer context (unused; kept for parity with Typer conventions). |
required |
Source code in qsh/cli/app.py
438 439 440 441 442 443 444 445 446 447 | |
load_plugins
load_plugins(app: Typer, ctx_provider: Callable[[], 'AppContext']) -> None
Lazy wrapper around plugin loading.
This keeps plugin discovery imports out of module import time for fast built-ins
like qsh version and qsh completion.
Source code in qsh/cli/app.py
94 95 96 97 98 99 100 101 102 | |
main
main() -> None
Entry point for the qsh command.
Source code in qsh/cli/app.py
536 537 538 | |
repl_command
repl_command() -> None
Start an interactive REPL session.
The REPL provides an interactive shell where you can run QSH commands without having to type 'qsh' before each command. It supports tab completion and maintains the current context config.
Examples: qsh repl # Start interactive shell qsh --context prod repl # Start REPL with specific context
Source code in qsh/cli/app.py
421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 | |
setup_logging
setup_logging(verbose: bool = False) -> logging.Logger
Configure logging with a rich handler and return the main logger.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
verbose
|
bool
|
Enable verbose log level (DEBUG) when True, otherwise WARNING. |
False
|
Returns:
| Type | Description |
|---|---|
Logger
|
Configured logger named |
Source code in qsh/cli/app.py
189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 | |
version_command
version_command() -> None
Show version information.
Source code in qsh/cli/app.py
450 451 452 453 454 455 | |