refactor: simplify filter plugin signatures by removing boxed parameters

This commit is contained in:
Andrew Phillips
2025-09-12 10:36:09 -03:00
committed by Andrew Phillips (aider)
parent 9c354d5ef4
commit 059bde09e4
10 changed files with 158 additions and 301 deletions

View File

@@ -34,15 +34,14 @@ impl HostnameMetaPlugin {
if let Some(opts) = options {
for (key, value) in opts {
// Convert string "true"/"false" to boolean for hostname option
if key == "hostname" {
if let serde_yaml::Value::String(s) = &value {
if s == "false" {
final_options.insert(key, serde_yaml::Value::Bool(false));
continue;
} else if s == "true" {
final_options.insert(key, serde_yaml::Value::Bool(true));
continue;
}
if key == "hostname"
&& let serde_yaml::Value::String(s) = &value {
if s == "false" {
final_options.insert(key, serde_yaml::Value::Bool(false));
continue;
} else if s == "true" {
final_options.insert(key, serde_yaml::Value::Bool(true));
continue;
}
}
final_options.insert(key, value);
@@ -152,12 +151,11 @@ impl HostnameMetaPlugin {
if let Some(_first_addr) = addrs.first() {
// For local addresses, we might not get a reverse lookup, so try to infer
// from the system's domain name
if let Ok(domain) = std::process::Command::new("domainname").output() {
if domain.status.success() {
let domain_str = String::from_utf8_lossy(&domain.stdout).trim().to_string();
if !domain_str.is_empty() && domain_str != "(none)" {
return format!("{}.{}", short_hostname, domain_str);
}
if let Ok(domain) = std::process::Command::new("domainname").output()
&& domain.status.success() {
let domain_str = String::from_utf8_lossy(&domain.stdout).trim().to_string();
if !domain_str.is_empty() && domain_str != "(none)" {
return format!("{}.{}", short_hostname, domain_str);
}
}
}
@@ -168,12 +166,10 @@ impl HostnameMetaPlugin {
if let Ok(full_hostname) = std::process::Command::new("hostname")
.arg("-f")
.output()
{
if full_hostname.status.success() {
let full_hostname_str = String::from_utf8_lossy(&full_hostname.stdout).trim().to_string();
if !full_hostname_str.is_empty() && full_hostname_str != short_hostname {
return full_hostname_str;
}
&& full_hostname.status.success() {
let full_hostname_str = String::from_utf8_lossy(&full_hostname.stdout).trim().to_string();
if !full_hostname_str.is_empty() && full_hostname_str != short_hostname {
return full_hostname_str;
}
}
@@ -265,32 +261,29 @@ impl MetaPlugin for HostnameMetaPlugin {
let mut metadata = Vec::new();
// Add enabled metadata to the response using process_metadata_outputs
if hostname_enabled {
if let Some(meta_data) = crate::meta_plugin::process_metadata_outputs(
if hostname_enabled
&& let Some(meta_data) = crate::meta_plugin::process_metadata_outputs(
"hostname",
serde_yaml::Value::String(hostname_value.clone()),
&self.outputs
) {
metadata.push(meta_data);
}
metadata.push(meta_data);
}
if hostname_full_enabled {
if let Some(meta_data) = crate::meta_plugin::process_metadata_outputs(
if hostname_full_enabled
&& let Some(meta_data) = crate::meta_plugin::process_metadata_outputs(
"hostname_full",
serde_yaml::Value::String(full_hostname.clone()),
&self.outputs
) {
metadata.push(meta_data);
}
metadata.push(meta_data);
}
if hostname_short_enabled {
if let Some(meta_data) = crate::meta_plugin::process_metadata_outputs(
if hostname_short_enabled
&& let Some(meta_data) = crate::meta_plugin::process_metadata_outputs(
"hostname_short",
serde_yaml::Value::String(short_hostname.clone()),
&self.outputs
) {
metadata.push(meta_data);
}
metadata.push(meta_data);
}
// Update outputs based on enabled status
@@ -364,4 +357,4 @@ fn register_hostname_plugin() {
register_meta_plugin(MetaPluginType::Hostname, |options, outputs| {
Box::new(HostnameMetaPlugin::new(options, outputs))
});
}
}