From aa27e96d538f86f393d1e768201ea5f2050e246b Mon Sep 17 00:00:00 2001 From: Paul Campbell Date: Sat, 6 Apr 2024 18:39:20 +0100 Subject: [PATCH] feat(init): creates a default configuration file The default configuration file is currently empty --- default.toml | 0 src/init.rs | 22 ++++++++++++++++++++++ src/main.rs | 3 +++ 3 files changed, 25 insertions(+) create mode 100644 default.toml create mode 100644 src/init.rs diff --git a/default.toml b/default.toml new file mode 100644 index 0000000..e69de29 diff --git a/src/init.rs b/src/init.rs new file mode 100644 index 0000000..9e00f6c --- /dev/null +++ b/src/init.rs @@ -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); + } + } + } +} diff --git a/src/main.rs b/src/main.rs index f8beee0..64abe55 100644 --- a/src/main.rs +++ b/src/main.rs @@ -1,3 +1,5 @@ +mod init; + use clap::Parser; #[derive(Parser, Debug)] @@ -23,6 +25,7 @@ fn main() { match commands.command { Command::Init => { println!("Init command"); + init::run(); } Command::Server(server) => match server { Server::Init => {