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

28 lines
802 B
Rust
Raw Normal View History

use std::path::PathBuf;
2024-04-28 08:05:09 +01:00
use kxio::fs::FileSystem;
2024-04-07 16:09:16 +01:00
pub fn run(fs: FileSystem) {
let file_name = ".git-next.toml";
2024-04-28 08:05:09 +01:00
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)
}
}
}
}