add commandline arg to specify a conduwuit config file

Signed-off-by: strawberry <strawberry@puppygock.gay>
This commit is contained in:
strawberry 2024-03-09 18:41:26 -05:00 committed by June
parent aec7097cd3
commit d52f03414e
2 changed files with 20 additions and 4 deletions

View file

@ -53,13 +53,18 @@ use tracing_subscriber::{prelude::*, EnvFilter};
#[global_allocator]
static GLOBAL: Jemalloc = Jemalloc;
#[derive(Parser)]
#[derive(Parser, Debug)]
#[clap(version, about, long_about = None)]
struct Args;
struct Args {
#[arg(short, long)]
/// Optional argument to the path of a conduwuit config TOML file
config: Option<String>,
}
#[tokio::main]
async fn main() {
Args::parse();
let args = Args::parse();
// Initialize config
let raw_config = if Env::var("CONDUIT_CONFIG").is_some() {
Figment::new()
@ -71,6 +76,16 @@ async fn main() {
.nested(),
)
.merge(Env::prefixed("CONDUIT_").global())
} else if args.config.is_some() {
Figment::new()
.merge(
Toml::file(args.config.expect(
"conduwuit config commandline argument was specified, but appears to be invalid. This should be \
set to the path of a valid TOML file.",
))
.nested(),
)
.merge(Env::prefixed("CONDUIT_").global())
} else {
Figment::new().merge(Env::prefixed("CONDUIT_").global())
};