from_csv

Function from_csv 

Source
pub fn from_csv(
    file: &str,
    output: Option<&str>,
    type_name: &str,
) -> Result<(), CliError>
Expand description

Convert a CSV file to HEDL format.

Parses a CSV file and converts it to canonical HEDL format. The first row is assumed to be the header row containing column names.

§Arguments

  • file - Path to the CSV file to convert
  • output - Optional output file path. If None, writes to stdout
  • type_name - The type name to use for the HEDL matrix list (must be alphanumeric)

§Returns

Returns Ok(()) on success.

§Errors

Returns Err if:

  • The file cannot be read
  • The CSV is malformed or empty
  • The type name is invalid (must be alphanumeric with underscores)
  • CSV-to-HEDL conversion fails
  • HEDL canonicalization fails
  • Output writing fails

§Examples

use hedl_cli::commands::from_csv;

// Convert CSV to HEDL on stdout with type name "Person"
from_csv("people.csv", None, "Person")?;

// Convert CSV to HEDL file
from_csv("data.csv", Some("output.hedl"), "Record")?;

// Invalid type name will fail
let result = from_csv("data.csv", None, "Invalid-Name!");
assert!(result.is_err());

§Security

The type name is validated to prevent injection attacks. Only alphanumeric characters and underscores are allowed.