refactor: replace meta_name with MetaPluginType from strum

Co-authored-by: aider (openai/andrew/openrouter/deepseek/deepseek-chat-v3.1) <aider@aider.chat>
This commit is contained in:
Andrew Phillips
2025-08-27 21:04:52 -03:00
parent 892a3f24a5
commit 79fdf05d84
14 changed files with 36 additions and 32 deletions

View File

@@ -126,8 +126,8 @@ impl MetaPlugin for BinaryMetaPlugin {
} }
} }
fn meta_name(&self) -> String { fn meta_type(&self) -> MetaPluginType {
self.base.meta_name.clone() MetaPluginType::Binary
} }
fn outputs(&self) -> &std::collections::HashMap<String, serde_yaml::Value> { fn outputs(&self) -> &std::collections::HashMap<String, serde_yaml::Value> {

View File

@@ -9,7 +9,6 @@ pub struct MetaPluginCommand {
pub program: String, pub program: String,
pub args: Vec<String>, pub args: Vec<String>,
pub supported: bool, pub supported: bool,
pub meta_name: String,
pub split_whitespace: bool, pub split_whitespace: bool,
process: Option<Child>, process: Option<Child>,
writer: Option<Box<dyn Write>>, writer: Option<Box<dyn Write>>,
@@ -67,7 +66,6 @@ impl MetaPluginCommand {
program: program_path.map_or_else(|_| program.to_string(), |p| p.to_string_lossy().to_string()), program: program_path.map_or_else(|_| program.to_string(), |p| p.to_string_lossy().to_string()),
args: args.iter().map(|s| s.to_string()).collect(), args: args.iter().map(|s| s.to_string()).collect(),
supported, supported,
meta_name,
split_whitespace, split_whitespace,
process: None, process: None,
writer: None, writer: None,
@@ -158,7 +156,7 @@ impl MetaPlugin for MetaPluginCommand {
// Use process_metadata_outputs to handle output mapping // Use process_metadata_outputs to handle output mapping
if let Some(meta_data) = crate::meta_plugin::process_metadata_outputs( if let Some(meta_data) = crate::meta_plugin::process_metadata_outputs(
&self.meta_name, &self.meta_type().to_string(),
serde_yaml::Value::String(result), serde_yaml::Value::String(result),
&self.outputs &self.outputs
) { ) {
@@ -192,8 +190,8 @@ impl MetaPlugin for MetaPluginCommand {
} }
} }
fn meta_name(&self) -> String { fn meta_type(&self) -> MetaPluginType {
self.meta_name.clone() MetaPluginType::Command
} }
fn program_info(&self) -> Option<(&str, Vec<&str>)> { fn program_info(&self) -> Option<(&str, Vec<&str>)> {

View File

@@ -69,8 +69,8 @@ impl MetaPlugin for CwdMetaPlugin {
} }
} }
fn meta_name(&self) -> String { fn meta_type(&self) -> MetaPluginType {
self.meta_name.clone() MetaPluginType::Cwd
} }
fn initialize(&mut self) -> crate::meta_plugin::MetaPluginResponse { fn initialize(&mut self) -> crate::meta_plugin::MetaPluginResponse {

View File

@@ -218,8 +218,8 @@ impl MetaPlugin for DigestMetaPlugin {
} }
} }
fn meta_name(&self) -> String { fn meta_type(&self) -> MetaPluginType {
self.meta_name.clone() MetaPluginType::Digest
} }
fn outputs(&self) -> &std::collections::HashMap<String, serde_yaml::Value> { fn outputs(&self) -> &std::collections::HashMap<String, serde_yaml::Value> {

View File

@@ -223,8 +223,8 @@ impl MetaPlugin for HostnameMetaPlugin {
} }
} }
fn meta_name(&self) -> String { fn meta_type(&self) -> MetaPluginType {
self.meta_name.clone() MetaPluginType::Hostname
} }
fn initialize(&mut self) -> crate::meta_plugin::MetaPluginResponse { fn initialize(&mut self) -> crate::meta_plugin::MetaPluginResponse {

View File

@@ -86,8 +86,8 @@ impl MetaPlugin for KeepPidMetaPlugin {
} }
} }
fn meta_name(&self) -> String { fn meta_type(&self) -> MetaPluginType {
self.meta_name.clone() MetaPluginType::KeepPid
} }
fn initialize(&mut self) -> crate::meta_plugin::MetaPluginResponse { fn initialize(&mut self) -> crate::meta_plugin::MetaPluginResponse {

View File

@@ -207,8 +207,8 @@ impl MetaPlugin for MagicFileMetaPlugin {
} }
} }
fn meta_name(&self) -> String { fn meta_type(&self) -> MetaPluginType {
"magic_file".to_string() MetaPluginType::MagicFile
} }

View File

@@ -185,9 +185,15 @@ pub fn process_metadata_outputs(internal_name: &str, value: serde_yaml::Value, o
} }
pub trait MetaPlugin where Self: 'static { pub trait MetaPlugin where Self: 'static {
fn meta_type(&self) -> MetaPluginType;
// For backward compatibility, provide meta_name() that uses meta_type()
fn meta_name(&self) -> String {
self.meta_type().to_string()
}
fn is_supported(&self) -> bool { fn is_supported(&self) -> bool {
true true
}
fn is_internal(&self) -> bool { fn is_internal(&self) -> bool {
true true
@@ -218,7 +224,7 @@ pub trait MetaPlugin where Self: 'static {
} }
} }
fn meta_name(&self) -> String; fn meta_type(&self) -> MetaPluginType;
// Get program information for display in status // Get program information for display in status
fn program_info(&self) -> Option<(&str, Vec<&str>)> { fn program_info(&self) -> Option<(&str, Vec<&str>)> {
@@ -294,7 +300,7 @@ pub fn get_meta_plugin(
// For command type, we need to parse the command from options // For command type, we need to parse the command from options
let mut program_name = String::new(); let mut program_name = String::new();
let mut args = Vec::new(); let mut args = Vec::new();
let mut meta_name = "command".to_string(); let meta_name = MetaPluginType::Command.to_string();
let mut split_whitespace = true; let mut split_whitespace = true;
if let Some(opts) = &options { if let Some(opts) = &options {

View File

@@ -115,8 +115,8 @@ impl MetaPlugin for ReadRateMetaPlugin {
} }
} }
fn meta_name(&self) -> String { fn meta_type(&self) -> MetaPluginType {
self.meta_name.clone() MetaPluginType::ReadRate
} }
fn outputs(&self) -> &std::collections::HashMap<String, serde_yaml::Value> { fn outputs(&self) -> &std::collections::HashMap<String, serde_yaml::Value> {

View File

@@ -108,8 +108,8 @@ impl MetaPlugin for ReadTimeMetaPlugin {
} }
} }
fn meta_name(&self) -> String { fn meta_type(&self) -> MetaPluginType {
self.meta_name.clone() MetaPluginType::ReadTime
} }
fn outputs(&self) -> &std::collections::HashMap<String, serde_yaml::Value> { fn outputs(&self) -> &std::collections::HashMap<String, serde_yaml::Value> {

View File

@@ -86,8 +86,8 @@ impl MetaPlugin for ShellMetaPlugin {
} }
} }
fn meta_name(&self) -> String { fn meta_type(&self) -> MetaPluginType {
self.meta_name.clone() MetaPluginType::Shell
} }
fn initialize(&mut self) -> crate::meta_plugin::MetaPluginResponse { fn initialize(&mut self) -> crate::meta_plugin::MetaPluginResponse {

View File

@@ -87,8 +87,8 @@ impl MetaPlugin for ShellPidMetaPlugin {
} }
} }
fn meta_name(&self) -> String { fn meta_type(&self) -> MetaPluginType {
self.meta_name.clone() MetaPluginType::ShellPid
} }
fn initialize(&mut self) -> crate::meta_plugin::MetaPluginResponse { fn initialize(&mut self) -> crate::meta_plugin::MetaPluginResponse {

View File

@@ -583,8 +583,8 @@ impl MetaPlugin for TextMetaPlugin {
} }
} }
fn meta_name(&self) -> String { fn meta_type(&self) -> MetaPluginType {
self.base.meta_name.clone() MetaPluginType::Text
} }
fn outputs(&self) -> &std::collections::HashMap<String, serde_yaml::Value> { fn outputs(&self) -> &std::collections::HashMap<String, serde_yaml::Value> {

View File

@@ -71,8 +71,8 @@ impl MetaPlugin for UserMetaPlugin {
} }
} }
fn meta_name(&self) -> String { fn meta_type(&self) -> MetaPluginType {
self.base.meta_name.clone() MetaPluginType::User
} }
fn outputs(&self) -> &std::collections::HashMap<String, serde_yaml::Value> { fn outputs(&self) -> &std::collections::HashMap<String, serde_yaml::Value> {