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:
parent
de9bb4fd03
commit
bd82fd7b30
5 changed files with 35 additions and 30 deletions
1
.gitignore
vendored
1
.gitignore
vendored
|
|
@ -1,7 +1,6 @@
|
|||
# Rust / Cargo
|
||||
/target
|
||||
**/*.rs.bk
|
||||
Cargo.lock
|
||||
*.pdb
|
||||
|
||||
# IDEs
|
||||
|
|
|
|||
11
Cargo.lock
generated
11
Cargo.lock
generated
|
|
@ -16,7 +16,6 @@ dependencies = [
|
|||
"env_logger",
|
||||
"glob",
|
||||
"indicatif",
|
||||
"itertools",
|
||||
"log",
|
||||
"once_cell",
|
||||
"predicates",
|
||||
|
|
@ -24,7 +23,6 @@ dependencies = [
|
|||
"regex",
|
||||
"serde",
|
||||
"tempfile",
|
||||
"thiserror",
|
||||
"toml",
|
||||
"unicode-segmentation",
|
||||
"walkdir",
|
||||
|
|
@ -478,15 +476,6 @@ version = "1.70.1"
|
|||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "7943c866cc5cd64cbc25b2e01621d07fa8eb2a1a23160ee81ce38704e97b8ecf"
|
||||
|
||||
[[package]]
|
||||
name = "itertools"
|
||||
version = "0.12.1"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "ba291022dbbd398a455acf126c1e341954079855bc60dfdda641363bd6922569"
|
||||
dependencies = [
|
||||
"either",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "js-sys"
|
||||
version = "0.3.77"
|
||||
|
|
|
|||
|
|
@ -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);
|
||||
match Self::load_internal(cfg_path, verbose) {
|
||||
Ok(config) => Ok(config),
|
||||
Err(_) => {
|
||||
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(e) => {
|
||||
warn!(
|
||||
"Fehler beim Laden der Konfigurationsdatei '{}': {}. Verwende Standardwerte.",
|
||||
path, e
|
||||
);
|
||||
Ok(Self::default())
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -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 {
|
||||
|
|
|
|||
|
|
@ -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.
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue