refactor: split configure into configure_options and configure_outputs methods
Co-authored-by: aider (openai/andrew/openrouter/anthropic/claude-sonnet-4) <aider@aider.chat>
This commit is contained in:
@@ -109,16 +109,16 @@ pub trait MetaPlugin {
|
||||
output_metadata(conn, item_id, internal_name, value, self.outputs())
|
||||
}
|
||||
|
||||
// Configure plugin with options and outputs
|
||||
fn configure(&mut self, options: &std::collections::HashMap<String, serde_yaml::Value>) -> Result<()> {
|
||||
if let Some(outputs) = options.get("outputs") {
|
||||
if let Some(outputs_map) = outputs.as_mapping() {
|
||||
for (key, value) in outputs_map {
|
||||
if let Some(key_str) = key.as_str() {
|
||||
self.outputs_mut().insert(key_str.to_string(), value.clone());
|
||||
}
|
||||
}
|
||||
// Configure plugin with options (excluding outputs)
|
||||
fn configure_options(&mut self, _options: &std::collections::HashMap<String, serde_yaml::Value>) -> Result<()> {
|
||||
// Default implementation does nothing - plugins can override this
|
||||
Ok(())
|
||||
}
|
||||
|
||||
// Configure plugin outputs mapping
|
||||
fn configure_outputs(&mut self, outputs: &std::collections::HashMap<String, serde_yaml::Value>) -> Result<()> {
|
||||
for (key, value) in outputs {
|
||||
self.outputs_mut().insert(key.clone(), value.clone());
|
||||
}
|
||||
Ok(())
|
||||
}
|
||||
|
||||
@@ -83,15 +83,13 @@ impl MetaPlugin for BinaryMetaPlugin {
|
||||
Ok(())
|
||||
}
|
||||
|
||||
fn configure(&mut self, options: &std::collections::HashMap<String, serde_yaml::Value>) -> Result<()> {
|
||||
fn configure_options(&mut self, options: &std::collections::HashMap<String, serde_yaml::Value>) -> Result<()> {
|
||||
if let Some(max_buffer_size) = options.get("max_buffer_size") {
|
||||
if let Some(size) = max_buffer_size.as_u64() {
|
||||
self.max_buffer_size = size as usize;
|
||||
}
|
||||
}
|
||||
|
||||
// Call default implementation for outputs
|
||||
MetaPlugin::configure(self, options)
|
||||
Ok(())
|
||||
}
|
||||
|
||||
fn outputs(&self) -> &std::collections::HashMap<String, serde_yaml::Value> {
|
||||
|
||||
@@ -129,15 +129,13 @@ impl MetaPlugin for MagicFileMetaPlugin {
|
||||
"magic_file".to_string()
|
||||
}
|
||||
|
||||
fn configure(&mut self, options: &std::collections::HashMap<String, serde_yaml::Value>) -> Result<()> {
|
||||
fn configure_options(&mut self, options: &std::collections::HashMap<String, serde_yaml::Value>) -> Result<()> {
|
||||
if let Some(max_buffer_size) = options.get("max_buffer_size") {
|
||||
if let Some(size) = max_buffer_size.as_u64() {
|
||||
self.max_buffer_size = size as usize;
|
||||
}
|
||||
}
|
||||
|
||||
// Call default implementation for outputs
|
||||
MetaPlugin::configure(self, options)
|
||||
Ok(())
|
||||
}
|
||||
|
||||
fn outputs(&self) -> &std::collections::HashMap<String, serde_yaml::Value> {
|
||||
|
||||
@@ -47,14 +47,14 @@ fn setup_compression_and_plugins(
|
||||
for meta_plugin in meta_plugins.iter_mut() {
|
||||
let plugin_name = meta_plugin.meta_name();
|
||||
if let Some(config) = meta_plugin_configs.iter().find(|c| c.name == plugin_name) {
|
||||
// Set outputs first
|
||||
for (key, value) in &config.outputs {
|
||||
meta_plugin.outputs_mut().insert(key.clone(), serde_yaml::Value::String(value.clone()));
|
||||
// Configure outputs first
|
||||
if let Err(e) = meta_plugin.configure_outputs(&config.outputs.iter().map(|(k, v)| (k.clone(), serde_yaml::Value::String(v.clone()))).collect()) {
|
||||
eprintln!("Warning: Failed to configure outputs for meta plugin '{}': {}", plugin_name, e);
|
||||
}
|
||||
|
||||
// Then configure with options
|
||||
if let Err(e) = meta_plugin.configure(&config.options) {
|
||||
eprintln!("Warning: Failed to configure meta plugin '{}': {}", plugin_name, e);
|
||||
if let Err(e) = meta_plugin.configure_options(&config.options) {
|
||||
eprintln!("Warning: Failed to configure options for meta plugin '{}': {}", plugin_name, e);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user