use std::path::Path;
use anyhow::{Context, Result};
use cabin_manifest::edit::{self, DocumentMut};
pub(crate) fn read_document(manifest_path: &Path) -> Result<DocumentMut> {
let text = std::fs::read_to_string(manifest_path)
.with_context(|| format!("failed to read manifest at {}", manifest_path.display()))?;
edit::parse_document(&text)
.with_context(|| format!("failed to parse manifest at {}", manifest_path.display()))
}
pub(crate) fn write_document(manifest_path: &Path, doc: &DocumentMut) -> Result<()> {
cabin_fs::write_atomic(manifest_path, doc.to_string())
.with_context(|| format!("failed to write manifest at {}", manifest_path.display()))
}