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