From 0d07f23ceea19c2d32adbcfe01fdf2f3cb345cdd Mon Sep 17 00:00:00 2001 From: Hanno Braun Date: Tue, 23 May 2023 11:09:03 +0200 Subject: [PATCH 1/6] Add dependency on Clap to `cuboid` --- Cargo.lock | 1 + models/cuboid/Cargo.toml | 4 ++++ 2 files changed, 5 insertions(+) diff --git a/Cargo.lock b/Cargo.lock index be680800f..eab9690ce 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -623,6 +623,7 @@ name = "cuboid" version = "0.1.0" dependencies = [ "anyhow", + "clap", "fj-kernel", "fj-math", "fj-window", diff --git a/models/cuboid/Cargo.toml b/models/cuboid/Cargo.toml index 6fab5e1ff..bf42f447d 100644 --- a/models/cuboid/Cargo.toml +++ b/models/cuboid/Cargo.toml @@ -8,6 +8,10 @@ edition = "2021" anyhow = "1.0.71" itertools = "0.10.5" +[dependencies.clap] +version = "4.3.0" +features = ["derive"] + [dependencies.fj-kernel] path = "../../crates/fj-kernel" From f307339bc3e51b132049985232343384c1148443 Mon Sep 17 00:00:00 2001 From: Hanno Braun Date: Tue, 23 May 2023 11:10:54 +0200 Subject: [PATCH 2/6] Add dependency on `fj-export` to `cuboid` --- Cargo.lock | 1 + models/cuboid/Cargo.toml | 3 +++ 2 files changed, 4 insertions(+) diff --git a/Cargo.lock b/Cargo.lock index eab9690ce..e3fc5075a 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -624,6 +624,7 @@ version = "0.1.0" dependencies = [ "anyhow", "clap", + "fj-export", "fj-kernel", "fj-math", "fj-window", diff --git a/models/cuboid/Cargo.toml b/models/cuboid/Cargo.toml index bf42f447d..dbb1f30eb 100644 --- a/models/cuboid/Cargo.toml +++ b/models/cuboid/Cargo.toml @@ -12,6 +12,9 @@ itertools = "0.10.5" version = "4.3.0" features = ["derive"] +[dependencies.fj-export] +path = "../../crates/fj-export" + [dependencies.fj-kernel] path = "../../crates/fj-kernel" From 04e375790cb92571ec17b9c5e62c0c6901849a19 Mon Sep 17 00:00:00 2001 From: Hanno Braun Date: Tue, 30 May 2023 10:45:32 +0200 Subject: [PATCH 3/6] 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() + } +} From e6ddc88f0192e97349b77b0a653888a6b73c6696 Mon Sep 17 00:00:00 2001 From: Hanno Braun Date: Tue, 30 May 2023 10:48:57 +0200 Subject: [PATCH 4/6] Adapt `export-validator` to new setup --- tools/export-validator/src/main.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) 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() { From 3aa08cc5e2cfee88064ad83c6ae4a275d9ef6f15 Mon Sep 17 00:00:00 2001 From: Hanno Braun Date: Tue, 30 May 2023 10:49:12 +0200 Subject: [PATCH 5/6] Re-enable `export-validator` in `justfile` --- justfile | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) 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 # From 678dcf5632ff6196ca72925123cab0f6d2aa8bbc Mon Sep 17 00:00:00 2001 From: Hanno Braun Date: Tue, 30 May 2023 10:49:59 +0200 Subject: [PATCH 6/6] Re-enable `export-validator` in CI build --- .github/workflows/ci.yml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) 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