feat(server): creates a default server configuration file

The default configuration is currently blank
This commit is contained in:
Paul Campbell 2024-04-06 18:42:34 +01:00
parent aa27e96d53
commit 1e3ca5b711
3 changed files with 24 additions and 0 deletions

0
server-default.toml Normal file
View file

View file

@ -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");

22
src/server.rs Normal file
View file

@ -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);
}
}
}
}