Skip to content

Commit

Permalink
build(deps): config-0.12.0 and fixes (#178)
Browse files Browse the repository at this point in the history
  • Loading branch information
rinor authored Mar 1, 2022
1 parent a7107e1 commit 13700d2
Show file tree
Hide file tree
Showing 3 changed files with 37 additions and 31 deletions.
54 changes: 30 additions & 24 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ log = "0.4.14"
env_logger = "0.9.0"
crossterm = "0.23"
merge = "0.1.0"
config = { version = "0.11.0", default-features = false, features = ["toml"] }
config = { version = "0.12.0", default-features = false, features = ["toml"] }
serde = { version = "1.0.136", features = ["derive"] }
serde_json = "1.0.79"
strum = "0.23"
Expand Down
12 changes: 6 additions & 6 deletions src/bin/oura/daemon.rs
Original file line number Diff line number Diff line change
Expand Up @@ -139,23 +139,23 @@ struct ConfigRoot {

impl ConfigRoot {
pub fn new(explicit_file: Option<String>) -> Result<Self, ConfigError> {
let mut s = Config::default();
let mut s = Config::builder();

// our base config will always be in /etc/oura
s.merge(File::with_name("/etc/oura/daemon.toml").required(false))?;
s = s.add_source(File::with_name("/etc/oura/daemon.toml").required(false));

// but we can override it by having a file in the working dir
s.merge(File::with_name("oura.toml").required(false))?;
s = s.add_source(File::with_name("oura.toml").required(false));

// if an explicit file was passed, then we load it as mandatory
if let Some(explicit) = explicit_file {
s.merge(File::with_name(&explicit).required(true))?;
s = s.add_source(File::with_name(&explicit).required(true));
}

// finally, we use env vars to make some last-step overrides
s.merge(Environment::with_prefix("OURA").separator("_"))?;
s = s.add_source(Environment::with_prefix("OURA").separator("_"));

s.try_into()
s.build()?.try_deserialize()
}
}

Expand Down

0 comments on commit 13700d2

Please sign in to comment.