Skip to main content

candle_graph/
cli.rs

1//! Trace-file CLI helpers.
2
3pub mod args;
4pub mod trace_cli;
5
6use anyhow::{Context, Result};
7use std::io::{self, Write};
8use std::path::Path;
9
10pub fn write_output(path: Option<&Path>, bytes: &[u8]) -> Result<()> {
11    match path {
12        Some(path) => {
13            if let Some(parent) = path
14                .parent()
15                .filter(|parent| !parent.as_os_str().is_empty())
16            {
17                std::fs::create_dir_all(parent)
18                    .with_context(|| format!("creating {}", parent.display()))?;
19            }
20            std::fs::write(path, bytes).with_context(|| format!("writing {}", path.display()))?;
21        }
22        None => io::stdout().lock().write_all(bytes)?,
23    }
24    Ok(())
25}