many-repos/many_repos/config.py

26 lines
685 B
Python
Raw Normal View History

2024-05-25 23:43:15 +02:00
import tomllib
from pathlib import Path
from typing import NamedTuple
from many_repos import errors
class Source(NamedTuple):
source_type: str
username: str
token: str
class Config(NamedTuple):
output_dir: str | Path
sources: dict[str, Source] | None
def load_config(config_path: str | Path) -> Config:
config_path = Path(config_path)
if not config_path.exists():
raise errors.ConfigNotFound(f"Config at path {config_path} not found!")
with config_path.open() as fp:
parsed_config = tomllib.load(fp)
return Config(output_dir="~/repos/", sources={"gitlab": Source(source_type="gitlab", username="justscreamy", token="urgay")})