11"""ConfigDrift CLI entry point."""
22
3- import typer
4- from enum import Enum
53from pathlib import Path
4+ from typing import Dict , Any , Optional
5+ from enum import Enum
6+
7+ import typer
68from rich .console import Console
79from rich .table import Table
8- from typing import Any
910
1011try :
1112 from revenueholdings_license import require_license
@@ -16,11 +17,13 @@ def require_license(product: str) -> None: # type: ignore[misc]
1617 pass
1718
1819from configdrift import __version__
20+ from configdrift .loader import load_file
1921from configdrift .diff import (
22+ ChangeType ,
2023 Severity ,
24+ diff_configs ,
2125 diff_environments ,
2226)
23- from configdrift .loader import load_file
2427
2528app = typer .Typer (
2629 name = "configdrift" ,
@@ -68,20 +71,20 @@ def check(
6871 console .print ("[red]ERROR: Provide at least 2 config files to compare.[/red]" )
6972 raise typer .Exit (code = 1 )
7073
71- env_configs : dict [str , dict [str , Any ]] = {}
74+ env_configs : Dict [str , Dict [str , Any ]] = {}
7275 env_labels = []
7376
7477 if len (files ) == 2 :
7578 env_labels = [baseline , target ]
7679 else :
7780 env_labels = [f"file_{ i + 1 } " for i in range (len (files ))]
7881
79- for label , filepath in zip (env_labels , files , strict = False ):
82+ for label , filepath in zip (env_labels , files ):
8083 try :
8184 env_configs [label ] = load_file (filepath )
8285 except Exception as e :
8386 console .print (f"[red]Error loading { filepath } : { e } [/red]" )
84- raise typer .Exit (code = 1 ) from e
87+ raise typer .Exit (code = 1 )
8588
8689 baseline_env = env_labels [0 ]
8790 results = diff_environments (env_configs , baseline_env = baseline_env )
@@ -100,7 +103,7 @@ def check(
100103 raise typer .Exit (code = 1 )
101104
102105
103- def _output_table (results : dict [str , Any ], baseline_env : str ):
106+ def _output_table (results : Dict [str , Any ], baseline_env : str ):
104107 for env_name , diff_result in results .items ():
105108 if not diff_result .changes :
106109 continue
@@ -132,7 +135,7 @@ def _output_table(results: dict[str, Any], baseline_env: str):
132135 console .print ()
133136
134137
135- def _output_json (results : dict [str , Any ]):
138+ def _output_json (results : Dict [str , Any ]):
136139 import json
137140 output = {}
138141 for env_name , diff_result in results .items ():
@@ -155,16 +158,16 @@ def _output_json(results: dict[str, Any]):
155158
156159@app .command ()
157160def scan (
158- dirs : list [str ] | None = typer .Argument (None , help = "Directories containing config files. Each dir is treated as an environment." ),
161+ dirs : Optional [ list [str ]] = typer .Argument (None , help = "Directories containing config files. Each dir is treated as an environment." ),
159162 baseline : str = typer .Option ("dev" , "--baseline" , "-b" , help = "Baseline directory name for comparison." ),
160- config : str | None = typer .Option (None , "--config" , "-c" , help = "Path to .configdrift.yaml config file." ),
163+ config : Optional [ str ] = typer .Option (None , "--config" , "-c" , help = "Path to .configdrift.yaml config file." ),
161164 output : OutputFormat = typer .Option (OutputFormat .TABLE , "--output" , "-o" , help = "Output format." ),
162165):
163166 """Scan directories of config files and compare environments."""
164167 if config :
165168 # Load config file for directory → env mapping (raw, not flattened)
166169 import yaml as _yaml
167- with open (config , encoding = "utf-8" ) as _f :
170+ with open (config , "r" , encoding = "utf-8" ) as _f :
168171 cfg_data = _yaml .safe_load (_f ) or {}
169172 dir_mapping = cfg_data .get ("environments" , {})
170173 elif dirs :
@@ -181,7 +184,7 @@ def scan(
181184 console .print (f"[red]Baseline environment '{ baseline } ' not found.[/red]" )
182185 raise typer .Exit (code = 1 )
183186
184- env_configs : dict [str , dict [str , Any ]] = {}
187+ env_configs : Dict [str , Dict [str , Any ]] = {}
185188 for env_name , dir_path in dir_mapping .items ():
186189 env_configs [env_name ] = {}
187190 p = Path (dir_path )
0 commit comments