diff --git a/src/filter_plugin/mod.rs b/src/filter_plugin/mod.rs index 8d77ab7..9bcd944 100644 --- a/src/filter_plugin/mod.rs +++ b/src/filter_plugin/mod.rs @@ -383,4 +383,72 @@ fn create_specific_filter( std::io::ErrorKind::InvalidInput, "tail_lines filter requires 'count' parameter" ))?; - Ok \ No newline at end of file + Ok(Box::new(tail::TailLinesFilter::new(count))) + } + FilterType::SkipBytes => { + let count = options.get("count") + .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 'count' parameter" + ))?; + Ok(Box::new(skip::SkipBytesFilter::new(count))) + } + FilterType::SkipLines => { + let count = options.get("count") + .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 'count' parameter" + ))?; + Ok(Box::new(skip::SkipLinesFilter::new(count))) + } + FilterType::StripAnsi => { + // StripAnsi doesn't take any parameters + if !options.is_empty() { + return Err(std::io::Error::new( + std::io::ErrorKind::InvalidInput, + "strip_ansi filter doesn't take parameters" + )); + } + Ok(Box::new(strip_ansi::StripAnsiFilter::new())) + } + } +} + +/// Parses an option value from a string into a JSON value. +/// +/// # Arguments +/// +/// * `input` - The input string. +/// +/// # Returns +/// +/// A `Result` containing the parsed JSON value. +fn parse_option_value(input: &str) -> Result { + // Remove quotes if present + let input = input.trim_matches(|c| c == '\'' || c == '"'); + + // Try to parse as number + if let Ok(num) = input.parse::() { + return Ok(serde_json::Value::Number(num.into())); + } + if let Ok(num) = input.parse::() { + if let Some(number) = serde_json::Number::from_f64(num) { + return Ok(serde_json::Value::Number(number)); + } + } + + // Try to parse as boolean + if input.eq_ignore_ascii_case("true") { + return Ok(serde_json::Value::Bool(true)); + } + if input.eq_ignore_ascii_case("false") { + return Ok(serde_json::Value::Bool(false)); + } + + // Treat as string + Ok(serde_json::Value::String(input.to_string())) +}