Add core modules (session, recorder, database)
This commit is contained in:
53
.termflow/config.py
Normal file
53
.termflow/config.py
Normal file
@@ -0,0 +1,53 @@
|
|||||||
|
"""Configuration management for Term Flow."""
|
||||||
|
|
||||||
|
import os
|
||||||
|
from pathlib import Path
|
||||||
|
from typing import Optional
|
||||||
|
|
||||||
|
import yaml
|
||||||
|
|
||||||
|
|
||||||
|
class Config:
|
||||||
|
"""Configuration manager for Term Flow."""
|
||||||
|
|
||||||
|
def __init__(self):
|
||||||
|
self._config_dir = Path(os.environ.get("TERMFLOW_HOME", Path.home() / ".termflow"))
|
||||||
|
self._config_dir.mkdir(parents=True, exist_ok=True)
|
||||||
|
self._db_path = os.environ.get(
|
||||||
|
"TERMFLOW_DB",
|
||||||
|
str(self._config_dir / "sessions.db")
|
||||||
|
)
|
||||||
|
self._git_cache = os.environ.get(
|
||||||
|
"TERMFLOW_GIT_CACHE",
|
||||||
|
str(self._config_dir / "git_cache")
|
||||||
|
)
|
||||||
|
self._default_style = os.environ.get("TERMFLOW_STYLE", "detailed")
|
||||||
|
|
||||||
|
@property
|
||||||
|
def config_dir(self) -> Path:
|
||||||
|
return self._config_dir
|
||||||
|
|
||||||
|
@property
|
||||||
|
def db_path(self) -> str:
|
||||||
|
return self._db_path
|
||||||
|
|
||||||
|
@property
|
||||||
|
def git_cache(self) -> str:
|
||||||
|
return self._git_cache
|
||||||
|
|
||||||
|
@property
|
||||||
|
def default_style(self) -> str:
|
||||||
|
return self._default_style
|
||||||
|
|
||||||
|
def get_session_db_path(self) -> str:
|
||||||
|
Path(self._db_path).parent.mkdir(parents=True, exist_ok=True)
|
||||||
|
return self._db_path
|
||||||
|
|
||||||
|
def get_git_cache_dir(self) -> str:
|
||||||
|
Path(self._git_cache).mkdir(parents=True, exist_ok=True)
|
||||||
|
return self._git_cache
|
||||||
|
|
||||||
|
|
||||||
|
def get_config() -> Config:
|
||||||
|
"""Get the current configuration."""
|
||||||
|
return Config()
|
||||||
Reference in New Issue
Block a user