import sys from pathlib import Path from typing import List, Optional def find_config_file(path: Path, names: List[str]) -> Optional[Path]: for name in names: config_path = path / name if config_path.exists(): return config_path for parent in path.parents: config_path = parent / name if config_path.exists(): return config_path return None def get_exit_code(issue_count: int, critical_count: int) -> int: if critical_count > 0: return 4 elif issue_count > 0: return 4 return 0 def format_severity(severity: str) -> str: colors = { "critical": "red", "warning": "yellow", "info": "blue", } return colors.get(severity, "white") def print_error(message: str, exit_code: int = 1): print(f"Error: {message}", file=sys.stderr) sys.exit(exit_code) def validate_path(path: str) -> Path: p = Path(path) if not p.exists(): print_error(f"Path does not exist: {path}", 2) if not p.is_dir(): print_error(f"Path is not a directory: {path}", 2) return p