refactor: Code-Qualität und Usability verbessern
- Ungenutzte Dependencies entfernt (itertools, thiserror) - 560 Build-Artefakte (target/) aus Git-Tracking entfernt - NO_COLOR Umgebungsvariable unterstützen (https://no-color.org/) - if let Ok/Err durch idiomatisches match ersetzt - Fehlermeldung bei Aufruf ohne Pfade hinzugefügt - Sequence::default() zu Sequence::standard() umbenannt um Verwechslung mit dem Rust Default-Trait zu vermeiden Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
This commit is contained in:
parent
b08ff38a49
commit
de9bb4fd03
563 changed files with 26 additions and 1600 deletions
23
src/main.rs
23
src/main.rs
|
|
@ -42,9 +42,11 @@ struct RenameOperation {
|
|||
new_path: PathBuf,
|
||||
}
|
||||
|
||||
/// Prüft ob farbige Ausgabe aktiviert sein soll
|
||||
/// Prüft ob farbige Ausgabe aktiviert sein soll.
|
||||
/// Respektiert --no-color Flag, NO_COLOR Umgebungsvariable (https://no-color.org/)
|
||||
/// und ob stdout ein Terminal ist.
|
||||
fn should_use_color(no_color_flag: bool) -> bool {
|
||||
!no_color_flag && std::io::stdout().is_terminal()
|
||||
!no_color_flag && std::env::var_os("NO_COLOR").is_none() && std::io::stdout().is_terminal()
|
||||
}
|
||||
|
||||
/// Startpunkt des Programms
|
||||
|
|
@ -75,7 +77,7 @@ fn main() -> Result<()> {
|
|||
)
|
||||
})?
|
||||
} else {
|
||||
Sequence::default()
|
||||
Sequence::standard()
|
||||
};
|
||||
|
||||
if args.verbose {
|
||||
|
|
@ -116,6 +118,12 @@ fn main() -> Result<()> {
|
|||
}
|
||||
}
|
||||
|
||||
// Prüfe ob Pfade angegeben wurden
|
||||
if args.paths.is_empty() {
|
||||
eprintln!("Keine Pfade angegeben. Nutze 'ntu --help' für Hilfe.");
|
||||
std::process::exit(1);
|
||||
}
|
||||
|
||||
// Für alle angegebenen Pfade
|
||||
for path in &args.paths {
|
||||
// Alle Einträge sammeln, damit zuerst die tiefsten umbenannt werden
|
||||
|
|
@ -140,13 +148,12 @@ fn main() -> Result<()> {
|
|||
.into_iter()
|
||||
.filter_entry(|e| !is_excluded(e, &exclude_patterns))
|
||||
{
|
||||
if let Ok(entry) = entry_result {
|
||||
entries.push(entry);
|
||||
} else if let Err(e) = entry_result {
|
||||
error!(
|
||||
match entry_result {
|
||||
Ok(entry) => entries.push(entry),
|
||||
Err(e) => error!(
|
||||
"{}",
|
||||
format!("Fehler beim Durchlaufen von {}: {}", path.display(), e).red()
|
||||
);
|
||||
),
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -83,8 +83,8 @@ impl Sequence {
|
|||
Self::all().into_iter().find(|s| s.name == name)
|
||||
}
|
||||
|
||||
/// Gibt die Default-Sequence zurück
|
||||
pub fn default() -> Sequence {
|
||||
/// Gibt die Standard-Sequence zurück
|
||||
pub fn standard() -> Sequence {
|
||||
Self::find("default").unwrap()
|
||||
}
|
||||
}
|
||||
|
|
@ -406,7 +406,7 @@ mod tests {
|
|||
#[test]
|
||||
fn test_clean_filename_basic() {
|
||||
let config = Config::default();
|
||||
let sequence = Sequence::default();
|
||||
let sequence = Sequence::standard();
|
||||
|
||||
// Spaces should become underscores
|
||||
assert_eq!(
|
||||
|
|
@ -430,7 +430,7 @@ mod tests {
|
|||
#[test]
|
||||
fn test_clean_filename_hidden_files() {
|
||||
let config = Config::default();
|
||||
let sequence = Sequence::default();
|
||||
let sequence = Sequence::standard();
|
||||
|
||||
// Hidden files should keep their leading dot
|
||||
assert_eq!(
|
||||
|
|
@ -460,7 +460,7 @@ mod tests {
|
|||
#[test]
|
||||
fn test_clean_filename_umlauts() {
|
||||
let config = make_test_config();
|
||||
let sequence = Sequence::default();
|
||||
let sequence = Sequence::standard();
|
||||
|
||||
// German umlauts
|
||||
assert_eq!(
|
||||
|
|
@ -482,7 +482,7 @@ mod tests {
|
|||
#[test]
|
||||
fn test_clean_filename_extensions() {
|
||||
let config = Config::default();
|
||||
let sequence = Sequence::default();
|
||||
let sequence = Sequence::standard();
|
||||
|
||||
// Single extension
|
||||
assert_eq!(
|
||||
|
|
@ -543,7 +543,7 @@ mod tests {
|
|||
#[test]
|
||||
fn test_clean_filename_special_identifiers() {
|
||||
let config = Config::default();
|
||||
let sequence = Sequence::default();
|
||||
let sequence = Sequence::standard();
|
||||
|
||||
// C++ should be preserved
|
||||
assert_eq!(
|
||||
|
|
@ -561,7 +561,7 @@ mod tests {
|
|||
#[test]
|
||||
fn test_clean_filename_no_change_needed() {
|
||||
let config = Config::default();
|
||||
let sequence = Sequence::default();
|
||||
let sequence = Sequence::standard();
|
||||
|
||||
// Already clean filenames should return None
|
||||
assert_eq!(
|
||||
|
|
@ -578,7 +578,7 @@ mod tests {
|
|||
#[test]
|
||||
fn test_clean_filename_empty_after_cleaning() {
|
||||
let config = Config::default();
|
||||
let sequence = Sequence::default();
|
||||
let sequence = Sequence::standard();
|
||||
|
||||
// File with only special chars should become "unnamed"
|
||||
assert_eq!(
|
||||
|
|
@ -590,7 +590,7 @@ mod tests {
|
|||
#[test]
|
||||
fn test_clean_filename_apostrophe() {
|
||||
let config = Config::default();
|
||||
let sequence = Sequence::default();
|
||||
let sequence = Sequence::standard();
|
||||
|
||||
// Apostrophes should be removed (not replaced with underscore)
|
||||
assert_eq!(
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue