#!/usr/bin/env python3 """Start the local GovOPlaN release console.""" from __future__ import annotations import argparse from pathlib import Path import secrets import sys from govoplan_release.workspace import DEFAULT_WORKSPACE_ROOT def main() -> int: parser = argparse.ArgumentParser(description=__doc__) parser.add_argument("--host", default="127.0.0.1", help="Bind host. Defaults to 127.0.0.1.") parser.add_argument("--port", type=int, default=8765, help="Bind port. Defaults to 8765.") parser.add_argument("--workspace-root", type=Path, default=DEFAULT_WORKSPACE_ROOT) parser.add_argument("--no-token", action="store_true", help="Disable the local API token guard.") args = parser.parse_args() try: import uvicorn except ImportError: print("uvicorn is required. Install the meta development environment with `pip install -r requirements-dev.txt`.", file=sys.stderr) return 2 from server.app import create_app workspace_root = args.workspace_root.expanduser().resolve() token = None if args.no_token else secrets.token_urlsafe(24) app = create_app(workspace_root=workspace_root, token=token) url = f"http://{args.host}:{args.port}/" if token: url = f"{url}?token={token}" print("GovOPlaN release console") print(f" workspace: {workspace_root}") print(f" url: {url}") print(" mode: local release dashboard; mutating actions require explicit confirmation") uvicorn.run(app, host=args.host, port=args.port, log_level="info") return 0 if __name__ == "__main__": raise SystemExit(main())