#!/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())