From a655078997d4513d71eae50abe5f4bf833b71282 Mon Sep 17 00:00:00 2001 From: Ed L Date: Fri, 27 Mar 2026 15:18:37 -0700 Subject: [PATCH] fix: --import now opens the wizard instead of doing a headless auto-import Previously --import ran ImportJson headless before the TUI started, hitting the category limit and printing the error to stderr where it was invisible. Now it parses the JSON and opens the ImportWizard on startup, matching :import behavior. Co-Authored-By: Claude Sonnet 4.6 --- src/main.rs | 29 ++++++++++++++++------------- 1 file changed, 16 insertions(+), 13 deletions(-) diff --git a/src/main.rs b/src/main.rs index 017c6a5..bef3947 100644 --- a/src/main.rs +++ b/src/main.rs @@ -93,20 +93,20 @@ fn main() -> Result<()> { return run_headless(&mut model, file_path, headless_cmds, headless_script); } - // Pre-TUI import - if let Some(ref path) = import_path { - let cmd = command::Command::ImportJson { - path: path.to_string_lossy().to_string(), - model_name: None, - array_path: None, - }; - let result = command::dispatch(&mut model, &cmd); - if !result.ok { - eprintln!("Import error: {}", result.message.unwrap_or_default()); + // Pre-TUI import: parse JSON and open wizard + let import_json = if let Some(ref path) = import_path { + match std::fs::read_to_string(path) { + Err(e) => { eprintln!("Cannot read '{}': {e}", path.display()); return Ok(()); } + Ok(content) => match serde_json::from_str::(&content) { + Err(e) => { eprintln!("JSON parse error: {e}"); return Ok(()); } + Ok(json) => Some(json), + } } - } + } else { + None + }; - run_tui(model, file_path) + run_tui(model, file_path, import_json) } fn run_headless( @@ -149,7 +149,7 @@ fn run_headless( std::process::exit(exit_code); } -fn run_tui(model: Model, file_path: Option) -> Result<()> { +fn run_tui(model: Model, file_path: Option, import_json: Option) -> Result<()> { enable_raw_mode()?; let mut stdout = io::stdout(); execute!(stdout, EnterAlternateScreen)?; @@ -157,6 +157,9 @@ fn run_tui(model: Model, file_path: Option) -> Result<()> { let mut terminal = Terminal::new(backend)?; let mut app = App::new(model, file_path); + if let Some(json) = import_json { + app.start_import_wizard(json); + } loop { terminal.draw(|f| draw(f, &app))?;