feat: started cli interface
This commit is contained in:
parent
c5b579b8db
commit
d0321f7ed1
4 changed files with 246 additions and 11 deletions
56
src/main.rs
56
src/main.rs
|
|
@ -1,17 +1,57 @@
|
|||
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<PathBuf>,
|
||||
/// Directory where world files will be saved; defaults to ../worlds
|
||||
#[arg(long, value_name = "WORLD_DIR")]
|
||||
world: Option<PathBuf>,
|
||||
/// Directory where backups will be stored; defaults to ../backups
|
||||
#[arg(long, value_name = "BACKUP_DIR")]
|
||||
backup: Option<PathBuf>,
|
||||
|
||||
/// XMS value for the server instance
|
||||
#[arg(long)]
|
||||
xms: Option<u32>,
|
||||
/// XMX value for the server instance
|
||||
#[arg(long)]
|
||||
xmx: Option<u32>,
|
||||
}
|
||||
|
||||
fn main() {
|
||||
let mut server = server::ServerCommand::new(ServerType::Paper, "1.19.4-545")
|
||||
.jar("paper-1.19.4-545.jar")
|
||||
.config("data/config")
|
||||
.world("data/worlds")
|
||||
.backup("data/backups")
|
||||
.mem(512, 1024)
|
||||
.spawn()
|
||||
.unwrap();
|
||||
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();
|
||||
|
|
|
|||
|
|
@ -1,10 +1,12 @@
|
|||
use crate::server::ServerProcess;
|
||||
use clap::ValueEnum;
|
||||
use std::fmt;
|
||||
use std::fs::File;
|
||||
use std::io::Write;
|
||||
use std::path::{Path, PathBuf};
|
||||
use std::process::{Child, Command, Stdio};
|
||||
|
||||
#[derive(Copy, Clone, PartialEq, Eq, PartialOrd, Ord, ValueEnum)]
|
||||
pub enum ServerType {
|
||||
Paper,
|
||||
Forge,
|
||||
|
|
@ -77,10 +79,13 @@ impl ServerCommand {
|
|||
self
|
||||
}
|
||||
|
||||
pub fn mem(mut self, xms: u32, xmx: u32) -> Self {
|
||||
self.xms = xms;
|
||||
self.xmx = xmx;
|
||||
pub fn xms(mut self, v: u32) -> Self {
|
||||
self.xms = v;
|
||||
self
|
||||
}
|
||||
|
||||
pub fn xmx(mut self, v: u32) -> Self {
|
||||
self.xmx = v;
|
||||
self
|
||||
}
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue