Files
alfred/scripts/validate_settings.py

67 lines
1.8 KiB
Python

#!/usr/bin/env python3
"""Validate settings against schema."""
import sys
from pathlib import Path
# Add parent directory to path
sys.path.insert(0, str(Path(__file__).resolve().parent.parent))
from alfred.settings_bootstrap import ConfigSource, SettingsBootstrap
from alfred.settings_schema import SCHEMA
def main():
"""
Validate settings from .env against schema.
Returns:
0 if valid, 1 if invalid
"""
print("🔍 Validating settings...")
try:
base_dir = Path(__file__).resolve().parent.parent
source = ConfigSource.from_base_dir(base_dir)
# Check if .env exists
if not source.env_path.exists():
print(f"{source.env_path} not found")
print(" Run 'make bootstrap' to generate it")
return 1
# Create bootstrap instance (loads and validates)
bootstrapper = SettingsBootstrap(source)
bootstrapper._load_sources()
bootstrapper._resolve_settings()
bootstrapper._validate_settings()
print(f"✅ All {len(SCHEMA)} settings are valid!")
# Show summary by category
print("\n📊 Settings summary:")
categories = {}
for definition in SCHEMA:
if definition.category not in categories:
categories[definition.category] = 0
categories[definition.category] += 1
for category, count in sorted(categories.items()):
print(f" {category}: {count} settings")
return 0
except ValueError as e:
print(f"❌ Validation failed: {e}")
return 1
except Exception as e:
print(f"❌ Error: {e}")
import traceback # noqa: PLC0415
traceback.print_exc()
return 1
if __name__ == "__main__":
sys.exit(main())