diff --git a/src/cli.rs b/src/cli.rs index 997cb9c..1b2cb1b 100644 --- a/src/cli.rs +++ b/src/cli.rs @@ -6,7 +6,7 @@ use std::path::PathBuf; #[clap(about, version, author)] #[clap(group( ArgGroup::new("mode") - .args(&["no_changes", "force"]) + .args(&["dry_run", "force"]) .multiple(false) ))] pub struct Cli { @@ -17,9 +17,9 @@ pub struct Cli { #[clap(short, long)] pub quiet: bool, - /// Nur anzeigen, aber keine realen Änderungen vornehmen - #[clap(short, long)] - pub no_changes: bool, + /// Nur anzeigen, aber keine realen Änderungen vornehmen (dry-run) + #[clap(short = 'n', long = "dry-run", alias = "no-changes")] + pub dry_run: bool, /// Existierende Dateien überschreiben #[clap(short, long)] @@ -36,4 +36,8 @@ pub struct Cli { /// Erlaubt, auch das Wurzelverzeichnis anzupassen #[clap(long)] pub modify_root: bool, + + /// Auch symbolische Links und Special Files verarbeiten + #[clap(long)] + pub special: bool, } diff --git a/src/main.rs b/src/main.rs index 8907bfa..14655d3 100644 --- a/src/main.rs +++ b/src/main.rs @@ -14,6 +14,20 @@ use sanitizer::{clean_filename, is_excluded, is_safe_rename}; use std::fs; use walkdir::WalkDir; +// Standard-Ausschlussmuster (ähnlich wie detox) +const DEFAULT_EXCLUDES: &[&str] = &[ + ".git", + ".git/**", + ".svn", + ".svn/**", + "node_modules", + "node_modules/**", + ".cache", + ".cache/**", + "__pycache__", + "__pycache__/**", +]; + /// Startpunkt des Programms fn main() -> Result<()> { // Initialisiere Logger @@ -26,9 +40,14 @@ fn main() -> Result<()> { let config = Config::from_default_locations(args.verbose)?; // let config = Config::load(".NameToUnix.conf", args.verbose)?; - // Ausschlussmuster (Glob-Patterns) vorbereiten - let exclude_patterns = args - .exclude + // Ausschlussmuster (Glob-Patterns) vorbereiten - Default-Excludes + User-Excludes + let mut all_excludes = DEFAULT_EXCLUDES + .iter() + .map(|s| s.to_string()) + .collect::>(); + all_excludes.extend(args.exclude.clone()); + + let exclude_patterns = all_excludes .iter() .map(|pattern| { Pattern::new(pattern) @@ -89,6 +108,15 @@ fn main() -> Result<()> { continue; } + // Special Files (Symlinks, etc.) nur mit --special verarbeiten + let file_type = entry.file_type(); + if !args.special && (!file_type.is_file() && !file_type.is_dir()) { + if args.verbose { + debug!("Skip special file: {}", old_path.display()); + } + continue; + } + // Dateiname (oder Verzeichnisname) ermitteln let filename = old_path.file_name().ok_or_else(|| { anyhow::anyhow!( @@ -105,7 +133,7 @@ fn main() -> Result<()> { info!("{} -> {}", old_path.display(), new_path.display()); } - if !args.no_changes && is_safe_rename(old_path, &new_path, args.force) { + if !args.dry_run && is_safe_rename(old_path, &new_path, args.force) { fs::rename(old_path, &new_path).with_context(|| { format!( "Fehler beim Umbenennen: {} -> {}",