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