Compare commits

...

1 Commits

Author SHA1 Message Date
Jędrzej Stuczyński 071e7de44d bugfix: always read values of environmental config options
regardless of whether they have the default values or not
2023-01-11 13:08:14 +00:00
+6 -3
View File
@@ -2,7 +2,6 @@
// SPDX-License-Identifier: Apache-2.0 // SPDX-License-Identifier: Apache-2.0
use handlebars::Handlebars; use handlebars::Handlebars;
use network_defaults::mainnet::read_var_if_not_default;
use network_defaults::var_names::CONFIGURED; use network_defaults::var_names::CONFIGURED;
use serde::de::DeserializeOwned; use serde::de::DeserializeOwned;
use serde::Serialize; use serde::Serialize;
@@ -155,10 +154,12 @@ pub trait OptionalSet {
<T as FromStr>::Err: Debug, <T as FromStr>::Err: Debug,
Self: Sized, Self: Sized,
{ {
// if explicit value is provided, use it
if let Some(val) = val { if let Some(val) = val {
return f(self, val); return f(self, val);
} else if std::env::var(CONFIGURED).is_ok() { } else if std::env::var(CONFIGURED).is_ok() {
if let Some(raw) = read_var_if_not_default(env_var) { // otherwise if environmental variable is configured, fallback to that and parse it from string
if let Ok(raw) = std::env::var(env_var) {
return f( return f(
self, self,
raw.parse().unwrap_or_else(|err| { raw.parse().unwrap_or_else(|err| {
@@ -186,10 +187,12 @@ pub trait OptionalSet {
G: Fn(&str) -> T, G: Fn(&str) -> T,
Self: Sized, Self: Sized,
{ {
// if explicit value is provided, use it
if let Some(val) = val { if let Some(val) = val {
return f(self, val); return f(self, val);
} else if std::env::var(CONFIGURED).is_ok() { } else if std::env::var(CONFIGURED).is_ok() {
if let Some(raw) = read_var_if_not_default(env_var) { // otherwise if environmental variable is configured, fallback to that
if let Ok(raw) = std::env::var(env_var) {
return f(self, parser(&raw)); return f(self, parser(&raw));
} }
} }