From 60a732ef0cfaaba3eaf14a43f57614f4988e172e Mon Sep 17 00:00:00 2001 From: Hatter Jiang Date: Sat, 4 Sep 2021 01:06:09 +0800 Subject: [PATCH] feat: add port for cert config --- src/config.rs | 3 ++- src/main.rs | 15 ++++++++------- 2 files changed, 10 insertions(+), 8 deletions(-) diff --git a/src/config.rs b/src/config.rs index 55bca69..9be659e 100644 --- a/src/config.rs +++ b/src/config.rs @@ -53,6 +53,7 @@ pub struct CertConfigItem { #[derive(Clone, Debug, Serialize, Deserialize)] #[serde(rename_all = "camelCase")] pub struct CertConfig { + pub port: Option, pub cert_items: Vec, } @@ -93,7 +94,7 @@ impl CertConfig { } } - Self { cert_items: filtered_cert_items } + Self { port: self.port, cert_items: filtered_cert_items } } pub fn load(config_fn: &str) -> XResult { diff --git a/src/main.rs b/src/main.rs index 37eef21..901a3fc 100644 --- a/src/main.rs +++ b/src/main.rs @@ -186,6 +186,14 @@ async fn main() -> tide::Result<()> { } }; + let cert_config_file = matches.value_of("config"); + let cert_config = cert_config_file.map(|f| + CertConfig::load(f).unwrap_or_else(|e| { + failure!("Load cert config: {}, failed: {}", f, e); + exit(1); + })); + let port = cert_config.as_ref().map(|c| c.port).flatten().unwrap_or(port); + let check = matches.is_present("check"); if !check { @@ -195,7 +203,6 @@ async fn main() -> tide::Result<()> { task::sleep(Duration::from_millis(500)).await; } - let cert_config = matches.value_of("config"); match cert_config { None => { // cert config is not assigned if check { @@ -240,12 +247,6 @@ async fn main() -> tide::Result<()> { } } Some(cert_config) => { // cert config is assigned - let cert_config = { - CertConfig::load(cert_config).unwrap_or_else(|e| { - failure!("Load cert config: {}, failed: {}", cert_config, e); - exit(1); - }) - }; if check { check_cert_config(&cert_config); return Ok(());