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

29 lines
945 B
Rust
Raw Normal View History

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-05-14 07:58:28 +01:00
let pathbuf = fs.base().join(file_name);
match fs.path_exists(&pathbuf) {
Ok(exists) => {
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)
}
}
}
}
2024-05-14 07:58:28 +01:00
Err(err) => {
eprintln!("Could not check if file exist: {} - {err:?}", file_name);
}
}
}