72 lines
2.1 KiB
Rust
72 lines
2.1 KiB
Rust
extern crate argparse;
|
|
|
|
use std::path::PathBuf;
|
|
|
|
#[derive(Debug, Clone, new)]
|
|
pub struct CliArguments {
|
|
pub ip_address: String,
|
|
pub port_number: u16,
|
|
pub data_store: PathBuf,
|
|
pub target_block_device: String,
|
|
pub block_size: u32,
|
|
pub check_size: u32,
|
|
}
|
|
|
|
pub fn get_arguments_parsed() -> CliArguments {
|
|
let mut ca = CliArguments::new(
|
|
"0.0.0.0".to_string(),
|
|
8754,
|
|
PathBuf::from("."),
|
|
String::new(),
|
|
16 << 20,
|
|
128 << 20,
|
|
);
|
|
{
|
|
let mut parser = argparse::ArgumentParser::new();
|
|
parser.set_description(
|
|
"Backs your block devices (hard drives) up using an X25519 key.",
|
|
);
|
|
parser
|
|
.refer(&mut ca.ip_address)
|
|
.add_argument("HOST", argparse::Store, "Host")
|
|
.required();
|
|
parser
|
|
.refer(&mut ca.port_number)
|
|
.add_option(&["-p", "--port"], argparse::Store, "Port");
|
|
parser.refer(&mut ca.block_size).add_option(
|
|
&["-b", "--block"],
|
|
argparse::Store,
|
|
"Block sizes to store",
|
|
);
|
|
parser.refer(&mut ca.check_size).add_option(
|
|
&["-c", "--check"],
|
|
argparse::Store,
|
|
"Multi-block sizes to check hashes",
|
|
);
|
|
parser.refer(&mut ca.data_store).add_argument(
|
|
&"DEST",
|
|
argparse::Store,
|
|
"Backup parts destination",
|
|
).required();
|
|
parser.refer(&mut ca.target_block_device).add_argument(
|
|
&"TARGET",
|
|
argparse::Store,
|
|
"Remote block device to back up",
|
|
).required();
|
|
parser.parse_args_or_exit();
|
|
}
|
|
if ca.check_size < ca.block_size {
|
|
panic!("{} must not be less than {}", ca.check_size, ca.block_size);
|
|
}
|
|
if (ca.check_size % 4096) != 0 {
|
|
panic!("{} must be multiple of {}", ca.check_size, 4096);
|
|
}
|
|
if (ca.block_size % 4096) != 0 {
|
|
panic!("{} must be multiple of {}", ca.block_size, 4096);
|
|
}
|
|
if (ca.check_size % ca.block_size) != 0 {
|
|
panic!("{} must be multiple of {}", ca.block_size, ca.block_size);
|
|
}
|
|
ca
|
|
}
|