Write a TOML value to a file, backing up any existing file first.
(path: &Path, value: &toml::Value)
| 1452 | |
| 1453 | /// Write a TOML value to a file, backing up any existing file first. |
| 1454 | pub fn write_toml_file(path: &Path, value: &toml::Value) -> Result<()> { |
| 1455 | backup_file(path)?; |
| 1456 | let contents = toml::to_string_pretty(value).unwrap_or_else(|_| String::new()); |
| 1457 | std::fs::write(path, contents).map_err(|e| TraceDecayError::Config { |
| 1458 | message: format!("failed to write {}: {e}", path.display()), |
| 1459 | })?; |
| 1460 | eprintln!("\x1b[32m✔\x1b[0m Wrote {}", path.display()); |
| 1461 | Ok(()) |
| 1462 | } |
| 1463 | |
| 1464 | // --------------------------------------------------------------------------- |
| 1465 | // Git post-commit hook |