diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 9a10e9bfc..faaa0c24b 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -59,5 +59,5 @@ jobs: run: cargo build --all-features - name: Run `cargo test` run: cargo test --all-features - # - name: Run `export-validator` - # run: cargo run --package export-validator + - name: Run `export-validator` + run: cargo run --package export-validator diff --git a/Cargo.lock b/Cargo.lock index be680800f..e3fc5075a 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -623,6 +623,8 @@ name = "cuboid" version = "0.1.0" dependencies = [ "anyhow", + "clap", + "fj-export", "fj-kernel", "fj-math", "fj-window", diff --git a/justfile b/justfile index 02d42fc60..7b0f2fb0f 100644 --- a/justfile +++ b/justfile @@ -9,7 +9,7 @@ export RUSTDOCFLAGS := "-D warnings" # For a full build that mirrors the CI build, see `just ci`. test: cargo test --all-features - # cargo run --package export-validator + cargo run --package export-validator # Run a full build that mirrors the CI build # diff --git a/models/cuboid/Cargo.toml b/models/cuboid/Cargo.toml index 6fab5e1ff..dbb1f30eb 100644 --- a/models/cuboid/Cargo.toml +++ b/models/cuboid/Cargo.toml @@ -8,6 +8,13 @@ edition = "2021" anyhow = "1.0.71" itertools = "0.10.5" +[dependencies.clap] +version = "4.3.0" +features = ["derive"] + +[dependencies.fj-export] +path = "../../crates/fj-export" + [dependencies.fj-kernel] path = "../../crates/fj-kernel" 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() + } +} diff --git a/tools/export-validator/src/main.rs b/tools/export-validator/src/main.rs index 5d3a3d9a2..5b6849e9b 100644 --- a/tools/export-validator/src/main.rs +++ b/tools/export-validator/src/main.rs @@ -35,8 +35,8 @@ fn handle_model(model: String) -> Result<(), anyhow::Error> { let export_file_path_str = export_file_path.to_str().unwrap(); let exit_status = Command::new("cargo") .arg("run") + .args(["-p", &model]) .arg("--") - .arg(&model) .args(["--export", export_file_path_str]) .status()?; if !exit_status.success() {