shine_core/init_template.rs
1use anyhow::{Context, Result, bail};
2use std::path::{Path, PathBuf};
3
4/// Write a `shine.toml` preset-metadata template into `dir`, refusing to
5/// overwrite an existing file unless `force` is set.
6///
7/// Returns the written path and whether an existing file was overwritten.
8pub fn write_shine_toml_template(
9 dir: &Path,
10 force: bool,
11 template: &str,
12) -> Result<(PathBuf, bool)> {
13 let path = dir.join("shine.toml");
14 let exists = path.exists();
15 if exists && !force {
16 bail!("shine.toml already exists; use --force to overwrite");
17 }
18 std::fs::write(&path, template).with_context(|| format!("writing {}", path.display()))?;
19 Ok((path, exists))
20}