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:
Andrew Phillips
2025-08-19 13:17:27 -03:00
parent 38cbf06579
commit 2b79c6380f
4 changed files with 19 additions and 23 deletions

View File

@@ -109,16 +109,16 @@ pub trait MetaPlugin {
output_metadata(conn, item_id, internal_name, value, self.outputs()) output_metadata(conn, item_id, internal_name, value, self.outputs())
} }
// Configure plugin with options and outputs // Configure plugin with options (excluding outputs)
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(outputs) = options.get("outputs") { // Default implementation does nothing - plugins can override this
if let Some(outputs_map) = outputs.as_mapping() { Ok(())
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 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(()) Ok(())
} }

View File

@@ -83,15 +83,13 @@ impl MetaPlugin for BinaryMetaPlugin {
Ok(()) 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(max_buffer_size) = options.get("max_buffer_size") {
if let Some(size) = max_buffer_size.as_u64() { if let Some(size) = max_buffer_size.as_u64() {
self.max_buffer_size = size as usize; self.max_buffer_size = size as usize;
} }
} }
Ok(())
// Call default implementation for outputs
MetaPlugin::configure(self, options)
} }
fn outputs(&self) -> &std::collections::HashMap<String, serde_yaml::Value> { fn outputs(&self) -> &std::collections::HashMap<String, serde_yaml::Value> {

View File

@@ -129,15 +129,13 @@ impl MetaPlugin for MagicFileMetaPlugin {
"magic_file".to_string() "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(max_buffer_size) = options.get("max_buffer_size") {
if let Some(size) = max_buffer_size.as_u64() { if let Some(size) = max_buffer_size.as_u64() {
self.max_buffer_size = size as usize; self.max_buffer_size = size as usize;
} }
} }
Ok(())
// Call default implementation for outputs
MetaPlugin::configure(self, options)
} }
fn outputs(&self) -> &std::collections::HashMap<String, serde_yaml::Value> { fn outputs(&self) -> &std::collections::HashMap<String, serde_yaml::Value> {

View File

@@ -47,14 +47,14 @@ fn setup_compression_and_plugins(
for meta_plugin in meta_plugins.iter_mut() { for meta_plugin in meta_plugins.iter_mut() {
let plugin_name = meta_plugin.meta_name(); let plugin_name = meta_plugin.meta_name();
if let Some(config) = meta_plugin_configs.iter().find(|c| c.name == plugin_name) { if let Some(config) = meta_plugin_configs.iter().find(|c| c.name == plugin_name) {
// Set outputs first // Configure outputs first
for (key, value) in &config.outputs { if let Err(e) = meta_plugin.configure_outputs(&config.outputs.iter().map(|(k, v)| (k.clone(), serde_yaml::Value::String(v.clone()))).collect()) {
meta_plugin.outputs_mut().insert(key.clone(), serde_yaml::Value::String(value.clone())); eprintln!("Warning: Failed to configure outputs for meta plugin '{}': {}", plugin_name, e);
} }
// Then configure with options // Then configure with options
if let Err(e) = meta_plugin.configure(&config.options) { if let Err(e) = meta_plugin.configure_options(&config.options) {
eprintln!("Warning: Failed to configure meta plugin '{}': {}", plugin_name, e); eprintln!("Warning: Failed to configure options for meta plugin '{}': {}", plugin_name, e);
} }
} }
} }