Skip to content

Commit 341402a

Browse files
committed
osrdyne: allow specifying an overriding configuration using CLI args
Signed-off-by: Leo Valais <[email protected]>
1 parent 26fc062 commit 341402a

File tree

2 files changed

+17
-8
lines changed

2 files changed

+17
-8
lines changed

osrdyne/src/config.rs

+10-7
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
use std::time::Duration;
1+
use std::{path::PathBuf, time::Duration};
22

33
use crate::drivers::{
44
docker::DockerDriverOptions, kubernetes::KubernetesDriverOptions,
@@ -53,10 +53,13 @@ impl Default for OsrdyneConfig {
5353
}
5454
}
5555

56-
pub fn parse_config() -> Result<OsrdyneConfig, figment::Error> {
57-
Figment::from(Serialized::defaults(OsrdyneConfig::default()))
58-
.merge(Yaml::file("osrdyne.yml"))
59-
// We use `__` as a separator for nested keys
60-
.merge(Env::prefixed("OSRDYNE__").split("__"))
61-
.extract()
56+
pub fn parse_config(file: Option<PathBuf>) -> Result<OsrdyneConfig, figment::Error> {
57+
let mut fig = Figment::from(Serialized::defaults(OsrdyneConfig::default()))
58+
.merge(Yaml::file("osrdyne.yml"));
59+
if let Some(file) = file {
60+
log::info!("Using configuration file: {}", file.display());
61+
fig = fig.merge(Yaml::file(file));
62+
}
63+
// We use `__` as a separator for nested keys
64+
fig.merge(Env::prefixed("OSRDYNE__").split("__")).extract()
6265
}

osrdyne/src/main.rs

+7-1
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ use lapin::ConnectionProperties;
33
use log::error;
44
use log::info;
55
use std::collections::BTreeMap;
6+
use std::path::PathBuf;
67
use std::sync::Arc;
78
use std::time::Duration;
89
use tokio::select;
@@ -62,7 +63,12 @@ fn request_queues_policy(config: &OsrdyneConfig) -> BTreeMap<String, ArgumentVal
6263
async fn main() -> Result<(), anyhow::Error> {
6364
env_logger::init();
6465

65-
let config = parse_config()?;
66+
let file = {
67+
let mut args = std::env::args();
68+
args.nth(1).map(PathBuf::from)
69+
};
70+
71+
let config = parse_config(file)?;
6672
log::info!("config: {:?}", &config);
6773
let pool = Arc::new(Pool::new(
6874
config.pool_id.clone(),

0 commit comments

Comments
 (0)