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);
}
// 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::<serde_json::Value>(&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<PathBuf>) -> Result<()> {
fn run_tui(model: Model, file_path: Option<PathBuf>, import_json: Option<serde_json::Value>) -> Result<()> {
enable_raw_mode()?;
let mut stdout = io::stdout();
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 app = App::new(model, file_path);
if let Some(json) = import_json {
app.start_import_wizard(json);
}
loop {
terminal.draw(|f| draw(f, &app))?;