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() {