diff --git a/server-default.toml b/server-default.toml new file mode 100644 index 00000000..e69de29b diff --git a/src/main.rs b/src/main.rs index 64abe550..7144ba12 100644 --- a/src/main.rs +++ b/src/main.rs @@ -1,4 +1,5 @@ mod init; +mod server; use clap::Parser; @@ -30,6 +31,7 @@ fn main() { Command::Server(server) => match server { Server::Init => { println!("Server Init command"); + server::init(); } Server::Start => { println!("Server Start command"); diff --git a/src/server.rs b/src/server.rs new file mode 100644 index 00000000..cf2a47f9 --- /dev/null +++ b/src/server.rs @@ -0,0 +1,22 @@ +use std::io::Write; + +pub(crate) fn init() { + let file_name = "git-next-server.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!("../server-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); + } + } + } +}