chore: print format type instead of index

When it raises an error caused by position of the format, now prints
the format type as string instead of the position inside the array of
formats.
In this way you can read on stdout the type like `.tar` or `.lz` instead
of `1`, `2`, .., `n`.
This commit is contained in:
Santo Cariotti 2021-10-08 07:11:36 +02:00
parent f46ff3c26e
commit d6327a00e8

View File

@ -85,12 +85,12 @@ pub fn run(command: Command, flags: &oof::Flags) -> crate::Result<()> {
return Err(Error::with_reason(reason)); return Err(Error::with_reason(reason));
} }
if let Some(format) = formats.iter().skip(1).position(|format| matches!(format, Tar | Zip)) { if let Some(format) = formats.iter().skip(1).find(|format| matches!(format, Tar | Zip)) {
let reason = FinalError::with_title(format!("Cannot compress to '{}'.", to_utf(&output_path))) let reason = FinalError::with_title(format!("Cannot compress to '{}'.", to_utf(&output_path)))
.detail(format!("Found the format '{}' in an incorrect position.", format)) .detail(format!("Found the format '{}' in an incorrect position.", format))
.detail(format!("{} can only be used at the start of the file extension.", format)) .detail(format!("'{}' can only be used at the start of the file extension.", format))
.hint(format!("If you wish to compress multiple files, start the extension with {}.", format)) .hint(format!("If you wish to compress multiple files, start the extension with '{}'.", format))
.hint(format!("Otherwise, remove {} from '{}'.", format, to_utf(&output_path))) .hint(format!("Otherwise, remove the last '{}' from '{}'.", format, to_utf(&output_path)))
.into_owned(); .into_owned();
return Err(Error::with_reason(reason)); return Err(Error::with_reason(reason));