pub fn format(
file: &str,
output: Option<&str>,
check: bool,
ditto: bool,
with_counts: bool,
) -> Result<(), CliError>Expand description
Format a HEDL file to canonical form.
Parses a HEDL file and outputs it in canonical (standardized) form. Can be used to check if a file is already canonical, or to add count hints to all matrix lists.
§Arguments
file- Path to the HEDL file to formatoutput- Optional output file path. IfNone, writes to stdoutcheck- Iftrue, only checks if the file is canonical without reformattingditto- Iftrue, uses ditto optimization (repeated values as")with_counts- Iftrue, automatically adds count hints to all matrix lists
§Returns
Returns Ok(()) on success, or Err if:
- The file cannot be read or parsed
- In check mode, if the file is not in canonical form
- Output cannot be written
§Errors
Returns Err if:
- The file cannot be read
- The file contains syntax errors
- Canonicalization fails
- In check mode, if the file is not already canonical
- Output writing fails
§Examples
use hedl_cli::commands::format;
// Format to stdout
format("input.hedl", None, false, true, false)?;
// Format to file with count hints
format("input.hedl", Some("output.hedl"), false, true, true)?;
// Check if file is already canonical
let result = format("input.hedl", None, true, true, false);
if result.is_ok() {
println!("File is already canonical");
}
// Disable ditto optimization
format("input.hedl", Some("output.hedl"), false, false, false)?;§Output
In check mode, prints “File is in canonical form” if valid, or returns an error. Otherwise, writes the canonical HEDL to the specified output or stdout.