From 79fdf05d8439d78a88c0dc5391867571b71c611f Mon Sep 17 00:00:00 2001 From: Andrew Phillips Date: Wed, 27 Aug 2025 21:04:52 -0300 Subject: [PATCH] refactor: replace meta_name with MetaPluginType from strum Co-authored-by: aider (openai/andrew/openrouter/deepseek/deepseek-chat-v3.1) --- src/meta_plugin/binary.rs | 4 ++-- src/meta_plugin/command.rs | 8 +++----- src/meta_plugin/cwd.rs | 4 ++-- src/meta_plugin/digest.rs | 4 ++-- src/meta_plugin/hostname.rs | 4 ++-- src/meta_plugin/keep_pid.rs | 4 ++-- src/meta_plugin/magic.rs | 4 ++-- src/meta_plugin/mod.rs | 12 +++++++++--- src/meta_plugin/read_rate.rs | 4 ++-- src/meta_plugin/read_time.rs | 4 ++-- src/meta_plugin/shell.rs | 4 ++-- src/meta_plugin/shell_pid.rs | 4 ++-- src/meta_plugin/text.rs | 4 ++-- src/meta_plugin/user.rs | 4 ++-- 14 files changed, 36 insertions(+), 32 deletions(-) diff --git a/src/meta_plugin/binary.rs b/src/meta_plugin/binary.rs index 1f7e29e..5dd7a53 100644 --- a/src/meta_plugin/binary.rs +++ b/src/meta_plugin/binary.rs @@ -126,8 +126,8 @@ impl MetaPlugin for BinaryMetaPlugin { } } - fn meta_name(&self) -> String { - self.base.meta_name.clone() + fn meta_type(&self) -> MetaPluginType { + MetaPluginType::Binary } fn outputs(&self) -> &std::collections::HashMap { diff --git a/src/meta_plugin/command.rs b/src/meta_plugin/command.rs index c660b79..06cf073 100644 --- a/src/meta_plugin/command.rs +++ b/src/meta_plugin/command.rs @@ -9,7 +9,6 @@ pub struct MetaPluginCommand { pub program: String, pub args: Vec, pub supported: bool, - pub meta_name: String, pub split_whitespace: bool, process: Option, writer: Option>, @@ -67,7 +66,6 @@ impl MetaPluginCommand { 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(), supported, - meta_name, split_whitespace, process: None, writer: None, @@ -158,7 +156,7 @@ impl MetaPlugin for MetaPluginCommand { // Use process_metadata_outputs to handle output mapping if let Some(meta_data) = crate::meta_plugin::process_metadata_outputs( - &self.meta_name, + &self.meta_type().to_string(), serde_yaml::Value::String(result), &self.outputs ) { @@ -192,8 +190,8 @@ impl MetaPlugin for MetaPluginCommand { } } - fn meta_name(&self) -> String { - self.meta_name.clone() + fn meta_type(&self) -> MetaPluginType { + MetaPluginType::Command } fn program_info(&self) -> Option<(&str, Vec<&str>)> { diff --git a/src/meta_plugin/cwd.rs b/src/meta_plugin/cwd.rs index cec2e26..506f6ef 100644 --- a/src/meta_plugin/cwd.rs +++ b/src/meta_plugin/cwd.rs @@ -69,8 +69,8 @@ impl MetaPlugin for CwdMetaPlugin { } } - fn meta_name(&self) -> String { - self.meta_name.clone() + fn meta_type(&self) -> MetaPluginType { + MetaPluginType::Cwd } fn initialize(&mut self) -> crate::meta_plugin::MetaPluginResponse { diff --git a/src/meta_plugin/digest.rs b/src/meta_plugin/digest.rs index bd713ef..1cfde75 100644 --- a/src/meta_plugin/digest.rs +++ b/src/meta_plugin/digest.rs @@ -218,8 +218,8 @@ impl MetaPlugin for DigestMetaPlugin { } } - fn meta_name(&self) -> String { - self.meta_name.clone() + fn meta_type(&self) -> MetaPluginType { + MetaPluginType::Digest } fn outputs(&self) -> &std::collections::HashMap { diff --git a/src/meta_plugin/hostname.rs b/src/meta_plugin/hostname.rs index 9238c98..dc4a40a 100644 --- a/src/meta_plugin/hostname.rs +++ b/src/meta_plugin/hostname.rs @@ -223,8 +223,8 @@ impl MetaPlugin for HostnameMetaPlugin { } } - fn meta_name(&self) -> String { - self.meta_name.clone() + fn meta_type(&self) -> MetaPluginType { + MetaPluginType::Hostname } fn initialize(&mut self) -> crate::meta_plugin::MetaPluginResponse { diff --git a/src/meta_plugin/keep_pid.rs b/src/meta_plugin/keep_pid.rs index 2e8e345..fb9abc8 100644 --- a/src/meta_plugin/keep_pid.rs +++ b/src/meta_plugin/keep_pid.rs @@ -86,8 +86,8 @@ impl MetaPlugin for KeepPidMetaPlugin { } } - fn meta_name(&self) -> String { - self.meta_name.clone() + fn meta_type(&self) -> MetaPluginType { + MetaPluginType::KeepPid } fn initialize(&mut self) -> crate::meta_plugin::MetaPluginResponse { diff --git a/src/meta_plugin/magic.rs b/src/meta_plugin/magic.rs index 2f6b559..48a4201 100644 --- a/src/meta_plugin/magic.rs +++ b/src/meta_plugin/magic.rs @@ -207,8 +207,8 @@ impl MetaPlugin for MagicFileMetaPlugin { } } - fn meta_name(&self) -> String { - "magic_file".to_string() + fn meta_type(&self) -> MetaPluginType { + MetaPluginType::MagicFile } diff --git a/src/meta_plugin/mod.rs b/src/meta_plugin/mod.rs index a8ab7e9..ecc5aa5 100644 --- a/src/meta_plugin/mod.rs +++ b/src/meta_plugin/mod.rs @@ -185,9 +185,15 @@ pub fn process_metadata_outputs(internal_name: &str, value: serde_yaml::Value, o } 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 { true - } fn is_internal(&self) -> bool { 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 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 let mut program_name = String::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; if let Some(opts) = &options { diff --git a/src/meta_plugin/read_rate.rs b/src/meta_plugin/read_rate.rs index edd59fd..d36a2b6 100644 --- a/src/meta_plugin/read_rate.rs +++ b/src/meta_plugin/read_rate.rs @@ -115,8 +115,8 @@ impl MetaPlugin for ReadRateMetaPlugin { } } - fn meta_name(&self) -> String { - self.meta_name.clone() + fn meta_type(&self) -> MetaPluginType { + MetaPluginType::ReadRate } fn outputs(&self) -> &std::collections::HashMap { diff --git a/src/meta_plugin/read_time.rs b/src/meta_plugin/read_time.rs index 6829768..db1e1aa 100644 --- a/src/meta_plugin/read_time.rs +++ b/src/meta_plugin/read_time.rs @@ -108,8 +108,8 @@ impl MetaPlugin for ReadTimeMetaPlugin { } } - fn meta_name(&self) -> String { - self.meta_name.clone() + fn meta_type(&self) -> MetaPluginType { + MetaPluginType::ReadTime } fn outputs(&self) -> &std::collections::HashMap { diff --git a/src/meta_plugin/shell.rs b/src/meta_plugin/shell.rs index cf5f459..c9ba120 100644 --- a/src/meta_plugin/shell.rs +++ b/src/meta_plugin/shell.rs @@ -86,8 +86,8 @@ impl MetaPlugin for ShellMetaPlugin { } } - fn meta_name(&self) -> String { - self.meta_name.clone() + fn meta_type(&self) -> MetaPluginType { + MetaPluginType::Shell } fn initialize(&mut self) -> crate::meta_plugin::MetaPluginResponse { diff --git a/src/meta_plugin/shell_pid.rs b/src/meta_plugin/shell_pid.rs index 9cff819..bd7aaa9 100644 --- a/src/meta_plugin/shell_pid.rs +++ b/src/meta_plugin/shell_pid.rs @@ -87,8 +87,8 @@ impl MetaPlugin for ShellPidMetaPlugin { } } - fn meta_name(&self) -> String { - self.meta_name.clone() + fn meta_type(&self) -> MetaPluginType { + MetaPluginType::ShellPid } fn initialize(&mut self) -> crate::meta_plugin::MetaPluginResponse { diff --git a/src/meta_plugin/text.rs b/src/meta_plugin/text.rs index cfe4042..744b911 100644 --- a/src/meta_plugin/text.rs +++ b/src/meta_plugin/text.rs @@ -583,8 +583,8 @@ impl MetaPlugin for TextMetaPlugin { } } - fn meta_name(&self) -> String { - self.base.meta_name.clone() + fn meta_type(&self) -> MetaPluginType { + MetaPluginType::Text } fn outputs(&self) -> &std::collections::HashMap { diff --git a/src/meta_plugin/user.rs b/src/meta_plugin/user.rs index 7ef4390..ce00feb 100644 --- a/src/meta_plugin/user.rs +++ b/src/meta_plugin/user.rs @@ -71,8 +71,8 @@ impl MetaPlugin for UserMetaPlugin { } } - fn meta_name(&self) -> String { - self.base.meta_name.clone() + fn meta_type(&self) -> MetaPluginType { + MetaPluginType::User } fn outputs(&self) -> &std::collections::HashMap {