mirror of
https://github.com/ouch-org/ouch.git
synced 2025-06-05 02:55:31 +00:00
feat: Add flag 'no-smart-unpack'
This commit is contained in:
parent
fdab666bf8
commit
ad8fd8935c
@ -100,6 +100,10 @@ pub enum Subcommand {
|
||||
/// Remove the source file after successful decompression
|
||||
#[arg(short = 'r', long)]
|
||||
remove: bool,
|
||||
|
||||
/// Disable Smart Unpack
|
||||
#[arg(long)]
|
||||
no_smart_unpack: bool,
|
||||
},
|
||||
/// List contents of an archive
|
||||
#[command(visible_aliases = ["l", "ls"])]
|
||||
@ -156,6 +160,7 @@ mod tests {
|
||||
files: vec!["\x00\x11\x22".into()],
|
||||
output_dir: None,
|
||||
remove: false,
|
||||
no_smart_unpack: false
|
||||
},
|
||||
}
|
||||
}
|
||||
@ -169,6 +174,7 @@ mod tests {
|
||||
files: to_paths(["file.tar.gz"]),
|
||||
output_dir: None,
|
||||
remove: false,
|
||||
no_smart_unpack: false,
|
||||
},
|
||||
..mock_cli_args()
|
||||
}
|
||||
@ -180,6 +186,7 @@ mod tests {
|
||||
files: to_paths(["file.tar.gz"]),
|
||||
output_dir: None,
|
||||
remove: false,
|
||||
no_smart_unpack: false,
|
||||
},
|
||||
..mock_cli_args()
|
||||
}
|
||||
@ -191,6 +198,7 @@ mod tests {
|
||||
files: to_paths(["a", "b", "c"]),
|
||||
output_dir: None,
|
||||
remove: false,
|
||||
no_smart_unpack: false,
|
||||
},
|
||||
..mock_cli_args()
|
||||
}
|
||||
|
@ -31,7 +31,7 @@ pub struct DecompressOptions<'a> {
|
||||
pub formats: Vec<Extension>,
|
||||
pub output_dir: &'a Path,
|
||||
pub output_file_path: PathBuf,
|
||||
pub is_output_dir_provided: bool,
|
||||
pub is_smart_unpack: bool,
|
||||
pub question_policy: QuestionPolicy,
|
||||
pub quiet: bool,
|
||||
pub password: Option<&'a [u8]>,
|
||||
@ -74,7 +74,7 @@ pub fn decompress_file(options: DecompressOptions) -> crate::Result<()> {
|
||||
options.output_dir,
|
||||
&options.output_file_path,
|
||||
options.question_policy,
|
||||
options.is_output_dir_provided,
|
||||
options.is_smart_unpack,
|
||||
)? {
|
||||
files
|
||||
} else {
|
||||
@ -152,7 +152,7 @@ pub fn decompress_file(options: DecompressOptions) -> crate::Result<()> {
|
||||
options.output_dir,
|
||||
&options.output_file_path,
|
||||
options.question_policy,
|
||||
options.is_output_dir_provided,
|
||||
options.is_smart_unpack,
|
||||
)? {
|
||||
files
|
||||
} else {
|
||||
@ -186,7 +186,7 @@ pub fn decompress_file(options: DecompressOptions) -> crate::Result<()> {
|
||||
options.output_dir,
|
||||
&options.output_file_path,
|
||||
options.question_policy,
|
||||
options.is_output_dir_provided,
|
||||
options.is_smart_unpack,
|
||||
)? {
|
||||
files
|
||||
} else {
|
||||
@ -218,7 +218,7 @@ pub fn decompress_file(options: DecompressOptions) -> crate::Result<()> {
|
||||
options.output_dir,
|
||||
&options.output_file_path,
|
||||
options.question_policy,
|
||||
options.is_output_dir_provided,
|
||||
options.is_smart_unpack,
|
||||
)? {
|
||||
files
|
||||
} else {
|
||||
@ -260,7 +260,7 @@ pub fn decompress_file(options: DecompressOptions) -> crate::Result<()> {
|
||||
options.output_dir,
|
||||
&options.output_file_path,
|
||||
options.question_policy,
|
||||
options.is_output_dir_provided,
|
||||
options.is_smart_unpack,
|
||||
)? {
|
||||
files
|
||||
} else {
|
||||
@ -295,12 +295,12 @@ fn execute_decompression(
|
||||
output_dir: &Path,
|
||||
output_file_path: &Path,
|
||||
question_policy: QuestionPolicy,
|
||||
is_output_dir_provided: bool,
|
||||
is_smart_unpack: bool,
|
||||
) -> crate::Result<ControlFlow<(), usize>> {
|
||||
if is_output_dir_provided {
|
||||
unpack(unpack_fn, output_dir, question_policy)
|
||||
} else {
|
||||
if is_smart_unpack {
|
||||
smart_unpack(unpack_fn, output_dir, output_file_path, question_policy)
|
||||
} else {
|
||||
unpack(unpack_fn, output_dir, question_policy)
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -148,6 +148,7 @@ pub fn run(
|
||||
files,
|
||||
output_dir,
|
||||
remove,
|
||||
no_smart_unpack,
|
||||
} => {
|
||||
let mut output_paths = vec![];
|
||||
let mut formats = vec![];
|
||||
@ -178,7 +179,7 @@ pub fn run(
|
||||
|
||||
// The directory that will contain the output files
|
||||
// We default to the current directory if the user didn't specify an output directory with --dir
|
||||
let is_output_dir_provided = output_dir.is_some();
|
||||
let is_smart_unpack = !no_smart_unpack && output_dir.is_none();
|
||||
let output_dir = if let Some(dir) = output_dir {
|
||||
utils::create_dir_if_non_existent(&dir)?;
|
||||
dir
|
||||
@ -202,7 +203,7 @@ pub fn run(
|
||||
formats,
|
||||
output_dir: &output_dir,
|
||||
output_file_path,
|
||||
is_output_dir_provided,
|
||||
is_smart_unpack,
|
||||
question_policy,
|
||||
quiet: args.quiet,
|
||||
password: args.password.as_deref().map(|str| {
|
||||
|
Loading…
x
Reference in New Issue
Block a user