fix: Cargo.lock tracken, verbose durchreichen, Config-Fehler melden, Platzhalter-Kollision beheben

- Cargo.lock aus .gitignore entfernt (Rust-Konvention: für Binaries committen)
- verbose-Parameter in clean_filename() wird jetzt korrekt von args.verbose
  durchgereicht statt hardcoded false
- Config::load() gibt bei Parse-Fehlern eine Warnung aus statt den Fehler
  still zu schlucken
- Platzhalter für C++/C# von CPLUSPLUS/CSHARP zu NTUxCPLUSPLUSx/NTUxCSHARPx
  geändert um Kollisionen mit echten Dateinamen zu vermeiden

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
This commit is contained in:
Dieter Schlüter 2026-02-13 04:32:59 +01:00
commit bd82fd7b30
5 changed files with 35 additions and 30 deletions

View file

@ -1,5 +1,5 @@
use anyhow::{Context, Result};
use log::{debug, info};
use log::{debug, info, warn};
use serde::Deserialize;
use std::collections::HashMap;
use std::fs;
@ -41,18 +41,27 @@ impl Config {
}
}
/// Öffentliche Methode zum Laden einer Konfiguration aus einem Pfad
/// Öffentliche Methode zum Laden einer Konfiguration aus einem Pfad.
/// Gibt Standardwerte zurück wenn die Datei nicht existiert,
/// propagiert aber Parse-Fehler als Warnung.
pub fn load(path: &str, verbose: bool) -> Result<Self> {
let cfg_path = Path::new(path);
if !cfg_path.exists() {
if verbose {
info!(
"Keine Konfigurationsdatei '{}' gefunden. Verwende Standardwerte.",
path
);
}
return Ok(Self::default());
}
match Self::load_internal(cfg_path, verbose) {
Ok(config) => Ok(config),
Err(_) => {
if verbose {
info!(
"Keine Konfigurationsdatei '{}' gefunden. Verwende Standardwerte.",
path
);
}
Err(e) => {
warn!(
"Fehler beim Laden der Konfigurationsdatei '{}': {}. Verwende Standardwerte.",
path, e
);
Ok(Self::default())
}
}

View file

@ -197,7 +197,7 @@ fn main() -> Result<()> {
// Dateiname ermitteln und bereinigen
let filename = old_path.file_name()?;
let new_name = clean_filename(filename, &config, &sequence, false)?;
let new_name = clean_filename(filename, &config, &sequence, args.verbose)?;
let new_path = old_path.with_file_name(&new_name);
Some(RenameOperation {

View file

@ -225,22 +225,30 @@ pub fn clean_filename(
}
}
// Eindeutige Platzhalter, die in echten Dateinamen praktisch nicht vorkommen.
// Bestehen nur aus \w-Zeichen (für RE_INVALID), ohne Mehrfach-Unterstriche (für RE_MULTI),
// ohne führende Unterstriche (für trim_leading_underscores).
const PH_CPLUSPLUS: &str = "NTUxCPLUSPLUSx";
const PH_CPLUSPLUS_LC: &str = "NTUxcplusplusx";
const PH_CSHARP: &str = "NTUxCSHARPx";
const PH_CSHARP_LC: &str = "NTUxcsharpx";
/// Schützt spezielle Identifikatoren vor der Umwandlung
fn preserve_special_identifiers(input: &str) -> String {
input
.replace("C++", "CPLUSPLUS")
.replace("c++", "cplusplus")
.replace("C#", "CSHARP")
.replace("c#", "csharp")
.replace("C++", PH_CPLUSPLUS)
.replace("c++", PH_CPLUSPLUS_LC)
.replace("C#", PH_CSHARP)
.replace("c#", PH_CSHARP_LC)
}
/// Stellt spezielle Identifikatoren wieder her
fn restore_special_identifiers(input: &str) -> String {
input
.replace("CPLUSPLUS", "C++")
.replace("cplusplus", "c++")
.replace("CSHARP", "C#")
.replace("csharp", "c#")
.replace(PH_CPLUSPLUS, "C++")
.replace(PH_CPLUSPLUS_LC, "c++")
.replace(PH_CSHARP, "C#")
.replace(PH_CSHARP_LC, "c#")
}
/// Fasst alle fest eingebauten Ersetzungen zusammen.