feat: take backup layers as arguments

export-backup
Jef Roosens 2023-06-23 10:53:17 +02:00
parent 0a459ee30b
commit a236c36a4f
Signed by: Jef Roosens
GPG Key ID: B75D4F293C7052DB
1 changed files with 51 additions and 0 deletions

View File

@ -1,6 +1,52 @@
use crate::server::ServerType; use crate::server::ServerType;
use clap::{Args, Parser, Subcommand}; use clap::{Args, Parser, Subcommand};
use std::error::Error;
use std::fmt;
use std::path::PathBuf; use std::path::PathBuf;
use std::str::FromStr;
#[derive(Clone, Debug)]
pub struct ManagerConfig {
name: String,
frequency: u32,
chain_len: u64,
chains: u64,
}
#[derive(Debug)]
pub struct ParseManagerConfigErr;
impl Error for ParseManagerConfigErr {}
impl fmt::Display for ParseManagerConfigErr {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
write!(f, "parse manager config err")
}
}
impl FromStr for ManagerConfig {
type Err = ParseManagerConfigErr;
fn from_str(s: &str) -> Result<Self, Self::Err> {
let splits: Vec<&str> = s.split(',').collect();
if let [name, frequency, chains, chain_len] = splits[..] {
let name: String = name.parse().map_err(|_| ParseManagerConfigErr)?;
let frequency: u32 = frequency.parse().map_err(|_| ParseManagerConfigErr)?;
let chains: u64 = chains.parse().map_err(|_| ParseManagerConfigErr)?;
let chain_len: u64 = chain_len.parse().map_err(|_| ParseManagerConfigErr)?;
Ok(ManagerConfig {
name,
chains,
chain_len,
frequency,
})
} else {
Err(ParseManagerConfigErr)
}
}
}
#[derive(Parser)] #[derive(Parser)]
#[command(author, version, about, long_about = None)] #[command(author, version, about, long_about = None)]
@ -35,6 +81,11 @@ pub struct Cli {
)] )]
pub backup: PathBuf, pub backup: PathBuf,
/// What backup layers to employ, provided as a list of tuples name,frequency,chain_len,chains
/// delimited by semicolons (;).
#[arg(long, env = "ALEX_LAYERS", global = true, value_delimiter = ';')]
pub layers: Vec<ManagerConfig>,
/// Length of a backup chain /// Length of a backup chain
#[arg( #[arg(
short = 'l', short = 'l',