Skip to main content

batch_format

Function batch_format 

Source
pub fn batch_format(params: BatchFormatParams) -> Result<(), CliError>
Expand description

Batch format multiple HEDL files to canonical form.

Formats multiple HEDL files to canonical form, with options for check-only mode, ditto optimization, and count hints. Supports parallel processing for improved performance on large file sets.

§Arguments

  • patterns - List of file patterns (glob patterns or explicit paths)
  • output_dir - Optional output directory for formatted files. If None, files are processed in-place
  • check - If true, only checks if files are canonical without reformatting
  • ditto - If true, uses ditto optimization (repeated values as ")
  • with_counts - If true, automatically adds count hints to all matrix lists
  • recursive - Enable recursive directory traversal
  • max_depth - Maximum recursion depth
  • parallel - If true, processes files in parallel (automatically enabled for 4+ files)
  • verbose - If true, shows detailed progress information

§Returns

Returns Ok(()) if all files are successfully formatted, Err with a summary if any fail.

§Errors

Returns Err if:

  • Any file cannot be read
  • Any file contains syntax errors
  • Canonicalization fails for any file
  • In check mode, if any file is not already canonical
  • Output directory cannot be created
  • Formatted files cannot be written

§Examples

use hedl_cli::commands::{batch_format, BatchFormatParams};

// Format files to output directory
batch_format(BatchFormatParams {
    patterns: vec!["*.hedl".to_string()],
    output_dir: Some("formatted/".to_string()),
    check: false,
    ditto: true,
    with_counts: false,
    recursive: false,
    max_depth: 10,
    parallel: true,
    verbose: false,
    max_files_override: None,
})?;

§Output

Displays progress information and a summary:

  • Success/failure for each file (✓ or ✗)
  • Detailed error messages for failures
  • Final count of failures

§Performance

Automatically uses parallel processing when beneficial (4+ files by default). Can be forced with the parallel flag for smaller file sets.