feat(init): creates a default configuration file

The default configuration file is currently empty
This commit is contained in:
Paul Campbell 2024-04-06 18:39:20 +01:00
parent dd124d11ae
commit aa27e96d53
3 changed files with 25 additions and 0 deletions

0
default.toml Normal file
View file

22
src/init.rs Normal file
View file

@ -0,0 +1,22 @@
use std::io::Write;
pub(crate) fn run() {
let file_name = ".git-next.toml";
let path = std::path::Path::new(file_name);
if !path.exists() {
match std::fs::File::create(file_name) {
Ok(mut file) => {
println!("Created a default configuration file at {}", file_name);
match file.write_all(include_bytes!("../default.toml")) {
Ok(_) => println!("Wrote to the configuration file successfully."),
Err(e) => {
eprintln!("Failed to write to the configuration file: {}", e)
}
}
}
Err(e) => {
eprintln!("Failed to create a default configuration file: {}", e);
}
}
}
}

View file

@ -1,3 +1,5 @@
mod init;
use clap::Parser; use clap::Parser;
#[derive(Parser, Debug)] #[derive(Parser, Debug)]
@ -23,6 +25,7 @@ fn main() {
match commands.command { match commands.command {
Command::Init => { Command::Init => {
println!("Init command"); println!("Init command");
init::run();
} }
Command::Server(server) => match server { Command::Server(server) => match server {
Server::Init => { Server::Init => {