From 8233a582f3b50f622b006a932b0184059f3e38a4 Mon Sep 17 00:00:00 2001 From: Hanno Braun Date: Thu, 20 Oct 2022 13:07:54 +0200 Subject: [PATCH 1/2] Don't allow `fj-app` to be started without model Starting `fj-app` without a model is not actually doing anything right now, so there's no benefit to the user. It actually can be detrimental, because it's confusing. This also enables some simplifications, which I'd like to do, to make what I'm working on easier. --- crates/fj-app/src/main.rs | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/crates/fj-app/src/main.rs b/crates/fj-app/src/main.rs index 4766c34a9..a7fa345b9 100644 --- a/crates/fj-app/src/main.rs +++ b/crates/fj-app/src/main.rs @@ -70,7 +70,11 @@ fn main() -> anyhow::Result<()> { } })?) } else { - None + return Err(anyhow!( + "You must specify a model to start Fornjot.\n\ + - Pass a model as a command-line argument. See `fj-app --help`.\n\ + - Specify a default model in the configuration file." + )); }; if let Some(export_path) = args.export { From e0c7b8fae491608ef0e94537f904403e9a19c241 Mon Sep 17 00:00:00 2001 From: Hanno Braun Date: Thu, 20 Oct 2022 13:10:42 +0200 Subject: [PATCH 2/2] Refactor --- crates/fj-app/src/main.rs | 19 ++++--------------- 1 file changed, 4 insertions(+), 15 deletions(-) diff --git a/crates/fj-app/src/main.rs b/crates/fj-app/src/main.rs index a7fa345b9..3dca6df06 100644 --- a/crates/fj-app/src/main.rs +++ b/crates/fj-app/src/main.rs @@ -58,7 +58,7 @@ fn main() -> anyhow::Result<()> { { let mut model_path = path; model_path.push(model); - Some(Model::from_path(model_path.clone()).with_context(|| { + Model::from_path(model_path.clone()).with_context(|| { if path_of_model.as_os_str().is_empty() { format!( "Model is not defined, can't find model defined inside the default-model also, add model like \n cargo run -- -m {}", model.display() @@ -68,7 +68,7 @@ fn main() -> anyhow::Result<()> { "Failed to load model: {0}\ninside default models directory: '{1}'\nCan mainly caused by: \n1. Model '{2}' can not be found inside '{1}'\n2.'{2}' can be mis-typed see inside '{1}' for a match\n3. Define model is '{2}' couldn\'t be found ((defined in command-line arguments))", model_path.display(), path_of_model.display(), model.display() ) } - })?) + })? } else { return Err(anyhow!( "You must specify a model to start Fornjot.\n\ @@ -80,13 +80,6 @@ fn main() -> anyhow::Result<()> { if let Some(export_path) = args.export { // export only mode. just load model, process, export and exit - let model = model.ok_or_else(|| { - anyhow!( - "No model specified, and no default model configured.\n\ - Specify a model by passing `--model path/to/model`." - ) - })?; - let shape = model.load_once(¶meters, &mut status)?; let shape = shape_processor.process(&shape)?; @@ -97,12 +90,8 @@ fn main() -> anyhow::Result<()> { let invert_zoom = config.invert_zoom.unwrap_or(false); - if let Some(model) = model { - let watcher = model.load_and_watch(parameters)?; - run(Some(watcher), shape_processor, status, invert_zoom)?; - } else { - run(None, shape_processor, status, invert_zoom)?; - } + let watcher = model.load_and_watch(parameters)?; + run(Some(watcher), shape_processor, status, invert_zoom)?; Ok(()) }