mirror of
https://github.com/Alishahryar1/free-claude-code.git
synced 2026-07-03 14:05:26 +02:00
61 lines
1.8 KiB
Python
61 lines
1.8 KiB
Python
"""CLI entry points for the installed package."""
|
|
|
|
from __future__ import annotations
|
|
|
|
from pathlib import Path
|
|
|
|
|
|
def _load_env_template() -> str:
|
|
"""Load the canonical root env template from package resources or source."""
|
|
import importlib.resources
|
|
|
|
packaged = importlib.resources.files("cli").joinpath("env.example")
|
|
if packaged.is_file():
|
|
return packaged.read_text("utf-8")
|
|
|
|
source_template = Path(__file__).resolve().parents[1] / ".env.example"
|
|
if source_template.is_file():
|
|
return source_template.read_text(encoding="utf-8")
|
|
|
|
raise FileNotFoundError("Could not find bundled or source .env.example template.")
|
|
|
|
|
|
def serve() -> None:
|
|
"""Start the FastAPI server (registered as `free-claude-code` script)."""
|
|
import uvicorn
|
|
|
|
from cli.process_registry import kill_all_best_effort
|
|
from config.settings import get_settings
|
|
|
|
settings = get_settings()
|
|
try:
|
|
uvicorn.run(
|
|
"api.app:create_asgi_app",
|
|
factory=True,
|
|
host=settings.host,
|
|
port=settings.port,
|
|
log_level="debug",
|
|
timeout_graceful_shutdown=5,
|
|
)
|
|
finally:
|
|
kill_all_best_effort()
|
|
|
|
|
|
def init() -> None:
|
|
"""Scaffold config at ~/.config/free-claude-code/.env (registered as `fcc-init`)."""
|
|
config_dir = Path.home() / ".config" / "free-claude-code"
|
|
env_file = config_dir / ".env"
|
|
|
|
if env_file.exists():
|
|
print(f"Config already exists at {env_file}")
|
|
print("Delete it first if you want to reset to defaults.")
|
|
return
|
|
|
|
config_dir.mkdir(parents=True, exist_ok=True)
|
|
template = _load_env_template()
|
|
env_file.write_text(template, encoding="utf-8")
|
|
print(f"Config created at {env_file}")
|
|
print(
|
|
"Edit it to set your API keys and model preferences, then run: free-claude-code"
|
|
)
|