feat: added backup cli command
parent
27d7e681c3
commit
5275356353
|
@ -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)
|
## [Unreleased](https://git.rustybever.be/Chewing_Bever/alex/src/branch/dev)
|
||||||
|
|
||||||
|
### Added
|
||||||
|
|
||||||
|
* Added `backup` CLI command
|
||||||
|
|
||||||
### Changed
|
### Changed
|
||||||
|
|
||||||
* Running the server now uses the `run` CLI subcommand
|
* Running the server now uses the `run` CLI subcommand
|
||||||
|
|
12
src/cli.rs
12
src/cli.rs
|
@ -50,6 +50,9 @@ pub struct Cli {
|
||||||
pub enum Commands {
|
pub enum Commands {
|
||||||
/// Run the server
|
/// Run the server
|
||||||
Run(RunArgs),
|
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)]
|
#[derive(Args)]
|
||||||
|
@ -89,3 +92,12 @@ pub struct RunArgs {
|
||||||
#[arg(short, long, default_value_t = false)]
|
#[arg(short, long, default_value_t = false)]
|
||||||
pub dry: bool,
|
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,
|
||||||
|
}
|
||||||
|
|
14
src/main.rs
14
src/main.rs
|
@ -4,7 +4,7 @@ mod signals;
|
||||||
mod stdin;
|
mod stdin;
|
||||||
|
|
||||||
use clap::Parser;
|
use clap::Parser;
|
||||||
use cli::{Cli, Commands, RunArgs};
|
use cli::{BackupArgs, Cli, Commands, RunArgs};
|
||||||
use std::io;
|
use std::io;
|
||||||
use std::sync::{Arc, Mutex};
|
use std::sync::{Arc, Mutex};
|
||||||
|
|
||||||
|
@ -57,10 +57,22 @@ fn command_run(cli: &Cli, args: &RunArgs) -> io::Result<()> {
|
||||||
signals::handle_signals(&mut signals, counter)
|
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<()> {
|
fn main() -> io::Result<()> {
|
||||||
let cli = Cli::parse();
|
let cli = Cli::parse();
|
||||||
|
|
||||||
match &cli.command {
|
match &cli.command {
|
||||||
Commands::Run(args) => command_run(&cli, args),
|
Commands::Run(args) => command_run(&cli, args),
|
||||||
|
Commands::Backup(args) => commands_backup(&cli, args),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue