fix: handle PathBuf correctly

This commit is contained in:
Edward Langley
2026-04-01 22:14:19 -07:00
parent da93145de5
commit 1d5edd2c09
4 changed files with 48 additions and 37 deletions

View File

@ -1,3 +1,5 @@
use std::path::PathBuf;
use super::types::{CellValueArg, Command, CommandResult};
use crate::formula::parse_formula;
use crate::import::analyzer::{analyze_records, extract_array_at_path, FieldKind};
@ -169,11 +171,11 @@ pub fn dispatch(model: &mut Model, cmd: &Command) -> CommandResult {
fn import_headless(
model: &mut Model,
path: &str,
path: &PathBuf,
model_name: Option<&str>,
array_path: Option<&str>,
) -> CommandResult {
let is_csv = path.ends_with(".csv");
let is_csv = path.extension().is_some_and(|ext| ext.eq_ignore_ascii_case("csv"));
let records = if is_csv {
// Parse CSV file
@ -185,7 +187,7 @@ fn import_headless(
// Parse JSON file
let content = match std::fs::read_to_string(path) {
Ok(c) => c,
Err(e) => return CommandResult::err(format!("Cannot read '{path}': {e}")),
Err(e) => return CommandResult::err(format!("Cannot read '{}': {e}", path.display())),
};
let value: serde_json::Value = match serde_json::from_str(&content) {
Ok(v) => v,

View File

@ -1,3 +1,5 @@
use std::path::PathBuf;
use crate::view::Axis;
use serde::{Deserialize, Serialize};
@ -80,7 +82,7 @@ pub enum Command {
/// Import a JSON file via the analyzer (non-interactive, uses auto-detected proposals).
ImportJson {
path: String,
path: PathBuf,
model_name: Option<String>,
/// Dot-path to the records array (empty = root)
array_path: Option<String>,