@@ -5,9 +5,7 @@ use crate::workspace::WorkspaceContext;
55use std:: fs;
66
77/// Run the clean command
8- pub fn run_clean ( ctx : & WorkspaceContext , cache : bool , backups : bool , reports : bool ) -> RailResult < ( ) > {
9- let mut cleaned_any = false ;
10-
8+ pub fn run_clean ( ctx : & WorkspaceContext , cache : bool , backups : bool , reports : bool , check : bool ) -> RailResult < ( ) > {
119 // If no flags provided, clean everything (cache, reports, and ALL backups)
1210 let clean_all = !cache && !backups && !reports;
1311
@@ -17,6 +15,78 @@ pub fn run_clean(ctx: &WorkspaceContext, cache: bool, backups: bool, reports: bo
1715 let prune_backups = backups && !clean_all;
1816 let delete_all_backups = clean_all;
1917
18+ // Dry-run mode: show what would be cleaned
19+ if check {
20+ println ! ( "🔍 DRY-RUN MODE - Showing what would be cleaned:\n " ) ;
21+ let mut would_clean = false ;
22+
23+ if clean_cache {
24+ let cache_path = ctx
25+ . workspace_root
26+ . join ( "target" )
27+ . join ( "cargo-rail" )
28+ . join ( "metadata.json" ) ;
29+ let old_cache = ctx. workspace_root . join ( "target" ) . join ( "rail" ) ;
30+
31+ if cache_path. exists ( ) {
32+ println ! ( " 📄 {}" , cache_path. display( ) ) ;
33+ would_clean = true ;
34+ }
35+ if old_cache. exists ( ) {
36+ println ! ( " 📁 {} (legacy)" , old_cache. display( ) ) ;
37+ would_clean = true ;
38+ }
39+ }
40+
41+ if clean_reports {
42+ let report_dir = ctx. workspace_root . join ( "target" ) . join ( "cargo-rail" ) ;
43+ if report_dir. exists ( ) {
44+ for entry in fs:: read_dir ( & report_dir) . ok ( ) . into_iter ( ) . flatten ( ) . flatten ( ) {
45+ let path = entry. path ( ) ;
46+ if path. is_file ( ) && path. extension ( ) . is_some_and ( |ext| ext == "md" ) {
47+ println ! ( " 📄 {}" , path. display( ) ) ;
48+ would_clean = true ;
49+ }
50+ }
51+ }
52+ }
53+
54+ if prune_backups || delete_all_backups {
55+ let backup_manager = BackupManager :: new ( & ctx. workspace_root ) ;
56+ if backup_manager. has_backups ( ) {
57+ let backup_list = backup_manager. list_backups ( ) ?;
58+ if delete_all_backups {
59+ for backup in & backup_list {
60+ println ! ( " 📦 backup: {}" , backup. id) ;
61+ would_clean = true ;
62+ }
63+ } else {
64+ let max_backups = ctx
65+ . config
66+ . as_ref ( )
67+ . map ( |c| c. unify . max_backups )
68+ . unwrap_or_else ( || UnifyConfig :: default ( ) . max_backups ) ;
69+ if backup_list. len ( ) > max_backups {
70+ for backup in backup_list. iter ( ) . skip ( max_backups) {
71+ println ! ( " 📦 backup (prune): {}" , backup. id) ;
72+ would_clean = true ;
73+ }
74+ }
75+ }
76+ }
77+ }
78+
79+ if would_clean {
80+ println ! ( "\n ✋ To execute cleanup, run: cargo rail clean" ) ;
81+ } else {
82+ println ! ( "Nothing to clean" ) ;
83+ }
84+ return Ok ( ( ) ) ;
85+ }
86+
87+ // Execute cleanup
88+ let mut cleaned_any = false ;
89+
2090 if clean_cache {
2191 clean_metadata_cache ( ctx) ?;
2292 cleaned_any = true ;
0 commit comments