From c7165fb52ceec855748f316ca88289a769916954 Mon Sep 17 00:00:00 2001 From: figsoda Date: Thu, 5 Jan 2023 14:33:37 -0500 Subject: [PATCH] avoid directly indexing when possible --- src/commands/mod.rs | 9 ++++----- 1 file changed, 4 insertions(+), 5 deletions(-) diff --git a/src/commands/mod.rs b/src/commands/mod.rs index 0ef92ef..d893e61 100644 --- a/src/commands/mod.rs +++ b/src/commands/mod.rs @@ -149,11 +149,10 @@ pub fn run( let error = FinalError::with_title(format!("Cannot compress to '{output_path}'.")) .detail(first_detail_message) .detail(format!( - "The compression format '{}' does not accept multiple files.", - &formats[0] + "The compression format '{first_format}' does not accept multiple files.", )) .detail("Formats that bundle files into an archive are .tar and .zip.") - .hint(format!("Try inserting '.tar' or '.zip' before '{}'.", &formats[0])) + .hint(format!("Try inserting '.tar' or '.zip' before '{first_format}'.")) .hint(format!("From: {output_path}")) .hint(format!("To: {suggested_output_path}")); @@ -245,7 +244,7 @@ pub fn run( .map(|(input_path, _)| PathBuf::from(input_path)) .collect(); - if !files_missing_format.is_empty() { + if let Some(path) = files_missing_format.first() { let error = FinalError::with_title("Cannot decompress files without extensions") .detail(format!( "Files without supported extensions: {}", @@ -258,7 +257,7 @@ pub fn run( .hint("Or overwrite this option with the '--format' flag:") .hint(format!( " ouch decompress {} --format tar.gz", - to_utf(&files_missing_format[0]) + EscapedPathDisplay::new(path), )); return Err(error.into());