From af0b2c6fdd5db167af0b5e6842ece3b9d5f25f5e Mon Sep 17 00:00:00 2001 From: Edward Langley Date: Mon, 30 Mar 2026 23:37:04 -0700 Subject: [PATCH] refactor: more entrypoint simplifications initial model calculated in its own function --- src/main.rs | 38 +++++++++++++++++++++----------------- 1 file changed, 21 insertions(+), 17 deletions(-) diff --git a/src/main.rs b/src/main.rs index 4f476e4..0dbdecb 100644 --- a/src/main.rs +++ b/src/main.rs @@ -84,6 +84,26 @@ fn parse_args(args: Vec) -> Option { }); } +fn get_initial_model(file_path: &Option) -> Result { + return if let Some(ref path) = file_path { + if path.exists() { + let mut m = persistence::load(path) + .with_context(|| format!("Failed to load {}", path.display()))?; + m.normalize_view_state(); + Ok(m) + } else { + let name = path + .file_stem() + .and_then(|s| s.to_str()) + .unwrap_or("New Model") + .to_string(); + Ok(Model::new(name)) + } + } else { + Ok(Model::new("New Model")) + } +} + fn main() -> Result<()> { let args: Vec = std::env::args().collect(); let maybe_cmd_line_args = parse_args(args); @@ -94,23 +114,7 @@ fn main() -> Result<()> { let cmd_line_args = maybe_cmd_line_args.unwrap(); // Load or create model - let mut model = if let Some(ref path) = cmd_line_args.file_path { - if path.exists() { - let mut m = persistence::load(path) - .with_context(|| format!("Failed to load {}", path.display()))?; - m.normalize_view_state(); - m - } else { - let name = path - .file_stem() - .and_then(|s| s.to_str()) - .unwrap_or("New Model") - .to_string(); - Model::new(name) - } - } else { - Model::new("New Model") - }; + let mut model = get_initial_model(&cmd_line_args.file_path)?; // Headless mode if !cmd_line_args.headless_cmds.is_empty() || cmd_line_args.headless_script.is_some() {