arg --openssl to --with-openssl
This commit is contained in:
parent
5e3ec48259
commit
1179840114
@ -6,7 +6,6 @@ use std::{
|
|||||||
collections::BTreeMap,
|
collections::BTreeMap,
|
||||||
fmt::Display,
|
fmt::Display,
|
||||||
path::{Path, PathBuf},
|
path::{Path, PathBuf},
|
||||||
str::FromStr,
|
|
||||||
};
|
};
|
||||||
use tokio::{
|
use tokio::{
|
||||||
fs::{self, File},
|
fs::{self, File},
|
||||||
@ -18,7 +17,7 @@ use futures_core::stream::Stream;
|
|||||||
pub(crate) type VarsMap = BTreeMap<String, String>;
|
pub(crate) type VarsMap = BTreeMap<String, String>;
|
||||||
|
|
||||||
pub(crate) const UTF8_STR: &str = "utf8";
|
pub(crate) const UTF8_STR: &str = "utf8";
|
||||||
pub(crate) const DEFAULT_ENCODING: &str = "cp866"; // .bat
|
pub(crate) const DEFAULT_ENCODING: &str = UTF8_STR;
|
||||||
|
|
||||||
#[derive(Debug, Clone, PartialEq)]
|
#[derive(Debug, Clone, PartialEq)]
|
||||||
pub enum OpenSSLProviderArg {
|
pub enum OpenSSLProviderArg {
|
||||||
@ -26,12 +25,11 @@ pub enum OpenSSLProviderArg {
|
|||||||
ExternalBin(String),
|
ExternalBin(String),
|
||||||
}
|
}
|
||||||
|
|
||||||
impl FromStr for OpenSSLProviderArg {
|
impl From<Option<&String>> for OpenSSLProviderArg {
|
||||||
type Err = anyhow::Error;
|
fn from(value: Option<&String>) -> Self {
|
||||||
fn from_str(s: &str) -> Result<Self, Self::Err> {
|
match value {
|
||||||
match s.to_ascii_lowercase().as_str() {
|
Some(x) => OpenSSLProviderArg::ExternalBin(x.clone()),
|
||||||
"internal" => Ok(OpenSSLProviderArg::Internal),
|
_ => OpenSSLProviderArg::Internal,
|
||||||
x => Ok(OpenSSLProviderArg::ExternalBin(x.to_string())),
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -75,9 +73,9 @@ pub(crate) struct Args {
|
|||||||
#[arg(long, default_value = "3650")]
|
#[arg(long, default_value = "3650")]
|
||||||
pub(crate) days: u32,
|
pub(crate) days: u32,
|
||||||
|
|
||||||
/// openssl binary or (internal)
|
/// use openssl binary
|
||||||
#[arg(long, short, default_value = "internal")]
|
#[arg(long = "with-openssl", short)]
|
||||||
pub(crate) openssl: OpenSSLProviderArg,
|
pub(crate) openssl: Option<String>,
|
||||||
|
|
||||||
/// template file
|
/// template file
|
||||||
#[arg(long, default_value = "template.ovpn")]
|
#[arg(long, default_value = "template.ovpn")]
|
||||||
@ -140,7 +138,7 @@ impl From<&Args> for AppConfig {
|
|||||||
defaults.encoding.clone()
|
defaults.encoding.clone()
|
||||||
};
|
};
|
||||||
let name = args.name.clone();
|
let name = args.name.clone();
|
||||||
let openssl = args.openssl.clone();
|
let openssl: OpenSSLProviderArg = args.openssl.as_ref().into();
|
||||||
let template_file = args.template_file.clone();
|
let template_file = args.template_file.clone();
|
||||||
let req_days = args.days;
|
let req_days = args.days;
|
||||||
let keys_subdir = args.keys_dir.clone();
|
let keys_subdir = args.keys_dir.clone();
|
||||||
@ -162,16 +160,10 @@ impl From<&Args> for AppConfig {
|
|||||||
}
|
}
|
||||||
|
|
||||||
pub(crate) async fn is_file_exist(filepath: &PathBuf) -> bool {
|
pub(crate) async fn is_file_exist(filepath: &PathBuf) -> bool {
|
||||||
let metadata = tokio::fs::metadata(&filepath).await;
|
match tokio::fs::metadata(&filepath).await {
|
||||||
if metadata.is_err() {
|
Ok(x) => x.is_file(),
|
||||||
return false;
|
_ => false,
|
||||||
}
|
}
|
||||||
|
|
||||||
if !metadata.unwrap().is_file() {
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
true
|
|
||||||
}
|
}
|
||||||
|
|
||||||
pub(crate) async fn read_file<P>(filepath: P, encoding: &str) -> Result<String>
|
pub(crate) async fn read_file<P>(filepath: P, encoding: &str) -> Result<String>
|
||||||
|
Loading…
Reference in New Issue
Block a user