Added a start command
All checks were successful
ci/woodpecker/push/woodpecker Pipeline was successful

This commit is contained in:
Gregory Ballantine 2022-09-19 17:21:23 -04:00
parent da099a11ce
commit dc9b3a7262
3 changed files with 32 additions and 1 deletions

View File

@ -1 +1,2 @@
pub mod new; pub mod new;
pub mod start;

23
src/cmd/start.rs Normal file
View File

@ -0,0 +1,23 @@
use std::process::Command;
pub fn start_command(server_name: &str) -> Result<(), Box<dyn std::error::Error>> {
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(())
}

View File

@ -15,11 +15,17 @@ enum Commands {
// new server subcommand // new server subcommand
#[clap(name = "new", about = "Create a new Minecraft java edition server instance.")] #[clap(name = "new", about = "Create a new Minecraft java edition server instance.")]
New { 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, server_name: String,
#[clap(short = 'm', long, required = true, help = "[REQUIRED] Minecraft Java Edition server version to use.")] #[clap(short = 'm', long, required = true, help = "[REQUIRED] Minecraft Java Edition server version to use.")]
minecraft_version: String, 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() { fn main() {
@ -29,6 +35,7 @@ fn main() {
// map subcommands back to the main command // map subcommands back to the main command
let res = match &cli.command { let res = match &cli.command {
Commands::New { server_name, minecraft_version } => cmd::new::new_command(&server_name, &minecraft_version), 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 { match res {