"""CLI entry point: `python -m bot_bottle.orchestrator `. Commands: run start the webhook server + watchdog + done-signal relay status print the tracked runs (issue -> slug, status) """ from __future__ import annotations import argparse import sys from .config import Config def main(argv: list[str] | None = None) -> int: parser = argparse.ArgumentParser(prog="python -m bot_bottle.orchestrator") sub = parser.add_subparsers(dest="command", required=True) sub.add_parser("run", help="start the webhook server, watchdog, and relay") sub.add_parser("status", help="list tracked runs") args = parser.parse_args(argv) config = Config.from_env() if args.command == "run": from . import bootstrap # pylint: disable=import-outside-toplevel print( f"orchestrator listening on " f"http://{config.webhook_host}:{config.webhook_port}/webhook", file=sys.stderr, ) bootstrap.run(config) return 0 if args.command == "status": from .bootstrap import ( # pylint: disable=import-outside-toplevel BotBottleStateStore, ) store = BotBottleStateStore(config.db_path) for r in store.all(): pr = f"PR#{r.pr_number}" if r.pr_number else "-" print(f"{r.owner}/{r.repo}#{r.issue_number}\t{r.slug}\t{r.status}\t{pr}") return 0 return 2 if __name__ == "__main__": sys.exit(main())