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