From b06799d7059c6eaade7f4eda56ac4859a6f0ebf1 Mon Sep 17 00:00:00 2001 From: Daniel Hofstetter Date: Sun, 31 Aug 2025 16:13:49 +0200 Subject: [PATCH 1/2] uucore/clap_l10n: use iterator from lines() --- src/uucore/src/lib/mods/clap_localization.rs | 14 ++++++-------- 1 file changed, 6 insertions(+), 8 deletions(-) diff --git a/src/uucore/src/lib/mods/clap_localization.rs b/src/uucore/src/lib/mods/clap_localization.rs index b179a6cf44f..a4e0096fa19 100644 --- a/src/uucore/src/lib/mods/clap_localization.rs +++ b/src/uucore/src/lib/mods/clap_localization.rs @@ -243,8 +243,8 @@ fn handle_invalid_value_error(err: Error, maybe_colorize: impl Fn(&str, Color) - } else { // Fallback if we can't extract context - use clap's default formatting let rendered_str = err.render().to_string(); - let lines: Vec<&str> = rendered_str.lines().collect(); - if let Some(main_error_line) = lines.first() { + + if let Some(main_error_line) = rendered_str.lines().next() { eprintln!("{main_error_line}"); eprintln!(); eprintln!("{}", translate!("common-help-suggestion")); @@ -284,10 +284,9 @@ pub fn handle_clap_error_with_exit_code(err: Error, util_name: &str, exit_code: } // For other simple validation errors, use the same simple format as other errors - let lines: Vec<&str> = rendered_str.lines().collect(); - if let Some(main_error_line) = lines.first() { + if let Some(main_error_line) = rendered_str.lines().next() { // Keep the "error: " prefix for test compatibility - eprintln!("{}", main_error_line); + eprintln!("{main_error_line}"); eprintln!(); // Use the execution phrase for the help suggestion to match test expectations eprintln!("{}", translate!("common-help-suggestion")); @@ -323,11 +322,10 @@ pub fn handle_clap_error_with_exit_code(err: Error, util_name: &str, exit_code: // For other errors, show just the error and help suggestion let rendered_str = err.render().to_string(); - let lines: Vec<&str> = rendered_str.lines().collect(); // Print error message (first line) - if let Some(first_line) = lines.first() { - eprintln!("{}", first_line); + if let Some(first_line) = rendered_str.lines().next() { + eprintln!("{first_line}"); } // For other errors, just show help suggestion From 62f82efca118e1e0b352d409f358dc04b19c3b1d Mon Sep 17 00:00:00 2001 From: Daniel Hofstetter Date: Sun, 31 Aug 2025 16:21:30 +0200 Subject: [PATCH 2/2] uucore/clap_l10n: move exit outside match --- src/uucore/src/lib/mods/clap_localization.rs | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/src/uucore/src/lib/mods/clap_localization.rs b/src/uucore/src/lib/mods/clap_localization.rs index a4e0096fa19..91b7f078d0e 100644 --- a/src/uucore/src/lib/mods/clap_localization.rs +++ b/src/uucore/src/lib/mods/clap_localization.rs @@ -93,17 +93,16 @@ fn handle_display_errors(err: Error) -> ! { let usage_label = translate!("common-usage"); let localized_help = help_text.replace("Usage:", &format!("{usage_label}:")); - print!("{}", localized_help); - std::process::exit(0); + print!("{localized_help}"); } ErrorKind::DisplayVersion => { // For version, use clap's built-in formatting and exit with 0 // Output to stdout as expected by tests print!("{}", err.render()); - std::process::exit(0); } _ => unreachable!("handle_display_errors called with non-display error"), } + std::process::exit(0); } /// Handle UnknownArgument errors with localization and suggestions