From 1e3ca5b7119d4b243f005be0d08fa49c0cbfd62e Mon Sep 17 00:00:00 2001 From: Paul Campbell Date: Sat, 6 Apr 2024 18:42:34 +0100 Subject: [PATCH] feat(server): creates a default server configuration file The default configuration is currently blank --- server-default.toml | 0 src/main.rs | 2 ++ src/server.rs | 22 ++++++++++++++++++++++ 3 files changed, 24 insertions(+) create mode 100644 server-default.toml create mode 100644 src/server.rs 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); + } + } + } +}