neue Optionen (-r, Installskript) installiert
This commit is contained in:
parent
0bab728d62
commit
d78e318d8a
15 changed files with 273 additions and 42 deletions
|
|
@ -13,6 +13,14 @@ pub struct Cli {
|
|||
/// Pfade (Dateien und Verzeichnisse) zum rekursiven Anpassen
|
||||
pub paths: Vec<PathBuf>,
|
||||
|
||||
/// Explizite Konfigurationsdatei (bypassed Standard-Hierarchie)
|
||||
#[clap(long = "conf", value_name = "FILE")]
|
||||
pub config_file: Option<PathBuf>,
|
||||
|
||||
/// Rekursive Verarbeitung von Unterverzeichnissen aktivieren
|
||||
#[clap(short = 'r', long)]
|
||||
pub recursive: bool,
|
||||
|
||||
/// Ausgaben unterdrücken (keine Umbenennungsinfos auf stdout)
|
||||
#[clap(short, long)]
|
||||
pub quiet: bool,
|
||||
|
|
|
|||
|
|
@ -57,6 +57,19 @@ impl Config {
|
|||
}
|
||||
}
|
||||
}
|
||||
|
||||
/// Lädt Konfiguration aus spezifischer Datei (fehlschlägt bei nicht-existierender Datei)
|
||||
pub fn from_file(path: &Path, verbose: bool) -> Result<Self> {
|
||||
if !path.exists() {
|
||||
return Err(anyhow::anyhow!(
|
||||
"Konfigurationsdatei nicht gefunden: {}",
|
||||
path.display()
|
||||
));
|
||||
}
|
||||
|
||||
Self::load_internal(path, verbose)
|
||||
}
|
||||
|
||||
/// Sucht nach Konfigurationsdateien in verschiedenen Orten und kombiniert sie
|
||||
pub fn from_default_locations(verbose: bool) -> Result<Self> {
|
||||
// Prioritätenreihenfolge (später überschreibt früher):
|
||||
|
|
|
|||
21
src/main.rs
21
src/main.rs
|
|
@ -60,9 +60,13 @@ fn main() -> Result<()> {
|
|||
colored::control::set_override(false);
|
||||
}
|
||||
|
||||
// Optional Konfigurationsdatei laden
|
||||
let config = Config::from_default_locations(args.verbose)?;
|
||||
// let config = Config::load(".NameToUnix.conf", args.verbose)?;
|
||||
// Config-Datei laden: entweder --conf oder Standard-Hierarchie
|
||||
let config = if let Some(config_path) = &args.config_file {
|
||||
Config::from_file(config_path, args.verbose)
|
||||
.with_context(|| format!("Fehler beim Laden der Konfiguration: {}", config_path.display()))?
|
||||
} else {
|
||||
Config::from_default_locations(args.verbose)?
|
||||
};
|
||||
|
||||
// Ausschlussmuster (Glob-Patterns) vorbereiten - Default-Excludes + User-Excludes
|
||||
let mut all_excludes = DEFAULT_EXCLUDES
|
||||
|
|
@ -90,7 +94,16 @@ fn main() -> Result<()> {
|
|||
for path in &args.paths {
|
||||
// Alle Einträge sammeln, damit zuerst die tiefsten umbenannt werden
|
||||
let mut entries = Vec::new();
|
||||
for entry_result in WalkDir::new(path)
|
||||
|
||||
let walker = if args.recursive {
|
||||
// Recursive: unbegrenzte Tiefe
|
||||
WalkDir::new(path)
|
||||
} else {
|
||||
// Non-recursive: max_depth(1) verarbeitet nur direkte Kinder
|
||||
WalkDir::new(path).max_depth(1)
|
||||
};
|
||||
|
||||
for entry_result in walker
|
||||
.into_iter()
|
||||
.filter_entry(|e| !is_excluded(e, &exclude_patterns))
|
||||
{
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue