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 <noreply@anthropic.com>
This commit is contained in:
Ed L
2026-03-27 15:18:37 -07:00
parent acc890764b
commit a655078997

View File

@ -93,20 +93,20 @@ fn main() -> Result<()> {
return run_headless(&mut model, file_path, headless_cmds, headless_script); return run_headless(&mut model, file_path, headless_cmds, headless_script);
} }
// Pre-TUI import // Pre-TUI import: parse JSON and open wizard
if let Some(ref path) = import_path { let import_json = if let Some(ref path) = import_path {
let cmd = command::Command::ImportJson { match std::fs::read_to_string(path) {
path: path.to_string_lossy().to_string(), Err(e) => { eprintln!("Cannot read '{}': {e}", path.display()); return Ok(()); }
model_name: None, Ok(content) => match serde_json::from_str::<serde_json::Value>(&content) {
array_path: None, Err(e) => { eprintln!("JSON parse error: {e}"); return Ok(()); }
Ok(json) => Some(json),
}
}
} else {
None
}; };
let result = command::dispatch(&mut model, &cmd);
if !result.ok {
eprintln!("Import error: {}", result.message.unwrap_or_default());
}
}
run_tui(model, file_path) run_tui(model, file_path, import_json)
} }
fn run_headless( fn run_headless(
@ -149,7 +149,7 @@ fn run_headless(
std::process::exit(exit_code); std::process::exit(exit_code);
} }
fn run_tui(model: Model, file_path: Option<PathBuf>) -> Result<()> { fn run_tui(model: Model, file_path: Option<PathBuf>, import_json: Option<serde_json::Value>) -> Result<()> {
enable_raw_mode()?; enable_raw_mode()?;
let mut stdout = io::stdout(); let mut stdout = io::stdout();
execute!(stdout, EnterAlternateScreen)?; execute!(stdout, EnterAlternateScreen)?;
@ -157,6 +157,9 @@ fn run_tui(model: Model, file_path: Option<PathBuf>) -> Result<()> {
let mut terminal = Terminal::new(backend)?; let mut terminal = Terminal::new(backend)?;
let mut app = App::new(model, file_path); let mut app = App::new(model, file_path);
if let Some(json) = import_json {
app.start_import_wizard(json);
}
loop { loop {
terminal.draw(|f| draw(f, &app))?; terminal.draw(|f| draw(f, &app))?;