Skip to content

Commit

Permalink
osrdyne: exit if the provided configuration file doesn't exist
Browse files Browse the repository at this point in the history
`Yaml::file_exact` fails if the path doesn't point to a file.
`Yaml::file` does not (by design).

Signed-off-by: Leo Valais <leo.valais97@gmail.com>
  • Loading branch information
leovalais committed Oct 1, 2024
1 parent 91021c9 commit 390e639
Showing 1 changed file with 10 additions and 7 deletions.
17 changes: 10 additions & 7 deletions osrdyne/src/config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -54,12 +54,15 @@ impl Default for OsrdyneConfig {
}

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

0 comments on commit 390e639

Please sign in to comment.