Yash030/claude-code-proxy
2
1"""CLI entry points for the installed package."""2 3from __future__ import annotations4 5from pathlib import Path6 7 8def _load_env_template() -> str:9 """Load the canonical root env template from package resources or source."""10 import importlib.resources11 12 packaged = importlib.resources.files("cli").joinpath("env.example")13 if packaged.is_file():14 return packaged.read_text("utf-8")15 16 source_template = Path(__file__).resolve().parents[1] / ".env.example"17 if source_template.is_file():18 return source_template.read_text(encoding="utf-8")19 20 raise FileNotFoundError("Could not find bundled or source .env.example template.")21 22 23def serve() -> None:24 """Start the FastAPI server (registered as `free-claude-code` script)."""25 import uvicorn26 27 from cli.process_registry import kill_all_best_effort28 from config.settings import get_settings29 30 settings = get_settings()31 try:32 uvicorn.run(33 "api.app:create_asgi_app",34 factory=True,35 host=settings.host,36 port=settings.port,37 log_level="debug",38 timeout_graceful_shutdown=5,39 )40 finally:41 kill_all_best_effort()42 43 44def init() -> None:45 """Scaffold config at ~/.config/free-claude-code/.env (registered as `fcc-init`)."""46 config_dir = Path.home() / ".config" / "free-claude-code"47 env_file = config_dir / ".env"48 49 if env_file.exists():50 print(f"Config already exists at {env_file}")51 print("Delete it first if you want to reset to defaults.")52 return53 54 config_dir.mkdir(parents=True, exist_ok=True)55 template = _load_env_template()56 env_file.write_text(template, encoding="utf-8")57 print(f"Config created at {env_file}")58 print(59 "Edit it to set your API keys and model preferences, then run: free-claude-code"60 )61 