Add support for environment files
This commit is contained in:
@ -48,6 +48,10 @@ pub enum ConsumptionBackend {
|
||||
#[derive(Parser, Debug)]
|
||||
#[command(version, about, long_about = None)]
|
||||
pub struct AppConfig {
|
||||
/// Read arguments from env file
|
||||
#[clap(short, long, env)]
|
||||
pub config: Option<String>,
|
||||
|
||||
/// Proxy IP, might end with a star "*"
|
||||
#[clap(short, long, env)]
|
||||
pub proxy_ip: Option<String>,
|
||||
@ -114,6 +118,21 @@ lazy_static::lazy_static! {
|
||||
}
|
||||
|
||||
impl AppConfig {
|
||||
/// Parse environment variables from file, if requedst
|
||||
pub fn parse_env_file() -> anyhow::Result<()> {
|
||||
if let Some(c) = Self::parse().config {
|
||||
log::info!("Load additional environment variables from {c}");
|
||||
let conf_file = Path::new(&c);
|
||||
|
||||
if !conf_file.is_file() {
|
||||
panic!("Specified configuration is not a file!");
|
||||
}
|
||||
dotenvy::from_path(conf_file)?;
|
||||
}
|
||||
|
||||
Ok(())
|
||||
}
|
||||
|
||||
/// Get parsed command line arguments
|
||||
pub fn get() -> &'static AppConfig {
|
||||
&ARGS
|
||||
|
@ -9,6 +9,9 @@ use tokio_schedule::{every, Job};
|
||||
|
||||
#[actix_web::main]
|
||||
async fn main() -> std::io::Result<()> {
|
||||
// Load additional config from file, if requested
|
||||
AppConfig::parse_env_file().expect("Failed to parse environment file!");
|
||||
|
||||
// Initialize OpenSSL
|
||||
openssl_sys::init();
|
||||
|
||||
|
Reference in New Issue
Block a user