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
|
# Rust / Cargo
|
||||||
/target
|
/target
|
||||||
**/*.rs.bk
|
**/*.rs.bk
|
||||||
Cargo.lock
|
|
||||||
*.pdb
|
*.pdb
|
||||||
|
|
||||||
# IDEs
|
# IDEs
|
||||||
|
|
|
||||||
11
Cargo.lock
generated
11
Cargo.lock
generated
|
|
@ -16,7 +16,6 @@ dependencies = [
|
||||||
"env_logger",
|
"env_logger",
|
||||||
"glob",
|
"glob",
|
||||||
"indicatif",
|
"indicatif",
|
||||||
"itertools",
|
|
||||||
"log",
|
"log",
|
||||||
"once_cell",
|
"once_cell",
|
||||||
"predicates",
|
"predicates",
|
||||||
|
|
@ -24,7 +23,6 @@ dependencies = [
|
||||||
"regex",
|
"regex",
|
||||||
"serde",
|
"serde",
|
||||||
"tempfile",
|
"tempfile",
|
||||||
"thiserror",
|
|
||||||
"toml",
|
"toml",
|
||||||
"unicode-segmentation",
|
"unicode-segmentation",
|
||||||
"walkdir",
|
"walkdir",
|
||||||
|
|
@ -478,15 +476,6 @@ version = "1.70.1"
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
checksum = "7943c866cc5cd64cbc25b2e01621d07fa8eb2a1a23160ee81ce38704e97b8ecf"
|
checksum = "7943c866cc5cd64cbc25b2e01621d07fa8eb2a1a23160ee81ce38704e97b8ecf"
|
||||||
|
|
||||||
[[package]]
|
|
||||||
name = "itertools"
|
|
||||||
version = "0.12.1"
|
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
|
||||||
checksum = "ba291022dbbd398a455acf126c1e341954079855bc60dfdda641363bd6922569"
|
|
||||||
dependencies = [
|
|
||||||
"either",
|
|
||||||
]
|
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "js-sys"
|
name = "js-sys"
|
||||||
version = "0.3.77"
|
version = "0.3.77"
|
||||||
|
|
|
||||||
|
|
@ -1,5 +1,5 @@
|
||||||
use anyhow::{Context, Result};
|
use anyhow::{Context, Result};
|
||||||
use log::{debug, info};
|
use log::{debug, info, warn};
|
||||||
use serde::Deserialize;
|
use serde::Deserialize;
|
||||||
use std::collections::HashMap;
|
use std::collections::HashMap;
|
||||||
use std::fs;
|
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> {
|
pub fn load(path: &str, verbose: bool) -> Result<Self> {
|
||||||
let cfg_path = Path::new(path);
|
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) {
|
match Self::load_internal(cfg_path, verbose) {
|
||||||
Ok(config) => Ok(config),
|
Ok(config) => Ok(config),
|
||||||
Err(_) => {
|
Err(e) => {
|
||||||
if verbose {
|
warn!(
|
||||||
info!(
|
"Fehler beim Laden der Konfigurationsdatei '{}': {}. Verwende Standardwerte.",
|
||||||
"Keine Konfigurationsdatei '{}' gefunden. Verwende Standardwerte.",
|
path, e
|
||||||
path
|
);
|
||||||
);
|
|
||||||
}
|
|
||||||
Ok(Self::default())
|
Ok(Self::default())
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -197,7 +197,7 @@ fn main() -> Result<()> {
|
||||||
|
|
||||||
// Dateiname ermitteln und bereinigen
|
// Dateiname ermitteln und bereinigen
|
||||||
let filename = old_path.file_name()?;
|
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);
|
let new_path = old_path.with_file_name(&new_name);
|
||||||
|
|
||||||
Some(RenameOperation {
|
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
|
/// Schützt spezielle Identifikatoren vor der Umwandlung
|
||||||
fn preserve_special_identifiers(input: &str) -> String {
|
fn preserve_special_identifiers(input: &str) -> String {
|
||||||
input
|
input
|
||||||
.replace("C++", "CPLUSPLUS")
|
.replace("C++", PH_CPLUSPLUS)
|
||||||
.replace("c++", "cplusplus")
|
.replace("c++", PH_CPLUSPLUS_LC)
|
||||||
.replace("C#", "CSHARP")
|
.replace("C#", PH_CSHARP)
|
||||||
.replace("c#", "csharp")
|
.replace("c#", PH_CSHARP_LC)
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Stellt spezielle Identifikatoren wieder her
|
/// Stellt spezielle Identifikatoren wieder her
|
||||||
fn restore_special_identifiers(input: &str) -> String {
|
fn restore_special_identifiers(input: &str) -> String {
|
||||||
input
|
input
|
||||||
.replace("CPLUSPLUS", "C++")
|
.replace(PH_CPLUSPLUS, "C++")
|
||||||
.replace("cplusplus", "c++")
|
.replace(PH_CPLUSPLUS_LC, "c++")
|
||||||
.replace("CSHARP", "C#")
|
.replace(PH_CSHARP, "C#")
|
||||||
.replace("csharp", "c#")
|
.replace(PH_CSHARP_LC, "c#")
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Fasst alle fest eingebauten Ersetzungen zusammen.
|
/// Fasst alle fest eingebauten Ersetzungen zusammen.
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue