From c29c91a7b92f97407df10df28f6af9651864f67a Mon Sep 17 00:00:00 2001 From: alemi Date: Fri, 25 Oct 2024 17:31:01 +0200 Subject: [PATCH] fix: smart var replace in client too --- src/model/client.rs | 22 +++++++++------------- 1 file changed, 9 insertions(+), 13 deletions(-) diff --git a/src/model/client.rs b/src/model/client.rs index a9ea0c6..20ddffe 100644 --- a/src/model/client.rs +++ b/src/model/client.rs @@ -1,4 +1,4 @@ -use crate::ext::FillableFromEnvironment; +use crate::ext::{FillError, FillableFromEnvironment}; #[derive(Debug, Default, Clone, serde::Serialize, serde::Deserialize)] @@ -16,21 +16,17 @@ pub struct ClientConfig { } impl FillableFromEnvironment for ClientConfig { - fn fill(mut self, env: &toml::Table) -> Self { + fn fill(mut self, env: &toml::Table) -> Result { let vars = Self::default_vars(env); - for (k, v) in vars { - let k_var = format!("${{{k}}}"); - - if let Some(base) = self.base { - self.base = Some(base.replace(&k_var, &v)); - } - - if let Some(user_agent) = self.user_agent { - self.user_agent = Some(user_agent.replace(&k_var, &v)); - } + if let Some(ref base) = self.base { + self.base = Some(Self::replace(base.clone(), &vars)?); } - self + if let Some(ref user_agent) = self.user_agent { + self.user_agent = Some(Self::replace(user_agent.clone(), &vars)?); + } + + Ok(self) } }