initial commit: dynamic infra tooling cli
This commit is contained in:
commit
db843ceec8
9 changed files with 339 additions and 0 deletions
30
infra_cli/config.py
Normal file
30
infra_cli/config.py
Normal file
|
|
@ -0,0 +1,30 @@
|
|||
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
|
||||
Loading…
Add table
Add a link
Reference in a new issue