import os import yaml DEFAULT_CONFIG_PATH = os.path.expanduser("~/.config/loopaware/infra-cli.yaml") class Config: def __init__(self, config_path=None): self.path = config_path or os.environ.get("INFRA_CONFIG") or DEFAULT_CONFIG_PATH self.data = self._load() def _load(self): if not os.path.exists(self.path): # Fallback to local config if exists if os.path.exists("config.yaml"): self.path = "config.yaml" else: raise FileNotFoundError(f"Config file not found at {self.path}. Please create it based on config.yaml.example") with open(self.path, 'r') as f: return yaml.safe_vars(f) if hasattr(yaml, 'safe_vars') else yaml.safe_load(f) def get(self, key, default=None): parts = key.split('.') val = self.data for part in parts: if isinstance(val, dict) and part in val: val = val[part] else: return default return val