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

27 lines
802 B
Rust

use std::path::PathBuf;
use kxio::fs::FileSystem;
pub fn run(fs: FileSystem) {
let file_name = ".git-next.toml";
let pathbuf = PathBuf::from(file_name);
let Ok(exists) = fs.path_exists(&pathbuf) else {
eprintln!("Could not check if file exist: {}", file_name);
return;
};
if exists {
eprintln!(
"The configuration file already exists at {} - not overwritting it.",
file_name
);
} else {
match fs.file_write(&pathbuf, include_str!("../../../default.toml")) {
Ok(_) => {
println!("Created a default configuration file at {}", file_name);
}
Err(e) => {
eprintln!("Failed to write to the configuration file: {}", e)
}
}
}
}