cargo_setupx/utils/
write_file.rs1use crate::error::{Result, SetupError};
4use std::fs;
5use std::path::Path;
6
7pub fn write_file(path: &Path, content: &str, force: bool) -> Result<()> {
9 if path.exists() && !force {
10 return Err(SetupError::FileExists {
11 path: path.to_path_buf(),
12 });
13 }
14
15 if let Some(parent) = path.parent() {
17 fs::create_dir_all(parent)?;
18 }
19
20 fs::write(path, content)?;
21
22 let status = if path.exists() && force {
23 "✏️ Overwrote"
24 } else {
25 "✅ Created"
26 };
27
28 println!("{} {}", status, path.display());
29 Ok(())
30}