diff --git a/src/config/config_manager.py b/src/config/config_manager.py new file mode 100644 index 0000000..fc98d41 --- /dev/null +++ b/src/config/config_manager.py @@ -0,0 +1,26 @@ +import json +import os +from pathlib import Path +from src.config.settings import Settings + + +class ConfigManager: + def __init__(self, config_path: str = None): + if config_path is None: + config_path = os.environ.get( + "DEVDASH_CONFIG", + str(Path.home() / ".devdash" / "config.json") + ) + self.config_path = Path(config_path) + + def load_config(self) -> Settings: + if self.config_path.exists(): + with open(self.config_path) as f: + data = json.load(f) + return Settings(**data) + return Settings() + + def save_config(self, settings: Settings) -> None: + self.config_path.parent.mkdir(parents=True, exist_ok=True) + with open(self.config_path, "w") as f: + json.dump(settings.model_dump(), f, indent=2)