feat: take backup layers as arguments
parent
0a459ee30b
commit
a236c36a4f
51
src/cli.rs
51
src/cli.rs
|
@ -1,6 +1,52 @@
|
|||
use crate::server::ServerType;
|
||||
use clap::{Args, Parser, Subcommand};
|
||||
use std::error::Error;
|
||||
use std::fmt;
|
||||
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)]
|
||||
#[command(author, version, about, long_about = None)]
|
||||
|
@ -35,6 +81,11 @@ pub struct Cli {
|
|||
)]
|
||||
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
|
||||
#[arg(
|
||||
short = 'l',
|
||||
|
|
Loading…
Reference in New Issue