mod server; use clap::{Parser, Subcommand}; use server::{ServerCommand, ServerType}; use std::io; use std::path::PathBuf; #[derive(Parser)] #[command(author, version, about, long_about = None)] struct Cli { /// Type of server type_: ServerType, /// Version string for the server, e.g. 1.19.4-545 server_version: String, /// Server jar to execute jar: PathBuf, /// Directory where configs are stored, and where the server will run; defaults to the current /// directory. #[arg(long, value_name = "CONFIG_DIR")] config: Option, /// Directory where world files will be saved; defaults to ../worlds #[arg(long, value_name = "WORLD_DIR")] world: Option, /// Directory where backups will be stored; defaults to ../backups #[arg(long, value_name = "BACKUP_DIR")] backup: Option, /// XMS value for the server instance #[arg(long)] xms: Option, /// XMX value for the server instance #[arg(long)] xmx: Option, } fn main() { let cli = Cli::parse(); let mut cmd = server::ServerCommand::new(cli.type_, &cli.server_version) .jar(cli.jar) .config(cli.config.unwrap_or(".".into())) .world(cli.world.unwrap_or("../worlds".into())) .backup(cli.backup.unwrap_or("../backups".into())); if let Some(xms) = cli.xms { cmd = cmd.xms(xms); } if let Some(xmx) = cli.xmx { cmd = cmd.xmx(xmx); } let mut server = cmd.spawn().expect("Failed to start server."); let stdin = io::stdin(); let input = &mut String::new(); loop { input.clear(); stdin.read_line(input); println!("input: {}", input.trim()); if let Err(e) = server.send_command(input) { println!("{}", e); }; if input.trim() == "stop" { break; } } }