Skip to main content

write_output

Function write_output 

Source
pub fn write_output(content: &str, path: Option<&str>) -> Result<(), CliError>
Expand description

Write content to a file or stdout.

Writes the provided content to either a specified file path or to stdout if no path is provided. This is the standard output mechanism used by all HEDL CLI commands.

§Arguments

  • content - The string content to write
  • path - Optional output file path. If None, writes to stdout

§Returns

Returns Ok(()) on success.

§Errors

Returns Err if:

  • File creation or writing fails (when path is Some)
  • Writing to stdout fails (when path is None)

§Examples

use hedl_cli::commands::write_output;

// Write to stdout
let hedl_content = "%VERSION: 1.0\n---\nteams:@Team[name]\n  |t1,Team A\n  |t2,Team B";
write_output(hedl_content, None)?;

// Write to file
write_output(hedl_content, Some("output.hedl"))?;

§Panics

Does not panic under normal circumstances. All I/O errors are returned as Err values.