Skip to main content

mint_cli/output/
report.rs

1use std::path::Path;
2
3use serde_json::Value;
4
5use crate::output::error::OutputError;
6
7/// Write used values JSON report to disk.
8pub fn write_used_values_json(path: &Path, report: &Value) -> Result<(), OutputError> {
9    let contents = serde_json::to_string_pretty(report)
10        .map_err(|e| OutputError::FileError(format!("failed to serialize JSON report: {}", e)))?;
11
12    if let Some(parent) = path.parent()
13        && !parent.as_os_str().is_empty()
14    {
15        std::fs::create_dir_all(parent).map_err(|e| {
16            OutputError::FileError(format!(
17                "failed to create report directory {}: {}",
18                parent.display(),
19                e
20            ))
21        })?;
22    }
23
24    std::fs::write(path, contents).map_err(|e| {
25        OutputError::FileError(format!(
26            "failed to write JSON report {}: {}",
27            path.display(),
28            e
29        ))
30    })?;
31
32    Ok(())
33}