Initial upload: DevDash CLI with TUI dashboard
Some checks failed
CI / test (push) Has been cancelled
Some checks failed
CI / test (push) Has been cancelled
This commit is contained in:
26
src/config/config_manager.py
Normal file
26
src/config/config_manager.py
Normal file
@@ -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)
|
||||
Reference in New Issue
Block a user