From 04e375790cb92571ec17b9c5e62c0c6901849a19 Mon Sep 17 00:00:00 2001 From: Hanno Braun Date: Tue, 30 May 2023 10:45:32 +0200 Subject: [PATCH] Add CLI interface for exporting to `cuboid` model --- models/cuboid/src/main.rs | 29 +++++++++++++++++++++++++++-- 1 file changed, 27 insertions(+), 2 deletions(-) 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() + } +}