refactor: compose BaseMetaPlugin in remaining meta plugins
Co-authored-by: aider (openai/andrew/openrouter/sonoma-sky-alpha) <aider@aider.chat>
This commit is contained in:
@@ -1,10 +1,10 @@
|
||||
use super::{MetaPlugin, MetaPluginType, process_metadata_outputs};
|
||||
use super::{MetaPlugin, MetaPluginType, process_metadata_outputs, BaseMetaPlugin};
|
||||
|
||||
#[derive(Debug, Clone)]
|
||||
/// Meta plugin that extracts environment variables prefixed with KEEP_META_ as metadata.
|
||||
pub struct EnvMetaPlugin {
|
||||
is_finalized: bool,
|
||||
outputs: std::collections::HashMap<String, serde_yaml::Value>,
|
||||
base: BaseMetaPlugin,
|
||||
env_vars: Vec<(String, String)>,
|
||||
}
|
||||
|
||||
@@ -48,9 +48,12 @@ impl EnvMetaPlugin {
|
||||
}
|
||||
}
|
||||
|
||||
let mut base = BaseMetaPlugin::new();
|
||||
base.outputs = outputs_map;
|
||||
|
||||
EnvMetaPlugin {
|
||||
is_finalized: false,
|
||||
outputs: outputs_map,
|
||||
base,
|
||||
env_vars,
|
||||
}
|
||||
}
|
||||
@@ -106,7 +109,7 @@ impl MetaPlugin for EnvMetaPlugin {
|
||||
if let Some(meta_data) = process_metadata_outputs(
|
||||
name,
|
||||
serde_yaml::Value::String(value.clone()),
|
||||
&self.outputs
|
||||
self.base.outputs()
|
||||
) {
|
||||
metadata.push(meta_data);
|
||||
}
|
||||
@@ -172,7 +175,7 @@ impl MetaPlugin for EnvMetaPlugin {
|
||||
///
|
||||
/// A reference to the `HashMap` of outputs.
|
||||
fn outputs(&self) -> &std::collections::HashMap<String, serde_yaml::Value> {
|
||||
&self.outputs
|
||||
self.base.outputs()
|
||||
}
|
||||
|
||||
/// Returns a mutable reference to the outputs mapping.
|
||||
@@ -181,7 +184,7 @@ impl MetaPlugin for EnvMetaPlugin {
|
||||
///
|
||||
/// A mutable reference to the `HashMap` of outputs.
|
||||
fn outputs_mut(&mut self) -> &mut std::collections::HashMap<String, serde_yaml::Value> {
|
||||
&mut self.outputs
|
||||
self.base.outputs_mut()
|
||||
}
|
||||
|
||||
/// Returns the default output names based on collected env vars.
|
||||
@@ -203,10 +206,7 @@ impl MetaPlugin for EnvMetaPlugin {
|
||||
///
|
||||
/// An empty `HashMap`.
|
||||
fn options(&self) -> &std::collections::HashMap<String, serde_yaml::Value> {
|
||||
use once_cell::sync::Lazy;
|
||||
static EMPTY: Lazy<std::collections::HashMap<String, serde_yaml::Value>> =
|
||||
Lazy::new(std::collections::HashMap::new);
|
||||
&EMPTY
|
||||
self.base.options()
|
||||
}
|
||||
|
||||
/// Returns a mutable reference to the options mapping.
|
||||
@@ -215,7 +215,7 @@ impl MetaPlugin for EnvMetaPlugin {
|
||||
///
|
||||
/// Panics with "options_mut() not implemented for EnvMetaPlugin".
|
||||
fn options_mut(&mut self) -> &mut std::collections::HashMap<String, serde_yaml::Value> {
|
||||
panic!("options_mut() not implemented for EnvMetaPlugin")
|
||||
self.base.options_mut()
|
||||
}
|
||||
}
|
||||
use crate::meta_plugin::register_meta_plugin;
|
||||
@@ -226,4 +226,4 @@ fn register_env_plugin() {
|
||||
register_meta_plugin(MetaPluginType::Env, |options, outputs| {
|
||||
Box::new(EnvMetaPlugin::new(options, outputs))
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user