refactor: more entrypoint simplifications

initial model calculated in its own function
This commit is contained in:
Edward Langley
2026-03-30 23:37:04 -07:00
parent 3e3ac05b05
commit af0b2c6fdd

View File

@ -84,6 +84,26 @@ fn parse_args(args: Vec<String>) -> Option<CmdLineArgs> {
});
}
fn get_initial_model(file_path: &Option<PathBuf>) -> Result<Model> {
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<String> = 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() {