craby_cli 0.1.0-beta.6

Craby CLI
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
use std::{fs, path::PathBuf};

pub fn write_file(file_path: &PathBuf, content: &String, overwrite: bool) -> anyhow::Result<bool> {
    if !overwrite && file_path.try_exists()? {
        return Ok(false);
    }

    if let Some(parent) = file_path.parent() {
        if !parent.try_exists()? {
            fs::create_dir_all(parent)?;
        }
    }

    fs::write(file_path, content)?;
    Ok(true)
}