Add a new option

This commit is contained in:
2025-09-03 22:59:22 +08:00
parent 4d5ad39e24
commit cc72c89f0c
4 changed files with 58 additions and 2 deletions

View File

@@ -83,6 +83,9 @@ pub struct Arg {
#[arg(short = 'T', long, value_enum, global = true)]
/// Output script type
pub output_type: Option<OutputScriptType>,
#[arg(short = 'n', long, global = true)]
/// Disable extra extension when locating/export output script
pub output_no_extra_ext: bool,
#[cfg(feature = "image")]
#[arg(short = 'i', long, value_enum, global = true)]
/// Output image type

View File

@@ -3,6 +3,7 @@ pub mod atomic;
#[cfg(feature = "fancy-regex")]
pub mod fancy_regex;
pub mod io;
pub mod path;
#[cfg(feature = "emote-psb")]
pub mod psb;
#[cfg(feature = "markup5ever_rcdom")]

14
src/ext/path.rs Normal file
View File

@@ -0,0 +1,14 @@
//! Extensions for std::path
pub trait PathBufExt {
/// Remove all extensions from the path.
fn remove_all_extensions(&mut self);
}
impl PathBufExt for std::path::PathBuf {
fn remove_all_extensions(&mut self) {
while self.extension().is_some() {
self.set_extension("");
}
}
}

View File

@@ -7,6 +7,7 @@ pub mod scripts;
pub mod types;
pub mod utils;
use ext::path::PathBufExt;
use scripts::base::ArchiveContent;
fn get_encoding(
@@ -542,6 +543,9 @@ pub fn export_script(
continue;
}
let mut out_path = std::path::PathBuf::from(&odir).join(f.name());
if arg.output_no_extra_ext {
out_path.remove_all_extensions();
}
out_path.set_extension(if of.is_custom() {
script_file.custom_output_extension()
} else {
@@ -729,7 +733,11 @@ pub fn export_script(
if !arg.image_output_flat {
if let Some(fname) = f.file_name() {
pb.push(fname);
pb.set_extension("");
if arg.output_no_extra_ext {
pb.remove_all_extensions();
} else {
pb.set_extension("");
}
}
pb.push(img_data.name);
} else {
@@ -752,6 +760,11 @@ pub fn export_script(
));
} else {
pb.push(img_data.name);
if arg.output_no_extra_ext {
pb.remove_all_extensions();
} else {
pb.set_extension("");
}
}
pb.set_extension(out_type.as_ref());
pb.to_string_lossy().into_owned()
@@ -767,7 +780,11 @@ pub fn export_script(
img_data.name
));
} else {
pb.set_extension("");
if arg.output_no_extra_ext {
pb.remove_all_extensions();
} else {
pb.set_extension("");
}
pb.push(img_data.name);
}
pb.set_extension(out_type.as_ref());
@@ -813,6 +830,9 @@ pub fn export_script(
if let Some(fname) = f.file_name() {
pb.push(fname);
}
if arg.output_no_extra_ext {
pb.remove_all_extensions();
}
pb.set_extension(out_type.as_ref());
pb.to_string_lossy().into_owned()
} else {
@@ -821,6 +841,9 @@ pub fn export_script(
}
None => {
let mut pb = std::path::PathBuf::from(filename);
if arg.output_no_extra_ext {
pb.remove_all_extensions();
}
pb.set_extension(out_type.as_ref());
pb.to_string_lossy().into_owned()
}
@@ -866,6 +889,9 @@ pub fn export_script(
if let Some(fname) = f.file_name() {
pb.push(fname);
}
if arg.output_no_extra_ext {
pb.remove_all_extensions();
}
pb.set_extension(ext);
pb.to_string_lossy().into_owned()
} else {
@@ -874,6 +900,9 @@ pub fn export_script(
}
None => {
let mut pb = std::path::PathBuf::from(filename);
if arg.output_no_extra_ext {
pb.remove_all_extensions();
}
pb.set_extension(ext);
pb.to_string_lossy().into_owned()
}
@@ -1007,6 +1036,9 @@ pub fn import_script(
of = script_file.default_output_script_type();
}
let mut out_path = std::path::PathBuf::from(&odir).join(f.name());
if arg.output_no_extra_ext {
out_path.remove_all_extensions();
}
let ext = if of.is_custom() {
script_file.custom_output_extension()
} else {
@@ -1261,6 +1293,9 @@ pub fn import_script(
if let Some(fname) = f.file_name() {
pb.push(fname);
}
if arg.output_no_extra_ext {
pb.remove_all_extensions();
}
pb.set_extension(out_type.as_ref());
pb.to_string_lossy().into_owned()
} else {
@@ -1303,6 +1338,9 @@ pub fn import_script(
if let Some(fname) = f.file_name() {
pb.push(fname);
}
if arg.output_no_extra_ext {
pb.remove_all_extensions();
}
pb.set_extension(of.as_ref());
pb.to_string_lossy().into_owned()
} else {