Skip to content

Commit 21a36c7

Browse files
committed
Support specifying a pattern for the output filename
1 parent f5ca0a8 commit 21a36c7

File tree

1 file changed

+14
-8
lines changed

1 file changed

+14
-8
lines changed

splashsurf/src/reconstruction.rs

Lines changed: 14 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ pub struct ReconstructSubcommandArgs {
3232
/// Path to the input file where the particle positions are stored (supported formats: VTK 4.2, VTU, binary f32 XYZ, PLY, BGEO)
3333
#[arg(help_heading = ARGS_IO, short = 'i', long, group = "input", value_parser = value_parser!(PathBuf))]
3434
pub input_file: Option<PathBuf>,
35-
/// Path to a sequence of particle files that should be processed, use `{}` in the filename to indicate a placeholder
35+
/// Path to a sequence of particle files that should be processed, use "{}" in the filename to indicate a placeholder. To specify an output format, use e.g. --output_file="filename_{}.obj".
3636
#[arg(help_heading = ARGS_IO, short = 's', long, group = "input", value_parser = value_parser!(PathBuf))]
3737
pub input_sequence: Option<PathBuf>,
3838
/// Filename for writing the reconstructed surface to disk (default: "{original_filename}_surface.vtk")
@@ -574,14 +574,20 @@ mod arguments {
574574
}
575575
}
576576

577-
// Make sure that we have a placeholder \"{}\" in the filename part of the sequence pattern
577+
// Make sure that we have a placeholder "{}" in the filename part of the sequence pattern
578578
if input_filename.contains("{}") {
579-
let input_stem = input_pattern.file_stem().unwrap().to_string_lossy();
580-
// Currently, only VTK files are supported for output
581-
let output_filename = format!(
582-
"{}.vtk",
583-
input_stem.replace("{}", &format!("{}_{{}}", output_suffix))
584-
);
579+
let output_filename = if let Some(output_file) = &args.output_file {
580+
let output_pattern = output_file.to_string_lossy();
581+
if output_pattern.contains("{}") {
582+
output_pattern.to_string()
583+
} else {
584+
return Err(anyhow!("The output filename \"{}\" does not contain a place holder \"{{}}\"", output_file.display()));
585+
}
586+
} else {
587+
let input_stem = input_pattern.file_stem().unwrap().to_string_lossy();
588+
// Use VTK format as default fallback
589+
format!("{}.vtk", input_stem.replace("{}", &format!("{}_{{}}", output_suffix)))
590+
};
585591

586592
Self::try_new(
587593
true,

0 commit comments

Comments
 (0)