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

@@ -53,8 +53,8 @@ impl GrepFilter {
///
/// # Arguments
///
/// * `reader` - A boxed mutable reference to the input reader providing the data stream.
/// * `writer` - A boxed mutable reference to the output writer where matching lines are sent.
/// * `reader` - Mutable reference to the input data stream.
/// * `writer` - Mutable reference to the output writer where matching lines are sent.
///
/// # Returns
///
@@ -67,33 +67,33 @@ impl GrepFilter {
/// # Examples
///
/// ```
/// filter.filter(Box::new(&mut input), Box::new(&mut output))?;
/// filter.filter(&mut input, &mut output)?;
/// ```
impl FilterPlugin for GrepFilter {
fn filter(&mut self, mut reader: Box<&mut dyn Read>, mut writer: Box<&mut dyn Write>) -> Result<()> {
let mut buf_reader = std::io::BufReader::new(&mut *reader);
fn filter(&mut self, reader: &mut dyn Read, writer: &mut dyn Write) -> Result<()> {
let mut buf_reader = std::io::BufReader::new(reader);
for line in buf_reader.by_ref().lines() {
let line = line?;
if self.regex.is_match(&line) {
writeln!(&mut *writer, "{}", line)?;
writeln!(writer, "{}", line)?;
}
}
Ok(())
}
/// Clones this filter into a new boxed instance.
///
/// Creates a new GrepFilter with the same regex pattern.
///
/// # Returns
///
/// A new `Box<dyn FilterPlugin>` representing a clone of this filter.
///
/// # Examples
///
/// ```
/// let cloned = filter.clone_box();
/// ```
///
/// Creates a new GrepFilter with the same regex pattern.
///
/// # Returns
///
/// A new `Box<dyn FilterPlugin>` representing a clone of this filter.
///
/// # Examples
///
/// ```
/// let cloned = filter.clone_box();
/// ```
fn clone_box(&self) -> Box<dyn FilterPlugin> {
Box::new(Self {
regex: self.regex.clone(),
@@ -101,20 +101,20 @@ impl FilterPlugin for GrepFilter {
}
/// Returns the configuration options for this filter.
///
/// The only option is the required "pattern" for the regex.
///
/// # Returns
///
/// A vector containing one `FilterOption` for "pattern" (required, no default).
///
/// # Examples
///
/// ```
/// let opts = filter.options();
/// assert_eq!(opts.len(), 1);
/// assert!(opts[0].required);
/// ```
///
/// The only option is the required "pattern" for the regex.
///
/// # Returns
///
/// A vector containing one `FilterOption` for "pattern" (required, no default).
///
/// # Examples
///
/// ```
/// let opts = filter.options();
/// assert_eq!(opts.len(), 1);
/// assert!(opts[0].required);
/// ```
fn options(&self) -> Vec<FilterOption> {
vec![
FilterOption {

View File

@@ -3,7 +3,6 @@ use std::io::{Result, Read, Write, BufRead};
use crate::common::PIPESIZE;
use crate::services::filter_service::register_filter_plugin;
/// A filter that reads the first N bytes from the input stream.
/// A filter that reads the first N bytes from the input stream.
///
/// Limits the output to the initial bytes specified in the configuration.
@@ -55,8 +54,8 @@ impl HeadBytesFilter {
///
/// # Arguments
///
/// * `reader` - Boxed mutable reference to the input data stream.
/// * `writer` - Boxed mutable reference to the output stream.
/// * `reader` - Mutable reference to the input data stream.
/// * `writer` - Mutable reference to the output stream.
///
/// # Returns
///
@@ -73,7 +72,7 @@ impl HeadBytesFilter {
/// // Input "Hello World" becomes "Hello"
/// ```
impl FilterPlugin for HeadBytesFilter {
fn filter(&mut self, mut reader: Box<&mut dyn Read>, mut writer: Box<&mut dyn Write>) -> Result<()> {
fn filter(&mut self, reader: &mut dyn Read, writer: &mut dyn Write) -> Result<()> {
if self.remaining == 0 {
return Ok(());
}
@@ -81,11 +80,11 @@ impl FilterPlugin for HeadBytesFilter {
let mut buffer = vec![0; PIPESIZE];
while self.remaining > 0 {
let to_read = std::cmp::min(self.remaining, PIPESIZE);
let bytes_read = (&mut *reader).read(&mut buffer[..to_read])?;
let bytes_read = reader.read(&mut buffer[..to_read])?;
if bytes_read == 0 {
break;
}
(&mut *writer).write_all(&buffer[..bytes_read])?;
writer.write_all(&buffer[..bytes_read])?;
self.remaining -= bytes_read;
}
Ok(())
@@ -123,14 +122,6 @@ impl FilterPlugin for HeadBytesFilter {
}
/// A filter that reads the first N lines from the input stream.
/// A filter that reads the first N lines from the input stream.
///
/// Limits output to the initial lines specified, writing each full line to output.
/// Handles line endings properly using buffered reading.
///
/// # Fields
///
/// * `remaining` - Number of lines left to read before stopping.
pub struct HeadLinesFilter {
remaining: usize,
}
@@ -173,8 +164,8 @@ impl HeadLinesFilter {
///
/// # Arguments
///
/// * `reader` - Boxed mutable reference to the input data stream.
/// * `writer` - Boxed mutable reference to the output stream.
/// * `reader` - Mutable reference to the input data stream.
/// * `writer` - Mutable reference to the output stream.
///
/// # Returns
///
@@ -191,15 +182,15 @@ impl HeadLinesFilter {
/// // Input "Line1\nLine2\nLine3" becomes "Line1\nLine2\n"
/// ```
impl FilterPlugin for HeadLinesFilter {
fn filter(&mut self, mut reader: Box<&mut dyn Read>, mut writer: Box<&mut dyn Write>) -> Result<()> {
fn filter(&mut self, reader: &mut dyn Read, writer: &mut dyn Write) -> Result<()> {
if self.remaining == 0 {
return Ok(());
}
let mut buf_reader = std::io::BufReader::new(&mut *reader);
let mut buf_reader = std::io::BufReader::new(reader);
for line in buf_reader.by_ref().lines() {
let line = line?;
writeln!(&mut *writer, "{}", line)?;
writeln!(writer, "{}", line)?;
self.remaining -= 1;
if self.remaining == 0 {
break;

View File

@@ -19,36 +19,6 @@ impl SkipBytesFilter {
remaining: count,
}
}
/// Creates a new instance from options.
///
/// # Arguments
///
/// * `options` - An optional JSON value containing configuration options for the filter.
///
/// # Returns
///
/// A `Result` containing a boxed `FilterPlugin` on success, or an `io::Error` if options are invalid.
pub fn create(options: Option<serde_json::Value>) -> Result<Box<dyn FilterPlugin>> {
let options = options.ok_or_else(|| {
std::io::Error::new(
std::io::ErrorKind::InvalidInput,
"skip_bytes filter requires options"
)
})?;
let count = options.get("n")
.and_then(|v| v.as_u64())
.map(|n| n as usize)
.ok_or_else(|| {
std::io::Error::new(
std::io::ErrorKind::InvalidInput,
"skip_bytes filter requires 'n' parameter"
)
})?;
Ok(Box::new(Self::new(count)))
}
}
impl FilterPlugin for SkipBytesFilter {
@@ -56,19 +26,19 @@ impl FilterPlugin for SkipBytesFilter {
///
/// # Arguments
///
/// * `reader` - A boxed mutable reference to the input reader providing the data stream.
/// * `writer` - A boxed mutable reference to the output writer where filtered data is sent.
/// * `reader` - Mutable reference to the input reader providing the data stream.
/// * `writer` - Mutable reference to the output writer where filtered data is sent.
///
/// # Returns
///
/// Returns `Ok(())` on success, or an `io::Error` if reading or writing fails.
fn filter(&mut self, mut reader: Box<&mut dyn Read>, mut writer: Box<&mut dyn Write>) -> Result<()> {
fn filter(&mut self, reader: &mut dyn Read, writer: &mut dyn Write) -> Result<()> {
// Skip bytes in chunks
if self.remaining > 0 {
let mut buffer = vec![0; PIPESIZE];
while self.remaining > 0 {
let to_read = std::cmp::min(self.remaining, PIPESIZE);
let bytes_read = (&mut *reader).read(&mut buffer[..to_read])?;
let bytes_read = reader.read(&mut buffer[..to_read])?;
if bytes_read == 0 {
break;
}
@@ -77,7 +47,7 @@ impl FilterPlugin for SkipBytesFilter {
}
// Copy the remaining data using io::copy for efficiency
std::io::copy(&mut *reader, &mut *writer)?;
std::io::copy(reader, writer)?;
Ok(())
}
@@ -124,36 +94,6 @@ impl SkipLinesFilter {
remaining: count,
}
}
/// Creates a new instance from options.
///
/// # Arguments
///
/// * `options` - An optional JSON value containing configuration options for the filter.
///
/// # Returns
///
/// A `Result` containing a boxed `FilterPlugin` on success, or an `io::Error` if options are invalid.
pub fn create(options: Option<serde_json::Value>) -> Result<Box<dyn FilterPlugin>> {
let options = options.ok_or_else(|| {
std::io::Error::new(
std::io::ErrorKind::InvalidInput,
"skip_lines filter requires options"
)
})?;
let count = options.get("n")
.and_then(|v| v.as_u64())
.map(|n| n as usize)
.ok_or_else(|| {
std::io::Error::new(
std::io::ErrorKind::InvalidInput,
"skip_lines filter requires 'n' parameter"
)
})?;
Ok(Box::new(Self::new(count)))
}
}
impl FilterPlugin for SkipLinesFilter {
@@ -161,20 +101,20 @@ impl FilterPlugin for SkipLinesFilter {
///
/// # Arguments
///
/// * `reader` - A boxed mutable reference to the input reader providing the data stream.
/// * `writer` - A boxed mutable reference to the output writer where filtered data is sent.
/// * `reader` - Mutable reference to the input reader providing the data stream.
/// * `writer` - Mutable reference to the output writer where filtered data is sent.
///
/// # Returns
///
/// Returns `Ok(())` on success, or an `io::Error` if reading or writing fails.
fn filter(&mut self, mut reader: Box<&mut dyn Read>, mut writer: Box<&mut dyn Write>) -> Result<()> {
let mut buf_reader = std::io::BufReader::new(&mut *reader);
fn filter(&mut self, reader: &mut dyn Read, writer: &mut dyn Write) -> Result<()> {
let mut buf_reader = std::io::BufReader::new(reader);
for line in buf_reader.by_ref().lines() {
let line = line?;
if self.remaining > 0 {
self.remaining -= 1;
} else {
writeln!(&mut *writer, "{}", line)?;
writeln!(writer, "{}", line)?;
}
}
Ok(())

View File

@@ -3,6 +3,11 @@ use strip_ansi_escapes::Writer;
use super::{FilterPlugin, FilterOption};
/// A filter that removes ANSI escape sequences from the input.
///
/// # Fields
///
/// None, stateless filter.
#[derive(Default)]
pub struct StripAnsiFilter;
impl StripAnsiFilter {
@@ -21,16 +26,17 @@ impl FilterPlugin for StripAnsiFilter {
///
/// # Arguments
///
/// * `reader` - A boxed mutable reference to the input reader providing the data stream with potential ANSI codes.
/// * `writer` - A boxed mutable reference to the output writer where plain text is sent.
/// * `reader` - Mutable reference to the input reader providing the data stream with potential ANSI codes.
/// * `writer` - Mutable reference to the output writer where plain text is sent.
///
/// # Returns
///
/// Returns `Ok(())` on success, or an `io::Error` if reading or writing fails.
fn filter(&mut self, mut reader: Box<&mut dyn Read>, mut writer: Box<&mut dyn Write>) -> Result<()> {
let mut ansi_writer = Writer::new(&mut *writer);
std::io::copy(&mut *reader, &mut ansi_writer)?;
ansi_writer.flush()
fn filter(&mut self, reader: &mut dyn Read, writer: &mut dyn Write) -> Result<()> {
let mut ansi_writer = Writer::new(writer);
std::io::copy(reader, &mut ansi_writer)?;
ansi_writer.flush()?;
Ok(())
}
/// Clones this filter into a new boxed instance.

View File

@@ -22,36 +22,6 @@ impl TailBytesFilter {
count,
}
}
/// Creates a new instance from options.
///
/// # Arguments
///
/// * `options` - An optional JSON value containing configuration options for the filter.
///
/// # Returns
///
/// A `Result` containing a boxed `FilterPlugin` on success, or an `io::Error` if options are invalid.
pub fn create(options: Option<serde_json::Value>) -> Result<Box<dyn FilterPlugin>> {
let options = options.ok_or_else(|| {
std::io::Error::new(
std::io::ErrorKind::InvalidInput,
"tail_bytes filter requires options"
)
})?;
let count = options.get("n")
.and_then(|v| v.as_u64())
.map(|n| n as usize)
.ok_or_else(|| {
std::io::Error::new(
std::io::ErrorKind::InvalidInput,
"tail_bytes filter requires 'n' parameter"
)
})?;
Ok(Box::new(Self::new(count)))
}
}
impl FilterPlugin for TailBytesFilter {
@@ -59,16 +29,16 @@ impl FilterPlugin for TailBytesFilter {
///
/// # Arguments
///
/// * `reader` - A boxed mutable reference to the input reader providing the data stream.
/// * `writer` - A boxed mutable reference to the output writer where filtered data is sent.
/// * `reader` - Mutable reference to the input reader providing the data stream.
/// * `writer` - Mutable reference to the output writer where filtered data is sent.
///
/// # Returns
///
/// Returns `Ok(())` on success, or an `io::Error` if reading or writing fails.
fn filter(&mut self, mut reader: Box<&mut dyn Read>, mut writer: Box<&mut dyn Write>) -> Result<()> {
fn filter(&mut self, reader: &mut dyn Read, writer: &mut dyn Write) -> Result<()> {
let mut temp_buffer = vec![0; PIPESIZE];
loop {
let bytes_read = (&mut *reader).read(&mut temp_buffer)?;
let bytes_read = reader.read(&mut temp_buffer)?;
if bytes_read == 0 {
break;
}
@@ -84,7 +54,7 @@ impl FilterPlugin for TailBytesFilter {
// Write the buffered data at the end
let result: Vec<u8> = self.buffer.iter().cloned().collect();
(&mut *writer).write_all(&result)?;
writer.write_all(&result)?;
Ok(())
}
@@ -134,36 +104,6 @@ impl TailLinesFilter {
count,
}
}
/// Creates a new instance from options.
///
/// # Arguments
///
/// * `options` - An optional JSON value containing configuration options for the filter.
///
/// # Returns
///
/// A `Result` containing a boxed `FilterPlugin` on success, or an `io::Error` if options are invalid.
pub fn create(options: Option<serde_json::Value>) -> Result<Box<dyn FilterPlugin>> {
let options = options.ok_or_else(|| {
std::io::Error::new(
std::io::ErrorKind::InvalidInput,
"tail_lines filter requires options"
)
})?;
let count = options.get("n")
.and_then(|v| v.as_u64())
.map(|n| n as usize)
.ok_or_else(|| {
std::io::Error::new(
std::io::ErrorKind::InvalidInput,
"tail_lines filter requires 'n' parameter"
)
})?;
Ok(Box::new(Self::new(count)))
}
}
impl FilterPlugin for TailLinesFilter {
@@ -171,14 +111,14 @@ impl FilterPlugin for TailLinesFilter {
///
/// # Arguments
///
/// * `reader` - A boxed mutable reference to the input reader providing the data stream.
/// * `writer` - A boxed mutable reference to the output writer where filtered data is sent.
/// * `reader` - Mutable reference to the input reader providing the data stream.
/// * `writer` - Mutable reference to the output writer where filtered data is sent.
///
/// # Returns
///
/// Returns `Ok(())` on success, or an `io::Error` if reading or writing fails.
fn filter(&mut self, mut reader: Box<&mut dyn Read>, mut writer: Box<&mut dyn Write>) -> Result<()> {
let mut buf_reader = std::io::BufReader::new(&mut *reader);
fn filter(&mut self, reader: &mut dyn Read, writer: &mut dyn Write) -> Result<()> {
let mut buf_reader = std::io::BufReader::new(reader);
for line in buf_reader.by_ref().lines() {
let line = line?;
if self.lines.len() == self.count {
@@ -189,7 +129,7 @@ impl FilterPlugin for TailLinesFilter {
// Write the buffered lines
for line in &self.lines {
writeln!(&mut *writer, "{}", line)?;
writeln!(writer, "{}", line)?;
}
Ok(())
}

View File

@@ -5,17 +5,23 @@ use std::io::Write;
#[derive(Clone)]
enum Hasher {
Md5(md5::Context),
Sha256(Sha256),
Md5(md5::Context),
Sha512(Sha512),
}
impl Default for Hasher {
fn default() -> Self {
Hasher::Sha256(Sha256::default())
}
}
// Manual Debug implementation to avoid md5::Context not implementing Debug
impl std::fmt::Debug for Hasher {
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
match self {
Hasher::Md5(_) => write!(f, "Hasher::Md5"),
Hasher::Sha256(_) => write!(f, "Hasher::Sha256"),
Hasher::Md5(_) => write!(f, "Hasher::Md5"),
Hasher::Sha512(_) => write!(f, "Hasher::Sha512"),
}
}
@@ -24,24 +30,24 @@ impl std::fmt::Debug for Hasher {
impl Hasher {
fn update(&mut self, data: &[u8]) {
match self {
Hasher::Sha256(hasher) => hasher.update(data),
Hasher::Md5(hasher) => {
let _ = hasher.write(data);
},
Hasher::Sha256(hasher) => hasher.update(data),
Hasher::Sha512(hasher) => hasher.update(data),
}
}
fn finalize(&mut self) -> String {
match self {
Hasher::Md5(hasher) => {
let result = hasher.clone().compute();
format!("{:x}", result)
}
Hasher::Sha256(hasher) => {
let result = std::mem::replace(hasher, Sha256::new()).finalize_reset();
format!("{:x}", result)
}
Hasher::Md5(hasher) => {
let result = hasher.clone().compute();
format!("{:x}", result)
}
Hasher::Sha512(hasher) => {
let result = std::mem::replace(hasher, Sha512::new()).finalize_reset();
format!("{:x}", result)
@@ -51,14 +57,14 @@ impl Hasher {
fn output_name(&self) -> &'static str {
match self {
Hasher::Md5(_) => "digest_md5",
Hasher::Sha256(_) => "digest_sha256",
Hasher::Md5(_) => "digest_md5",
Hasher::Sha512(_) => "digest_sha512",
}
}
}
#[derive(Debug, Clone)]
#[derive(Debug, Default)]
pub struct DigestMetaPlugin {
hasher: Option<Hasher>,
is_finalized: bool,
@@ -66,17 +72,6 @@ pub struct DigestMetaPlugin {
options: std::collections::HashMap<String, serde_yaml::Value>,
}
impl Default for DigestMetaPlugin {
fn default() -> Self {
Self {
hasher: None,
is_finalized: false,
outputs: std::collections::HashMap::new(),
options: std::collections::HashMap::new(),
}
}
}
impl DigestMetaPlugin {
pub fn new(
@@ -119,7 +114,7 @@ impl DigestMetaPlugin {
// Add the method to options so it shows up in the status
plugin.options.insert("method".to_string(), serde_yaml::Value::String(method.to_string()));
// Set outputs based on the selected method
// Set outputs based on the selected hash method
// Only the selected method's output should be enabled, others should be None
let all_outputs = vec!["digest_md5", "digest_sha256", "digest_sha512"];
for output_name in all_outputs {
@@ -134,13 +129,12 @@ impl DigestMetaPlugin {
if let Some(outs) = outputs {
for (key, value) in outs {
// Only update if the output is not disabled (not None)
if let Some(current_value) = plugin.outputs.get_mut(&key) {
if !current_value.is_null() {
if let Some(current_value) = plugin.outputs.get_mut(&key)
&& !current_value.is_null() {
*current_value = value;
}
}
}
}
plugin
}

View File

@@ -205,7 +205,7 @@ impl MetaPlugin for EnvMetaPlugin {
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());
Lazy::new(std::collections::HashMap::new);
&EMPTY
}

View File

@@ -278,11 +278,10 @@ impl MetaPlugin for MetaPluginExec {
///
/// * `MetaPluginResponse` - Empty metadata, not finalized.
fn update(&mut self, data: &[u8]) -> MetaPluginResponse {
if let Some(ref mut writer) = self.writer {
if let Err(e) = writer.write_all(data) {
if let Some(ref mut writer) = self.writer
&& let Err(e) = writer.write_all(data) {
debug!("META: Failed to write to process stdin: {}", e);
}
}
MetaPluginResponse {
metadata: Vec::new(),
is_finalized: false,
@@ -377,27 +376,24 @@ fn register_exec_plugin() {
let mut split_whitespace = true;
if let Some(opts) = &options {
if let Some(command_value) = opts.get("command") {
if let Some(command_str) = command_value.as_str() {
if let Some(command_value) = opts.get("command")
&& let Some(command_str) = command_value.as_str() {
let parts: Vec<&str> = command_str.split_whitespace().collect();
if !parts.is_empty() {
program_name = parts[0].to_string();
args = parts[1..].iter().map(|s| s.to_string()).collect();
}
}
}
// Handle other options if needed
if let Some(split_value) = opts.get("split_whitespace") {
if let Some(split_bool) = split_value.as_bool() {
if let Some(split_value) = opts.get("split_whitespace")
&& let Some(split_bool) = split_value.as_bool() {
split_whitespace = split_bool;
}
}
if let Some(name_value) = opts.get("name") {
if let Some(name_str) = name_value.as_str() {
if let Some(name_value) = opts.get("name")
&& let Some(name_str) = name_value.as_str() {
meta_name = name_str.to_string();
}
}
}
Box::new(MetaPluginExec::new(&program_name,
args.iter().map(|s| s.as_str()).collect(),

View File

@@ -34,8 +34,8 @@ 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 key == "hostname"
&& let serde_yaml::Value::String(s) = &value {
if s == "false" {
final_options.insert(key, serde_yaml::Value::Bool(false));
continue;
@@ -44,7 +44,6 @@ impl HostnameMetaPlugin {
continue;
}
}
}
final_options.insert(key, value);
}
}
@@ -152,8 +151,8 @@ 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() {
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);
@@ -161,21 +160,18 @@ impl HostnameMetaPlugin {
}
}
}
}
// Fallback: try to get the FQDN using the system's hostname resolution
// This should give us the full hostname if configured
if let Ok(full_hostname) = std::process::Command::new("hostname")
.arg("-f")
.output()
{
if full_hostname.status.success() {
&& 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;
}
}
}
// Final fallback: return the short hostname
short_hostname
@@ -265,33 +261,30 @@ 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);
}
}
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);
}
}
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);
}
}
// Update outputs based on enabled status
// Handle hostname output

View File

@@ -385,8 +385,8 @@ impl TextMetaPlugin {
///
/// * `Option<MetaData>` - Metadata entry if enabled and data exists.
fn output_median_line_length_metadata(&self) -> Option<crate::meta_plugin::MetaData> {
if self.output_line_median_len {
if let Some(lengths) = &self.line_lengths {
if self.output_line_median_len
&& let Some(lengths) = &self.line_lengths {
if !lengths.is_empty() {
let mut sorted_lengths = lengths.clone();
sorted_lengths.sort();
@@ -403,11 +403,9 @@ impl TextMetaPlugin {
);
}
}
}
None
}
/// Helper method to output word and line counts.
///
/// Finalizes pending data and collects all enabled text statistics metadata.
@@ -476,7 +474,6 @@ impl MetaPlugin for TextMetaPlugin {
}
/// Updates the plugin with new data chunk.
///
/// Accumulates data for binary detection (if pending) or text statistics.