73 lines
2.0 KiB
Rust
73 lines
2.0 KiB
Rust
use std::path::PathBuf;
|
|
use structopt::StructOpt;
|
|
|
|
mod backup;
|
|
mod config;
|
|
mod discord;
|
|
mod region;
|
|
|
|
use crate::backup::{convert_backup_to_sp, do_backup};
|
|
use crate::config::AlbatrossConfig;
|
|
|
|
#[derive(Debug, StructOpt)]
|
|
#[structopt(about = "Backup your Minecraft Server!")]
|
|
struct Albatross {
|
|
/// Path to the Albatross config
|
|
#[structopt(short, long, env = "ALBATROSS_CONFIG", parse(from_os_str))]
|
|
config_path: PathBuf,
|
|
/// Subcommand
|
|
#[structopt(subcommand)]
|
|
sub_command: SubCommand,
|
|
}
|
|
|
|
#[derive(Debug, StructOpt)]
|
|
enum SubCommand {
|
|
/// Backup a server
|
|
Backup {
|
|
/// Output location override
|
|
#[structopt(short = "o", long = "ouptut", parse(from_os_str))]
|
|
output: Option<PathBuf>,
|
|
},
|
|
/// Export a backup as a single player world
|
|
Export {
|
|
/// Convert backup to singleplayer world
|
|
#[structopt(parse(from_os_str))]
|
|
input_backup: PathBuf,
|
|
|
|
/// Output location override
|
|
#[structopt(parse(from_os_str))]
|
|
output: PathBuf,
|
|
},
|
|
}
|
|
|
|
fn main() {
|
|
let opt = Albatross::from_args();
|
|
|
|
let cfg = AlbatrossConfig::new(opt.config_path.into_os_string().to_str().unwrap())
|
|
.expect("Config not found");
|
|
|
|
if cfg.world_config.is_some() {
|
|
match opt.sub_command {
|
|
SubCommand::Backup { output } => {
|
|
println!("Starting backup");
|
|
match do_backup(cfg, output) {
|
|
Ok(_) => println!("Backup complete!"),
|
|
Err(e) => println!("Error doing backup: {:?}", e),
|
|
};
|
|
}
|
|
SubCommand::Export {
|
|
input_backup,
|
|
output,
|
|
} => {
|
|
println!("Starting export");
|
|
match convert_backup_to_sp(&cfg, &input_backup, &output) {
|
|
Ok(_) => println!("Export complete!"),
|
|
Err(e) => println!("Error exporting backup: {:?}", e),
|
|
};
|
|
}
|
|
}
|
|
} else {
|
|
println!("No worlds specified in config file!")
|
|
}
|
|
}
|