Merge pull request #335 from figsoda/clippy

Clean up
This commit is contained in:
figsoda 2023-01-05 15:40:15 -05:00 committed by GitHub
commit 262ca5d582
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
7 changed files with 20 additions and 23 deletions

View File

@ -140,7 +140,7 @@ where
builder.append_file(path, file.file_mut()).map_err(|err| { builder.append_file(path, file.file_mut()).map_err(|err| {
FinalError::with_title("Could not create archive") FinalError::with_title("Could not create archive")
.detail("Unexpected error while trying to read file") .detail("Unexpected error while trying to read file")
.detail(format!("Error: {}.", err)) .detail(format!("Error: {err}."))
})?; })?;
} }
} }

View File

@ -146,16 +146,15 @@ pub fn run(
"You are trying to compress a folder." "You are trying to compress a folder."
}; };
let error = FinalError::with_title(format!("Cannot compress to '{}'.", output_path)) let error = FinalError::with_title(format!("Cannot compress to '{output_path}'."))
.detail(first_detail_message) .detail(first_detail_message)
.detail(format!( .detail(format!(
"The compression format '{}' does not accept multiple files.", "The compression format '{first_format}' does not accept multiple files.",
&formats[0]
)) ))
.detail("Formats that bundle files into an archive are .tar and .zip.") .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!("From: {output_path}"))
.hint(format!("To: {}", suggested_output_path)); .hint(format!("To: {suggested_output_path}"));
return Err(error.into()); return Err(error.into());
} }
@ -165,14 +164,12 @@ pub fn run(
"Cannot compress to '{}'.", "Cannot compress to '{}'.",
EscapedPathDisplay::new(&output_path) EscapedPathDisplay::new(&output_path)
)) ))
.detail(format!("Found the format '{}' in an incorrect position.", format)) .detail(format!("Found the format '{format}' in an incorrect position."))
.detail(format!( .detail(format!(
"'{}' can only be used at the start of the file extension.", "'{format}' can only be used at the start of the file extension."
format
)) ))
.hint(format!( .hint(format!(
"If you wish to compress multiple files, start the extension with '{}'.", "If you wish to compress multiple files, start the extension with '{format}'."
format
)) ))
.hint(format!( .hint(format!(
"Otherwise, remove the last '{}' from '{}'.", "Otherwise, remove the last '{}' from '{}'.",
@ -247,7 +244,7 @@ pub fn run(
.map(|(input_path, _)| PathBuf::from(input_path)) .map(|(input_path, _)| PathBuf::from(input_path))
.collect(); .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") let error = FinalError::with_title("Cannot decompress files without extensions")
.detail(format!( .detail(format!(
"Files without supported extensions: {}", "Files without supported extensions: {}",
@ -260,7 +257,7 @@ pub fn run(
.hint("Or overwrite this option with the '--format' flag:") .hint("Or overwrite this option with the '--format' flag:")
.hint(format!( .hint(format!(
" ouch decompress {} --format tar.gz", " ouch decompress {} --format tar.gz",
to_utf(&files_missing_format[0]) EscapedPathDisplay::new(path),
)); ));
return Err(error.into()); return Err(error.into());

View File

@ -76,7 +76,7 @@ impl Display for FinalError {
if is_running_in_accessible_mode() { if is_running_in_accessible_mode() {
write!(f, "\n{}hints:{}", *GREEN, *RESET)?; write!(f, "\n{}hints:{}", *GREEN, *RESET)?;
for hint in &self.hints { for hint in &self.hints {
write!(f, "\n{}", hint)?; write!(f, "\n{hint}")?;
} }
} else { } else {
for hint in &self.hints { for hint in &self.hints {
@ -138,7 +138,7 @@ impl fmt::Display for Error {
Error::Custom { reason } => reason.clone(), Error::Custom { reason } => reason.clone(),
}; };
write!(f, "{}", err) write!(f, "{err}")
} }
} }

View File

@ -57,7 +57,7 @@ fn print_entry(name: impl std::fmt::Display, is_dir: bool) {
if is_dir { if is_dir {
// if colors are deactivated, print final / to mark directories // if colors are deactivated, print final / to mark directories
if BLUE.is_empty() { if BLUE.is_empty() {
println!("{}/", name); println!("{name}/");
// if in ACCESSIBLE mode, use colors but print final / in case colors // if in ACCESSIBLE mode, use colors but print final / in case colors
// aren't read out aloud with a screen reader or aren't printed on a // aren't read out aloud with a screen reader or aren't printed on a
// braille reader // braille reader
@ -68,7 +68,7 @@ fn print_entry(name: impl std::fmt::Display, is_dir: bool) {
} }
} else { } else {
// not a dir -> just print the file name // not a dir -> just print the file name
println!("{}", name); println!("{name}");
} }
} }
@ -142,7 +142,7 @@ mod tree {
false => draw::FINAL_BRANCH, false => draw::FINAL_BRANCH,
}; };
print!("{}{}", prefix, final_part); print!("{prefix}{final_part}");
let is_dir = match self.file { let is_dir = match self.file {
Some(FileInArchive { is_dir, .. }) => is_dir, Some(FileInArchive { is_dir, .. }) => is_dir,
None => true, None => true,

View File

@ -31,7 +31,7 @@ pub const EXIT_FAILURE: i32 = libc::EXIT_FAILURE;
fn main() { fn main() {
if let Err(err) = run() { if let Err(err) = run() {
eprintln!("{}", err); eprintln!("{err}");
std::process::exit(EXIT_FAILURE); std::process::exit(EXIT_FAILURE);
} }
} }

View File

@ -20,7 +20,7 @@ impl Display for EscapedPathDisplay<'_> {
let bstr = bstr::BStr::new(self.path.as_os_str().as_bytes()); let bstr = bstr::BStr::new(self.path.as_os_str().as_bytes());
write!(f, "{}", bstr) write!(f, "{bstr}")
} }
} }
@ -47,7 +47,7 @@ impl Display for EscapedPathDisplay<'_> {
/// See <https://gist.github.com/marcospb19/ebce5572be26397cf08bbd0fd3b65ac1> for a comparison. /// See <https://gist.github.com/marcospb19/ebce5572be26397cf08bbd0fd3b65ac1> for a comparison.
pub fn to_utf(os_str: &Path) -> Cow<str> { pub fn to_utf(os_str: &Path) -> Cow<str> {
let format = || { let format = || {
let text = format!("{:?}", os_str); let text = format!("{os_str:?}");
Cow::Owned(text.trim_matches('"').to_string()) Cow::Owned(text.trim_matches('"').to_string())
}; };

View File

@ -86,7 +86,7 @@ pub fn user_wants_to_continue(
let path = to_utf(strip_cur_dir(path)); let path = to_utf(strip_cur_dir(path));
let path = Some(&*path); let path = Some(&*path);
let placeholder = Some("FILE"); let placeholder = Some("FILE");
Confirmation::new(&format!("Do you want to {} 'FILE'?", action), placeholder).ask(path) Confirmation::new(&format!("Do you want to {action} 'FILE'?"), placeholder).ask(path)
} }
} }
} }