mirror of
https://github.com/ouch-org/ouch.git
synced 2025-06-06 19:45:29 +00:00
Merge pull request #325 from a-moreira/feat/quiet
add cli option to (de)compress quietly
This commit is contained in:
commit
5d21895d33
@ -20,6 +20,10 @@ Categories Used:
|
||||
|
||||
## [Unreleased](https://github.com/ouch-org/ouch/compare/0.4.0...HEAD)
|
||||
|
||||
### New Features
|
||||
|
||||
- Add cli option to (de)compress quietly [\#325](https://github.com/ouch-org/ouch/pull/325) ([a-moreira](https://github.com/a-moreira))
|
||||
|
||||
### Improvements
|
||||
|
||||
- Allow ouch to decompress archive into existing folder [\#321](https://github.com/ouch-org/ouch/pull/321) ([a-moreira](https://github.com/a-moreira))
|
||||
|
@ -22,7 +22,7 @@ use crate::{
|
||||
|
||||
/// Unpacks the archive given by `archive` into the folder given by `into`.
|
||||
/// Assumes that output_folder is empty
|
||||
pub fn unpack_archive(reader: Box<dyn Read>, output_folder: &Path) -> crate::Result<Vec<PathBuf>> {
|
||||
pub fn unpack_archive(reader: Box<dyn Read>, output_folder: &Path, quiet: bool) -> crate::Result<Vec<PathBuf>> {
|
||||
assert!(output_folder.read_dir().expect("dir exists").count() == 0);
|
||||
let mut archive = tar::Archive::new(reader);
|
||||
|
||||
@ -37,15 +37,16 @@ pub fn unpack_archive(reader: Box<dyn Read>, output_folder: &Path) -> crate::Res
|
||||
// importance for most users, but would generate lots of
|
||||
// spoken text for users using screen readers, braille displays
|
||||
// and so on
|
||||
if !quiet {
|
||||
info!(
|
||||
inaccessible,
|
||||
"{:?} extracted. ({})",
|
||||
utils::strip_cur_dir(&output_folder.join(file.path()?)),
|
||||
format_size(file.size(), DECIMAL),
|
||||
);
|
||||
|
||||
info!(
|
||||
inaccessible,
|
||||
"{:?} extracted. ({})",
|
||||
utils::strip_cur_dir(&output_folder.join(file.path()?)),
|
||||
format_size(file.size(), DECIMAL),
|
||||
);
|
||||
|
||||
files_unpacked.push(file_path);
|
||||
files_unpacked.push(file_path);
|
||||
}
|
||||
}
|
||||
|
||||
Ok(files_unpacked)
|
||||
@ -86,6 +87,7 @@ pub fn build_archive_from_paths<W>(
|
||||
output_path: &Path,
|
||||
writer: W,
|
||||
file_visibility_policy: FileVisibilityPolicy,
|
||||
quiet: bool,
|
||||
) -> crate::Result<W>
|
||||
where
|
||||
W: Write,
|
||||
@ -118,7 +120,9 @@ where
|
||||
// little importance for most users, but would generate lots of
|
||||
// spoken text for users using screen readers, braille displays
|
||||
// and so on
|
||||
info!(inaccessible, "Compressing '{}'.", utils::to_utf(path));
|
||||
if !quiet {
|
||||
info!(inaccessible, "Compressing '{}'.", utils::to_utf(path));
|
||||
}
|
||||
|
||||
if path.is_dir() {
|
||||
builder.append_dir(path, path)?;
|
||||
|
@ -29,7 +29,7 @@ use crate::{
|
||||
|
||||
/// Unpacks the archive given by `archive` into the folder given by `output_folder`.
|
||||
/// Assumes that output_folder is empty
|
||||
pub fn unpack_archive<R>(mut archive: ZipArchive<R>, output_folder: &Path) -> crate::Result<Vec<PathBuf>>
|
||||
pub fn unpack_archive<R>(mut archive: ZipArchive<R>, output_folder: &Path, quiet: bool) -> crate::Result<Vec<PathBuf>>
|
||||
where
|
||||
R: Read + Seek,
|
||||
{
|
||||
@ -54,7 +54,9 @@ where
|
||||
// importance for most users, but would generate lots of
|
||||
// spoken text for users using screen readers, braille displays
|
||||
// and so on
|
||||
info!(inaccessible, "File {} extracted to \"{}\"", idx, file_path.display());
|
||||
if !quiet {
|
||||
info!(inaccessible, "File {} extracted to \"{}\"", idx, file_path.display());
|
||||
}
|
||||
fs::create_dir_all(&file_path)?;
|
||||
}
|
||||
_is_file @ false => {
|
||||
@ -66,12 +68,14 @@ where
|
||||
let file_path = strip_cur_dir(file_path.as_path());
|
||||
|
||||
// same reason is in _is_dir: long, often not needed text
|
||||
info!(
|
||||
inaccessible,
|
||||
"{:?} extracted. ({})",
|
||||
file_path.display(),
|
||||
format_size(file.size(), DECIMAL),
|
||||
);
|
||||
if !quiet {
|
||||
info!(
|
||||
inaccessible,
|
||||
"{:?} extracted. ({})",
|
||||
file_path.display(),
|
||||
format_size(file.size(), DECIMAL),
|
||||
);
|
||||
}
|
||||
|
||||
let mut output_file = fs::File::create(file_path)?;
|
||||
io::copy(&mut file, &mut output_file)?;
|
||||
@ -135,6 +139,7 @@ pub fn build_archive_from_paths<W>(
|
||||
output_path: &Path,
|
||||
writer: W,
|
||||
file_visibility_policy: FileVisibilityPolicy,
|
||||
quiet: bool,
|
||||
) -> crate::Result<W>
|
||||
where
|
||||
W: Write + Seek,
|
||||
@ -185,7 +190,9 @@ where
|
||||
// little importance for most users, but would generate lots of
|
||||
// spoken text for users using screen readers, braille displays
|
||||
// and so on
|
||||
info!(inaccessible, "Compressing '{}'.", to_utf(path));
|
||||
if !quiet {
|
||||
info!(inaccessible, "Compressing '{}'.", to_utf(path));
|
||||
}
|
||||
|
||||
let metadata = match path.metadata() {
|
||||
Ok(metadata) => metadata,
|
||||
|
@ -32,6 +32,7 @@ pub fn compress_files(
|
||||
extensions: Vec<Extension>,
|
||||
output_file: fs::File,
|
||||
output_path: &Path,
|
||||
quiet: bool,
|
||||
question_policy: QuestionPolicy,
|
||||
file_visibility_policy: FileVisibilityPolicy,
|
||||
) -> crate::Result<bool> {
|
||||
@ -74,7 +75,7 @@ pub fn compress_files(
|
||||
io::copy(&mut reader, &mut writer)?;
|
||||
}
|
||||
Tar => {
|
||||
archive::tar::build_archive_from_paths(&files, output_path, &mut writer, file_visibility_policy)?;
|
||||
archive::tar::build_archive_from_paths(&files, output_path, &mut writer, file_visibility_policy, quiet)?;
|
||||
writer.flush()?;
|
||||
}
|
||||
Zip => {
|
||||
@ -88,7 +89,13 @@ pub fn compress_files(
|
||||
|
||||
let mut vec_buffer = Cursor::new(vec![]);
|
||||
|
||||
archive::zip::build_archive_from_paths(&files, output_path, &mut vec_buffer, file_visibility_policy)?;
|
||||
archive::zip::build_archive_from_paths(
|
||||
&files,
|
||||
output_path,
|
||||
&mut vec_buffer,
|
||||
file_visibility_policy,
|
||||
quiet,
|
||||
)?;
|
||||
vec_buffer.rewind()?;
|
||||
io::copy(&mut vec_buffer, &mut writer)?;
|
||||
}
|
||||
|
@ -30,6 +30,7 @@ pub fn decompress_file(
|
||||
output_dir: &Path,
|
||||
output_file_path: PathBuf,
|
||||
question_policy: QuestionPolicy,
|
||||
quiet: bool,
|
||||
) -> crate::Result<()> {
|
||||
assert!(output_dir.exists());
|
||||
let reader = fs::File::open(input_file_path)?;
|
||||
@ -48,7 +49,7 @@ pub fn decompress_file(
|
||||
{
|
||||
let zip_archive = zip::ZipArchive::new(reader)?;
|
||||
let files = if let ControlFlow::Continue(files) = smart_unpack(
|
||||
|output_dir| crate::archive::zip::unpack_archive(zip_archive, output_dir),
|
||||
|output_dir| crate::archive::zip::unpack_archive(zip_archive, output_dir, quiet),
|
||||
output_dir,
|
||||
&output_file_path,
|
||||
question_policy,
|
||||
@ -111,7 +112,7 @@ pub fn decompress_file(
|
||||
}
|
||||
Tar => {
|
||||
if let ControlFlow::Continue(files) = smart_unpack(
|
||||
|output_dir| crate::archive::tar::unpack_archive(reader, output_dir),
|
||||
|output_dir| crate::archive::tar::unpack_archive(reader, output_dir, quiet),
|
||||
output_dir,
|
||||
&output_file_path,
|
||||
question_policy,
|
||||
@ -135,7 +136,7 @@ pub fn decompress_file(
|
||||
let zip_archive = zip::ZipArchive::new(io::Cursor::new(vec))?;
|
||||
|
||||
if let ControlFlow::Continue(files) = smart_unpack(
|
||||
|output_dir| crate::archive::zip::unpack_archive(zip_archive, output_dir),
|
||||
|output_dir| crate::archive::zip::unpack_archive(zip_archive, output_dir, quiet),
|
||||
output_dir,
|
||||
&output_file_path,
|
||||
question_policy,
|
||||
|
@ -164,6 +164,7 @@ pub fn run(
|
||||
formats,
|
||||
output_file,
|
||||
&output_path,
|
||||
args.quiet,
|
||||
question_policy,
|
||||
file_visibility_policy,
|
||||
);
|
||||
@ -244,7 +245,14 @@ pub fn run(
|
||||
|
||||
for ((input_path, formats), file_name) in files.iter().zip(formats).zip(output_paths) {
|
||||
let output_file_path = output_dir.join(file_name); // Path used by single file format archives
|
||||
decompress_file(input_path, formats, &output_dir, output_file_path, question_policy)?;
|
||||
decompress_file(
|
||||
input_path,
|
||||
formats,
|
||||
&output_dir,
|
||||
output_file_path,
|
||||
question_policy,
|
||||
args.quiet,
|
||||
)?;
|
||||
}
|
||||
}
|
||||
Subcommand::List { archives: files, tree } => {
|
||||
|
@ -29,6 +29,10 @@ pub struct Opts {
|
||||
#[arg(short = 'H', long)]
|
||||
pub hidden: bool,
|
||||
|
||||
/// Silences output
|
||||
#[arg(short = 'q', long)]
|
||||
pub quiet: bool,
|
||||
|
||||
/// Ignores files matched by git's ignore files
|
||||
#[arg(short = 'g', long)]
|
||||
pub gitignore: bool,
|
||||
|
Loading…
x
Reference in New Issue
Block a user