Files
2026-04-13 22:04:05 +02:00

62 lines
1.5 KiB
Python

"""Configuration management for myclaude."""
import json
from pathlib import Path
CONFIG_DIR = Path.home() / ".myclaude"
CONFIG_FILE = CONFIG_DIR / "config.json"
def save_config(repo_url: str) -> None:
"""Save or update the myclaude configuration file.
Args:
repo_url: The SSH URL of the central git repository.
"""
CONFIG_DIR.mkdir(parents=True, exist_ok=True)
existing = _read_file() if CONFIG_FILE.exists() else {}
existing["repo_url"] = repo_url
with CONFIG_FILE.open("w", encoding="utf-8") as f:
json.dump(existing, f, indent=2)
def load_config() -> dict:
"""Load the myclaude configuration file.
Returns:
The configuration as a dictionary.
Raises:
FileNotFoundError: If the configuration file does not exist.
"""
if not CONFIG_FILE.exists():
raise FileNotFoundError(
f"Configuration file not found at {CONFIG_FILE}. "
"Run 'myclaude init . --repo <url>' first."
)
return _read_file()
def get_repo_url() -> str:
"""Get the configured central repository URL.
Returns:
The SSH URL of the central git repository.
Raises:
FileNotFoundError: If the configuration file does not exist.
KeyError: If repo_url is not found in the configuration.
"""
config = load_config()
if "repo_url" not in config:
raise KeyError(
"No 'repo_url' found in configuration. "
"Run 'myclaude init . --repo <url>' first."
)
return config["repo_url"]
def _read_file() -> dict:
with CONFIG_FILE.open("r", encoding="utf-8") as f:
return json.load(f)