diff --git a/models/cuboid/src/main.rs b/models/cuboid/src/main.rs index b6a0a8a77..5a0f7b505 100644 --- a/models/cuboid/src/main.rs +++ b/models/cuboid/src/main.rs @@ -1,8 +1,10 @@ -use std::ops::Deref; +use std::{ops::Deref, path::PathBuf}; use fj_kernel::algorithms::{approx::Tolerance, triangulate::Triangulate}; fn main() -> anyhow::Result<()> { + let args = Args::parse(); + let cuboid = cuboid::cuboid(3., 2., 1.); // The tolerance makes no difference for this model, as there aren't any @@ -10,7 +12,30 @@ fn main() -> anyhow::Result<()> { let tolerance = Tolerance::from_scalar(1.)?; let mesh = (cuboid.deref(), tolerance).triangulate(); - fj_window::run(mesh, false)?; + + if let Some(path) = args.export { + fj_export::export(&mesh, &path)?; + } else { + fj_window::run(mesh, false)?; + } Ok(()) } + +/// Standardized CLI for Fornjot models +#[derive(clap::Parser)] +pub struct Args { + /// Export model to this path + #[arg(short, long, value_name = "PATH")] + pub export: Option, +} + +impl Args { + /// Parse the command-line arguments + /// + /// Convenience method that saves the caller from having to import the + /// `clap::Parser` trait. + pub fn parse() -> Self { + ::parse() + } +}