git-next/crates/cli/src/init.rs

19 lines
619 B
Rust
Raw Normal View History

//
use anyhow::{Context, Result};
2024-04-28 08:05:09 +01:00
use kxio::fs::FileSystem;
pub fn run(fs: FileSystem) -> Result<()> {
let pathbuf = fs.base().join(".git-next.toml");
if fs
.path_exists(&pathbuf)
.with_context(|| format!("Checking for existing file: {pathbuf:?}"))?
{
eprintln!("The configuration file already exists at {pathbuf:?} - not overwritting it.",);
} else {
fs.file_write(&pathbuf, include_str!("../default.toml"))
.with_context(|| format!("Writing file: {pathbuf:?}"))?;
println!("Created a default configuration file at {pathbuf:?}");
}
Ok(())
}