mirror of
https://github.com/ouch-org/ouch.git
synced 2025-06-06 19:45:29 +00:00
separate function check_first_format_when_compressing
This commit is contained in:
parent
f33c9c0f39
commit
93daa7b929
16
src/check.rs
16
src/check.rs
@ -150,3 +150,19 @@ pub fn check_missing_formats_when_decompressing(files: &[PathBuf], formats: &[Ve
|
||||
}
|
||||
Ok(())
|
||||
}
|
||||
|
||||
/// Check if there is a first format when compressing, and returns it.
|
||||
pub fn check_first_format_when_compressing<'a>(formats: &'a [Extension], output_path: &Path) -> Result<&'a Extension> {
|
||||
formats.first().ok_or_else(|| {
|
||||
let output_path = EscapedPathDisplay::new(output_path);
|
||||
FinalError::with_title(format!("Cannot compress to '{output_path}'."))
|
||||
.detail("You shall supply the compression format")
|
||||
.hint("Try adding supported extensions (see --help):")
|
||||
.hint(format!(" ouch compress <FILES>... {output_path}.tar.gz"))
|
||||
.hint(format!(" ouch compress <FILES>... {output_path}.zip"))
|
||||
.hint("")
|
||||
.hint("Alternatively, you can overwrite this option by using the '--format' flag:")
|
||||
.hint(format!(" ouch compress <FILES>... {output_path} --format tar.gz"))
|
||||
.into()
|
||||
})
|
||||
}
|
||||
|
@ -59,17 +59,7 @@ pub fn run(
|
||||
None => (None, extension::extensions_from_path(&output_path)),
|
||||
};
|
||||
|
||||
let first_format = formats.first().ok_or_else(|| {
|
||||
let output_path = EscapedPathDisplay::new(&output_path);
|
||||
FinalError::with_title(format!("Cannot compress to '{output_path}'."))
|
||||
.detail("You shall supply the compression format")
|
||||
.hint("Try adding supported extensions (see --help):")
|
||||
.hint(format!(" ouch compress <FILES>... {output_path}.tar.gz"))
|
||||
.hint(format!(" ouch compress <FILES>... {output_path}.zip"))
|
||||
.hint("")
|
||||
.hint("Alternatively, you can overwrite this option by using the '--format' flag:")
|
||||
.hint(format!(" ouch compress <FILES>... {output_path} --format tar.gz"))
|
||||
})?;
|
||||
let first_format = check::check_first_format_when_compressing(&formats, &output_path)?;
|
||||
|
||||
let is_some_input_a_folder = files.iter().any(|path| path.is_dir());
|
||||
let is_multiple_inputs = files.len() > 1;
|
||||
|
Loading…
x
Reference in New Issue
Block a user