mirror of
https://github.com/ouch-org/ouch.git
synced 2025-06-05 02:55:31 +00:00
fmt
This commit is contained in:
parent
e2ac5c4c9b
commit
93752d5fb5
@ -20,7 +20,8 @@ use crate::{
|
||||
error::FinalError,
|
||||
list::FileInArchive,
|
||||
utils::{
|
||||
self, cd_into_same_dir_as, get_invalid_utf8_paths, message::PrintMessage, pretty_format_list_of_paths, strip_cur_dir, Bytes, EscapedPathDisplay, FileVisibilityPolicy
|
||||
self, cd_into_same_dir_as, get_invalid_utf8_paths, message::PrintMessage, pretty_format_list_of_paths,
|
||||
strip_cur_dir, Bytes, EscapedPathDisplay, FileVisibilityPolicy,
|
||||
},
|
||||
warning,
|
||||
};
|
||||
@ -145,7 +146,7 @@ pub fn build_archive_from_paths<W>(
|
||||
writer: W,
|
||||
file_visibility_policy: FileVisibilityPolicy,
|
||||
quiet: bool,
|
||||
log_sender: Sender<PrintMessage>
|
||||
log_sender: Sender<PrintMessage>,
|
||||
) -> crate::Result<W>
|
||||
where
|
||||
W: Write + Seek,
|
||||
@ -202,12 +203,10 @@ where
|
||||
if !quiet {
|
||||
log_sender
|
||||
.send(PrintMessage {
|
||||
contents: format!(
|
||||
"Compressing '{}'.",
|
||||
EscapedPathDisplay::new(path)
|
||||
),
|
||||
contents: format!("Compressing '{}'.", EscapedPathDisplay::new(path)),
|
||||
accessible: false,
|
||||
}).unwrap();
|
||||
})
|
||||
.unwrap();
|
||||
}
|
||||
|
||||
let metadata = match path.metadata() {
|
||||
|
22
src/check.rs
22
src/check.rs
@ -5,13 +5,17 @@
|
||||
use std::{
|
||||
ffi::OsString,
|
||||
ops::ControlFlow,
|
||||
path::{Path, PathBuf}, sync::mpsc::Sender,
|
||||
path::{Path, PathBuf},
|
||||
sync::mpsc::Sender,
|
||||
};
|
||||
|
||||
use crate::{
|
||||
error::FinalError,
|
||||
extension::{build_archive_file_suggestion, Extension, PRETTY_SUPPORTED_ALIASES, PRETTY_SUPPORTED_EXTENSIONS},
|
||||
utils::{message::PrintMessage, pretty_format_list_of_paths, try_infer_extension, user_wants_to_continue, EscapedPathDisplay},
|
||||
utils::{
|
||||
message::PrintMessage, pretty_format_list_of_paths, try_infer_extension, user_wants_to_continue,
|
||||
EscapedPathDisplay,
|
||||
},
|
||||
warning, QuestionAction, QuestionPolicy, Result,
|
||||
};
|
||||
|
||||
@ -25,7 +29,7 @@ pub fn check_mime_type(
|
||||
path: &Path,
|
||||
formats: &mut Vec<Extension>,
|
||||
question_policy: QuestionPolicy,
|
||||
log_sender: Sender<PrintMessage>
|
||||
log_sender: Sender<PrintMessage>,
|
||||
) -> Result<ControlFlow<()>> {
|
||||
if formats.is_empty() {
|
||||
// File with no extension
|
||||
@ -35,13 +39,10 @@ pub fn check_mime_type(
|
||||
// mistyped, ...) which we should always inform the user about.
|
||||
log_sender
|
||||
.send(PrintMessage {
|
||||
contents: format!(
|
||||
"Detected file: `{}` extension as `{}`",
|
||||
path.display(),
|
||||
detected_format
|
||||
),
|
||||
contents: format!("Detected file: `{}` extension as `{}`", path.display(), detected_format),
|
||||
accessible: true,
|
||||
}).unwrap();
|
||||
})
|
||||
.unwrap();
|
||||
if user_wants_to_continue(path, question_policy, QuestionAction::Decompression)? {
|
||||
formats.push(detected_format);
|
||||
} else {
|
||||
@ -76,7 +77,8 @@ pub fn check_mime_type(
|
||||
path.display()
|
||||
),
|
||||
accessible: true,
|
||||
}).unwrap();
|
||||
})
|
||||
.unwrap();
|
||||
}
|
||||
Ok(ControlFlow::Continue(()))
|
||||
}
|
||||
|
@ -128,7 +128,7 @@ pub fn compress_files(
|
||||
&mut vec_buffer,
|
||||
file_visibility_policy,
|
||||
quiet,
|
||||
log_sender.clone()
|
||||
log_sender.clone(),
|
||||
)?;
|
||||
vec_buffer.rewind()?;
|
||||
io::copy(&mut vec_buffer, &mut writer)?;
|
||||
|
@ -19,7 +19,6 @@ use crate::{
|
||||
commands::{compress::compress_files, decompress::decompress_file, list::list_archive_contents},
|
||||
error::{Error, FinalError},
|
||||
extension::{self, parse_format},
|
||||
info,
|
||||
list::ListOptions,
|
||||
utils::{self, message::PrintMessage, to_utf, EscapedPathDisplay, FileVisibilityPolicy},
|
||||
warning, CliArgs, QuestionPolicy,
|
||||
@ -198,7 +197,9 @@ pub fn run(
|
||||
for path in files.iter() {
|
||||
let (pathbase, mut file_formats) = extension::separate_known_extensions_from_name(path);
|
||||
|
||||
if let ControlFlow::Break(_) = check::check_mime_type(path, &mut file_formats, question_policy, log_sender.clone())? {
|
||||
if let ControlFlow::Break(_) =
|
||||
check::check_mime_type(path, &mut file_formats, question_policy, log_sender.clone())?
|
||||
{
|
||||
return Ok(());
|
||||
}
|
||||
|
||||
@ -247,7 +248,9 @@ pub fn run(
|
||||
for path in files.iter() {
|
||||
let mut file_formats = extension::extensions_from_path(path);
|
||||
|
||||
if let ControlFlow::Break(_) = check::check_mime_type(path, &mut file_formats, question_policy, log_sender.clone())? {
|
||||
if let ControlFlow::Break(_) =
|
||||
check::check_mime_type(path, &mut file_formats, question_policy, log_sender.clone())?
|
||||
{
|
||||
return Ok(());
|
||||
}
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user