From 79d0bba640d954cd3e6acd7f4e83900eb9d56a1c Mon Sep 17 00:00:00 2001 From: sigoden Date: Tue, 14 May 2024 12:43:16 +0800 Subject: feat: allow binding model to the role (#505) --- src/client/common.rs | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) (limited to 'src/client/common.rs') diff --git a/src/client/common.rs b/src/client/common.rs index 495160b..004a7dc 100644 --- a/src/client/common.rs +++ b/src/client/common.rs @@ -70,8 +70,7 @@ macro_rules! register_client { impl $client { pub const NAME: &'static str = $name; - pub fn init(global_config: &$crate::config::GlobalConfig) -> Option> { - let model = global_config.read().model.clone(); + pub fn init(global_config: &$crate::config::GlobalConfig, model: &$crate::client::Model) -> Option> { let config = global_config.read().clients.iter().find_map(|client_config| { if let ClientConfig::$config(c) = client_config { if Self::name(c) == &model.client_name { @@ -84,7 +83,7 @@ macro_rules! register_client { Some(Box::new(Self { global_config: global_config.clone(), config, - model, + model: model.clone(), })) } @@ -109,11 +108,12 @@ macro_rules! register_client { )+ - pub fn init_client(config: &$crate::config::GlobalConfig) -> anyhow::Result> { + pub fn init_client(config: &$crate::config::GlobalConfig, model: Option<$crate::client::Model>) -> anyhow::Result> { + let model = model.unwrap_or_else(|| config.read().model.clone()); None - $(.or_else(|| $client::init(config)))+ + $(.or_else(|| $client::init(config, &model)))+ .ok_or_else(|| { - anyhow::anyhow!("Unknown client '{}'", &config.read().model.client_name) + anyhow::anyhow!("Unknown client '{}'", model.client_name) }) } -- cgit v1.2.3