feat: add option to activate continuous monitoring on config file

This commit is contained in:
Jun Kurihara 2023-07-24 21:53:01 +09:00
commit 411fbaf296
No known key found for this signature in database
GPG key ID: D992B3E3DE1DED23
8 changed files with 216 additions and 30 deletions

View file

@ -3,25 +3,44 @@ use crate::{
cert_file_reader::CryptoFileSource,
error::{anyhow, ensure},
};
use clap::Arg;
use clap::{Arg, ArgAction};
use rpxy_lib::{AppConfig, AppConfigList, ProxyConfig};
pub fn parse_opts() -> Result<String, anyhow::Error> {
/// Parsed options
pub struct Opts {
pub config_file_path: String,
pub watch: bool,
}
/// Parse arg values passed from cli
pub fn parse_opts() -> Result<Opts, anyhow::Error> {
let _ = include_str!("../../Cargo.toml");
let options = clap::command!().arg(
Arg::new("config_file")
.long("config")
.short('c')
.value_name("FILE")
.required(true)
.help("Configuration file path like ./config.toml"),
);
let options = clap::command!()
.arg(
Arg::new("config_file")
.long("config")
.short('c')
.value_name("FILE")
.required(true)
.help("Configuration file path like ./config.toml"),
)
.arg(
Arg::new("watch")
.long("watch")
.short('w')
.action(ArgAction::SetTrue)
.help("Activate dynamic reloading of the config file via continuous monitoring"),
);
let matches = options.get_matches();
///////////////////////////////////
let config_file_path = matches.get_one::<String>("config_file").unwrap();
let config_file_path = matches.get_one::<String>("config_file").unwrap().to_owned();
let watch = matches.get_one::<bool>("watch").unwrap().to_owned();
Ok(config_file_path.to_string())
Ok(Opts {
config_file_path,
watch,
})
}
pub fn build_settings(