diff --git a/default.toml b/default.toml new file mode 100644 index 00000000..e69de29b diff --git a/src/init.rs b/src/init.rs new file mode 100644 index 00000000..9e00f6ce --- /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 f8beee0f..64abe550 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 => {