use std::path::PathBuf;
use clap::Args;
#[derive(Debug, Clone, Copy)]
pub enum Protocol {
Tcp,
Udp,
}
#[derive(Args, Debug)]
pub struct NetworkClientOptions {
#[arg(long, default_value = "tcp")]
pub protocol: String,
#[arg(long, default_value = "127.0.0.1")]
pub host: String,
#[arg(long, default_value = "13337")]
pub port: u16,
#[arg(long, default_value = "100000")]
pub sleep: u64,
#[arg(long, default_value = "10")]
pub try_time: u64,
}
impl NetworkClientOptions {
pub fn protocol(&self) -> Protocol {
match self.protocol.as_str() {
"tcp" => Protocol::Tcp,
"udp" => Protocol::Udp,
_ => panic!("Invalid protocol specified"),
}
}
pub fn address(&self) -> String {
format!("{}:{}", self.host, self.port)
}
}
#[derive(Args, Debug)]
pub struct SSLOptions {
#[arg(long = "cert-file")]
pub cert_file: Option<PathBuf>,
#[arg(long = "key-file")]
pub key_file: Option<PathBuf>,
}
impl SSLOptions {
pub fn cert_file(&self) -> Option<String> {
self.cert_file
.clone()
.map(|p| p.to_str().unwrap().to_string())
}
pub fn key_file(&self) -> Option<String> {
self.key_file
.clone()
.map(|p| p.to_str().unwrap().to_string())
}
}