From 9a88386ddf67536508b812553c99ff75dba7d96a Mon Sep 17 00:00:00 2001 From: Matthias Ahouansou Date: Fri, 19 Apr 2024 21:06:58 +0100 Subject: [PATCH] feat: allow specifying config path via command flag --- src/clap.rs | 4 ++++ src/main.rs | 4 ++-- 2 files changed, 6 insertions(+), 2 deletions(-) diff --git a/src/clap.rs b/src/clap.rs index 68c2cca0..cea782cd 100644 --- a/src/clap.rs +++ b/src/clap.rs @@ -22,6 +22,10 @@ fn version() -> String { pub struct Args { #[command(subcommand)] pub command: Option, + + /// Path to the config file + #[arg(short, long, value_name = "PATH")] + pub config: Option, } #[derive(Subcommand)] diff --git a/src/main.rs b/src/main.rs index 3af475d9..ed7a7ccf 100644 --- a/src/main.rs +++ b/src/main.rs @@ -55,10 +55,10 @@ static GLOBAL: Jemalloc = Jemalloc; async fn main() { let cli = clap::parse(); - let path = + let path = cli.config.unwrap_or_else(|| { Env::var("CONDUIT_CONFIG") .expect("The config path must either be set via the -c/--config flag or the CONDUIT_CONFIG env var. Example: /etc/conduit.toml") - ; + }); match cli.command { Some(Commands::GenerateConfig) => {