From 527535635357d574b1d6e042a5a78271b6a9aecf Mon Sep 17 00:00:00 2001 From: Chewing_Bever Date: Fri, 16 Jun 2023 17:23:36 +0200 Subject: [PATCH] feat: added backup cli command --- CHANGELOG.md | 4 ++++ src/cli.rs | 12 ++++++++++++ src/main.rs | 14 +++++++++++++- 3 files changed, 29 insertions(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index e431581..e2ec666 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -7,6 +7,10 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 ## [Unreleased](https://git.rustybever.be/Chewing_Bever/alex/src/branch/dev) +### Added + +* Added `backup` CLI command + ### Changed * Running the server now uses the `run` CLI subcommand diff --git a/src/cli.rs b/src/cli.rs index 1acbe36..3c588aa 100644 --- a/src/cli.rs +++ b/src/cli.rs @@ -50,6 +50,9 @@ pub struct Cli { pub enum Commands { /// Run the server Run(RunArgs), + /// Create a new backup of the server. This command should only be used when the server is not + /// running. + Backup(BackupArgs), } #[derive(Args)] @@ -89,3 +92,12 @@ pub struct RunArgs { #[arg(short, long, default_value_t = false)] pub dry: bool, } + +#[derive(Args)] +pub struct BackupArgs { + /// Type of server + pub type_: ServerType, + /// Version string for the server, e.g. 1.19.4-545 + #[arg(env = "ALEX_SERVER_VERSION")] + pub server_version: String, +} diff --git a/src/main.rs b/src/main.rs index a1ae21c..3d82d11 100644 --- a/src/main.rs +++ b/src/main.rs @@ -4,7 +4,7 @@ mod signals; mod stdin; use clap::Parser; -use cli::{Cli, Commands, RunArgs}; +use cli::{BackupArgs, Cli, Commands, RunArgs}; use std::io; use std::sync::{Arc, Mutex}; @@ -57,10 +57,22 @@ fn command_run(cli: &Cli, args: &RunArgs) -> io::Result<()> { signals::handle_signals(&mut signals, counter) } +fn commands_backup(cli: &Cli, _args: &BackupArgs) -> io::Result<()> { + let mut manager = server::BackupManager::open( + cli.backup.clone(), + cli.config.clone(), + cli.world.clone(), + cli.max_backups, + )?; + + manager.create_backup() +} + fn main() -> io::Result<()> { let cli = Cli::parse(); match &cli.command { Commands::Run(args) => command_run(&cli, args), + Commands::Backup(args) => commands_backup(&cli, args), } }