@@ -45,7 +45,7 @@ def _json_null_handler(obj: Any) -> Any:
4545 Severity ,
4646 diff_environments ,
4747)
48- from configdrift .loader import load_file
48+ from configdrift .loader import get_literal_dotted_keys , load_file
4949
5050app = typer .Typer (
5151 name = "configdrift" ,
@@ -322,14 +322,15 @@ def fix(
322322 False , "--dry-run" , "-n" , help = "Show what would change without modifying files."
323323 ),
324324) -> None :
325+ baseline_path = Path (files [0 ])
326+ if not baseline_path .exists ():
327+ console .print (f"[red]ERROR: Baseline file not found: { baseline_path } [/red]" )
328+ raise typer .Exit (code = 1 )
325329 try :
326- baseline_data , baseline_literal_dotted = load_file (str (baseline_path ))
330+ baseline_data = load_file (str (baseline_path ))
327331 except Exception as e :
328332 console .print (f"[red]Error loading baseline config: { e } [/red]" )
329333 raise typer .Exit (code = 1 ) from e
330- if not baseline_path .exists ():
331- console .print (f"[red]ERROR: Baseline file not found: { baseline_path } [/red]" )
332- raise typer .Exit (code = 1 )
333334
334335
335336 # Track targets that could not be fixed so the command returns a
@@ -346,7 +347,7 @@ def fix(
346347 continue
347348
348349 try :
349- target_data , target_literal_dotted = load_file (str (target_path ))
350+ target_data = load_file (str (target_path ))
350351 except Exception as e :
351352 console .print (f"[red]Error loading target config { target_path } : { e } [/red]" )
352353 failed_targets .append (str (target_path ))
@@ -488,7 +489,7 @@ def fix(
488489 # source document are kept as single mapping keys rather
489490 # than being re-split into nested levels.
490491 # Merge literal dotted keys from both baseline and target
491- all_literal_dotted = baseline_literal_dotted | target_literal_dotted
492+ all_literal_dotted = get_literal_dotted_keys ( str ( baseline_path )) | get_literal_dotted_keys ( str ( target_path ))
492493 nested : dict [str , Any ] = {}
493494 for k , v in target_data .items ():
494495 if "." not in k or k in all_literal_dotted :
@@ -504,7 +505,7 @@ def fix(
504505 atomic_write_text (target_path , _json .dumps (nested , indent = 2 , default = _json_null_handler ) + "\n " )
505506 elif ext in (".yaml" , ".yml" ):
506507 # Reconstruct nested structure from flat keys for YAML output
507- all_literal_dotted = baseline_literal_dotted | target_literal_dotted
508+ all_literal_dotted = get_literal_dotted_keys ( str ( baseline_path )) | get_literal_dotted_keys ( str ( target_path ))
508509 nested : dict [str , Any ] = {}
509510 for k , v in target_data .items ():
510511 if "." not in k or k in all_literal_dotted :
@@ -542,7 +543,7 @@ def _has_null(val: Any) -> bool:
542543 )
543544 failed_targets .append (str (target_path ))
544545 continue
545- all_literal_dotted = baseline_literal_dotted | target_literal_dotted
546+ all_literal_dotted = get_literal_dotted_keys ( str ( baseline_path )) | get_literal_dotted_keys ( str ( target_path ))
546547 nested_toml : dict [str , Any ] = {}
547548 for k , v in target_data .items ():
548549 if "." not in k or k in all_literal_dotted :
0 commit comments