466f4ee13a
tracker-policy-pr / check-pr (pull_request) Successful in 13s
test / integration-docker (pull_request) Successful in 34s
test / unit (pull_request) Successful in 49s
lint / lint (push) Successful in 57s
test / integration-firecracker (pull_request) Successful in 3m29s
test / coverage (pull_request) Successful in 20s
test / publish-infra (pull_request) Has been skipped
Brings in the two commits main gained: #472 (CLI cleanup — remove `info`, split `list active` into a top-level `active`, simplify `list`) and the terminology glossary. #472 was written against the old flat cli/ layout, so its semantics are reconciled into the reorg'd cli/commands/ structure: * new `active` command lives at cli/commands/active.py, registered in the lazy registry and listed in `help` (not left at the flat path). * `info` removed: deleted cli/commands/info.py, dropped from the registry and `help`. * `list` simplified to list-available-only, using the reorg's os.getcwd()/constants.PROG conventions. * the `list active` -> `active` doc wording applied to the backend docstrings that our split moved into base.py / selection.py. Our reorg wins for the fully-rewritten dispatcher (cli/__init__ shim, backend facade). pyright: 0 errors. Full unit suite green (2243). Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
59 lines
2.2 KiB
Python
59 lines
2.2 KiB
Python
"""CLI subcommand registry.
|
|
|
|
One module per `bot-bottle <command>`, each exposing a `cmd_<name>(argv)`
|
|
handler. This package `__init__` maps command names to their handlers
|
|
**lazily**: a short-lived CLI run dispatches exactly one command, so
|
|
importing all twelve handlers (and their transitive deps — backend,
|
|
manifest, orchestrator, …) up front is wasted work. Each COMMANDS value is
|
|
a thin wrapper that imports its handler's module on first call. Shared CLI
|
|
helpers (`constants`, `tui`) stay one level up in the `cli` package.
|
|
"""
|
|
|
|
from __future__ import annotations
|
|
|
|
from importlib import import_module
|
|
from typing import Callable
|
|
|
|
# command name -> "<submodule>:<handler attr>". Kept as strings so building
|
|
# the registry imports nothing; the module loads only when dispatched.
|
|
_HANDLERS: dict[str, str] = {
|
|
"active": "active:cmd_active",
|
|
"backend": "backend:cmd_backend",
|
|
"cleanup": "cleanup:cmd_cleanup",
|
|
"commit": "commit:cmd_commit",
|
|
"edit": "edit:cmd_edit",
|
|
"help": "help:cmd_help",
|
|
"init": "init:cmd_init",
|
|
"list": "list:cmd_list",
|
|
"login": "login:cmd_login",
|
|
"resume": "resume:cmd_resume",
|
|
"start": "start:cmd_start",
|
|
"supervise": "supervise:cmd_supervise",
|
|
}
|
|
|
|
|
|
def _lazy(spec: str) -> Callable[[list[str]], "int | None"]:
|
|
"""Wrap a `<module>:<attr>` handler so its module is imported only when
|
|
the command is actually dispatched, not when the registry is built."""
|
|
module, attr = spec.split(":")
|
|
|
|
def run(argv: list[str]) -> "int | None":
|
|
handler = getattr(import_module(f".{module}", __name__), attr)
|
|
return handler(argv)
|
|
|
|
run.__name__ = attr
|
|
return run
|
|
|
|
|
|
COMMANDS = {name: _lazy(spec) for name, spec in _HANDLERS.items()}
|
|
|
|
# Commands that manage host prerequisites (or are otherwise store-free) and
|
|
# must run before — or without — a migrated DB. `backend` provisions/probes
|
|
# the host (TAP pool, /dev/kvm, firecracker) and never opens the store, so
|
|
# gating it on the schema breaks preflight on a fresh CI runner where stdin
|
|
# isn't a TTY and the migration prompt can't be answered. `help` and `login`
|
|
# likewise never touch the store.
|
|
NO_MIGRATION_COMMANDS = frozenset({"backend", "help", "login"})
|
|
|
|
__all__ = ["COMMANDS", "NO_MIGRATION_COMMANDS"]
|