From dc9b3a7262bd1da19739b5890b06970ed55d8b93 Mon Sep 17 00:00:00 2001 From: Gregory Ballantine Date: Mon, 19 Sep 2022 17:21:23 -0400 Subject: [PATCH] Added a start command --- src/cmd/mod.rs | 1 + src/cmd/start.rs | 23 +++++++++++++++++++++++ src/main.rs | 9 ++++++++- 3 files changed, 32 insertions(+), 1 deletion(-) create mode 100644 src/cmd/start.rs diff --git a/src/cmd/mod.rs b/src/cmd/mod.rs index 9d52a2b..cd38724 100644 --- a/src/cmd/mod.rs +++ b/src/cmd/mod.rs @@ -1 +1,2 @@ pub mod new; +pub mod start; diff --git a/src/cmd/start.rs b/src/cmd/start.rs new file mode 100644 index 0000000..6f04a78 --- /dev/null +++ b/src/cmd/start.rs @@ -0,0 +1,23 @@ +use std::process::Command; + +pub fn start_command(server_name: &str) -> Result<(), Box> { + println!("Starting server {}.", server_name); + + // set up our path variables + let home_path = shellexpand::tilde("~"); + let server_directory_path = format!("{}/{}", home_path, server_name); + let script_file_path = format!("{}/start.sh", server_directory_path); + let eula_file_path = format!("{}/eula.txt", server_directory_path); + + // check if eula.txt exists - if it doesn't then warn the user they'll need to accept it and possibly modify server settings + if !std::path::Path::new(&eula_file_path).exists() { + println!("The eula.txt does not exist - you will need to accept the EULA located at {} by changing 'false' to 'true'.", eula_file_path); + println!("This appears to be a new server instance. Don't forget to modify server.properties!"); + } + + // run the start command + Command::new(script_file_path).output()?; + + // return okay signal + Ok(()) +} diff --git a/src/main.rs b/src/main.rs index 640d422..b821e4f 100644 --- a/src/main.rs +++ b/src/main.rs @@ -15,11 +15,17 @@ enum Commands { // new server subcommand #[clap(name = "new", about = "Create a new Minecraft java edition server instance.")] New { - #[clap(short = 'n', long, required = true, help = "[REQUIRED] The name for your new server")] + #[clap(short = 'n', long, required = true, help = "[REQUIRED] The name for your new server.")] server_name: String, #[clap(short = 'm', long, required = true, help = "[REQUIRED] Minecraft Java Edition server version to use.")] minecraft_version: String, }, + + #[clap(name = "start", about = "Start a Minecraft java edition server instance.")] + Start { + #[clap(short = 'n', long, required = true, help = "[REQUIRED] The name of your Minecraft server instance.")] + server_name: String, + } } fn main() { @@ -29,6 +35,7 @@ fn main() { // map subcommands back to the main command let res = match &cli.command { Commands::New { server_name, minecraft_version } => cmd::new::new_command(&server_name, &minecraft_version), + Commands::Start { server_name } => cmd::start::start_command(&server_name), }; match res {