docs: Add rustdoc to filter plugin modules and arguments
Co-authored-by: aider (openai/andrew/openrouter/sonoma-sky-alpha) <aider@aider.chat>
This commit is contained in:
@@ -22,8 +22,8 @@ impl ExecFilter {
|
|||||||
/// # Arguments
|
/// # Arguments
|
||||||
///
|
///
|
||||||
/// * `program` - The name or path of the program to execute.
|
/// * `program` - The name or path of the program to execute.
|
||||||
/// * `args` - The arguments to pass to the program.
|
/// * `args` - A slice of string slices representing the arguments to pass to the program.
|
||||||
/// * `split_whitespace` - Whether to split arguments on whitespace.
|
/// * `split_whitespace` - Whether to split arguments on whitespace when parsing.
|
||||||
pub fn new(
|
pub fn new(
|
||||||
program: &str,
|
program: &str,
|
||||||
args: Vec<&str>,
|
args: Vec<&str>,
|
||||||
@@ -49,8 +49,12 @@ impl FilterPlugin for ExecFilter {
|
|||||||
///
|
///
|
||||||
/// # Arguments
|
/// # Arguments
|
||||||
///
|
///
|
||||||
/// * `reader` - The input reader.
|
/// * `reader` - A boxed mutable reference to the input reader providing the data stream to pipe to the program.
|
||||||
/// * `writer` - The output writer.
|
/// * `writer` - A boxed mutable reference to the output writer where the program's output is sent.
|
||||||
|
///
|
||||||
|
/// # Returns
|
||||||
|
///
|
||||||
|
/// Returns `Ok(())` on success, or an `io::Error` if process spawning, piping, or execution fails.
|
||||||
fn filter(&mut self, mut reader: Box<&mut dyn Read>, mut writer: Box<&mut dyn Write>) -> Result<()> {
|
fn filter(&mut self, mut reader: Box<&mut dyn Read>, mut writer: Box<&mut dyn Write>) -> Result<()> {
|
||||||
if !self.supported {
|
if !self.supported {
|
||||||
return Err(std::io::Error::new(
|
return Err(std::io::Error::new(
|
||||||
@@ -161,6 +165,10 @@ impl FilterPlugin for ExecFilter {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/// Clones this filter into a new boxed instance.
|
/// Clones this filter into a new boxed instance.
|
||||||
|
///
|
||||||
|
/// # Returns
|
||||||
|
///
|
||||||
|
/// A new `Box<dyn FilterPlugin>` representing a clone of this filter.
|
||||||
fn clone_box(&self) -> Box<dyn FilterPlugin> {
|
fn clone_box(&self) -> Box<dyn FilterPlugin> {
|
||||||
Box::new(ExecFilter {
|
Box::new(ExecFilter {
|
||||||
program: self.program.clone(),
|
program: self.program.clone(),
|
||||||
@@ -174,6 +182,10 @@ impl FilterPlugin for ExecFilter {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/// Returns the configuration options for this filter.
|
/// Returns the configuration options for this filter.
|
||||||
|
///
|
||||||
|
/// # Returns
|
||||||
|
///
|
||||||
|
/// A vector of `FilterOption` describing the filter's configurable parameters.
|
||||||
fn options(&self) -> Vec<FilterOption> {
|
fn options(&self) -> Vec<FilterOption> {
|
||||||
vec![
|
vec![
|
||||||
FilterOption {
|
FilterOption {
|
||||||
|
|||||||
@@ -12,11 +12,11 @@ impl GrepFilter {
|
|||||||
///
|
///
|
||||||
/// # Arguments
|
/// # Arguments
|
||||||
///
|
///
|
||||||
/// * `pattern` - The regular expression pattern to match.
|
/// * `pattern` - The regular expression pattern used to match lines.
|
||||||
///
|
///
|
||||||
/// # Errors
|
/// # Errors
|
||||||
///
|
///
|
||||||
/// Returns an error if the pattern is invalid.
|
/// Returns an `io::Error` if the regex pattern is invalid.
|
||||||
pub fn new(pattern: String) -> Result<Self> {
|
pub fn new(pattern: String) -> Result<Self> {
|
||||||
let regex = Regex::new(&pattern)
|
let regex = Regex::new(&pattern)
|
||||||
.map_err(|e| std::io::Error::new(std::io::ErrorKind::InvalidInput, e))?;
|
.map_err(|e| std::io::Error::new(std::io::ErrorKind::InvalidInput, e))?;
|
||||||
@@ -31,8 +31,12 @@ impl FilterPlugin for GrepFilter {
|
|||||||
///
|
///
|
||||||
/// # Arguments
|
/// # Arguments
|
||||||
///
|
///
|
||||||
/// * `reader` - The input reader.
|
/// * `reader` - A boxed mutable reference to the input reader providing the data stream.
|
||||||
/// * `writer` - The output writer.
|
/// * `writer` - A boxed mutable reference to the output writer where matching lines are 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, mut reader: Box<&mut dyn Read>, mut writer: Box<&mut dyn Write>) -> Result<()> {
|
||||||
let mut buf_reader = std::io::BufReader::new(&mut *reader);
|
let mut buf_reader = std::io::BufReader::new(&mut *reader);
|
||||||
for line in buf_reader.by_ref().lines() {
|
for line in buf_reader.by_ref().lines() {
|
||||||
@@ -45,6 +49,10 @@ impl FilterPlugin for GrepFilter {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/// Clones this filter into a new boxed instance.
|
/// Clones this filter into a new boxed instance.
|
||||||
|
///
|
||||||
|
/// # Returns
|
||||||
|
///
|
||||||
|
/// A new `Box<dyn FilterPlugin>` representing a clone of this filter.
|
||||||
fn clone_box(&self) -> Box<dyn FilterPlugin> {
|
fn clone_box(&self) -> Box<dyn FilterPlugin> {
|
||||||
Box::new(Self {
|
Box::new(Self {
|
||||||
regex: self.regex.clone(),
|
regex: self.regex.clone(),
|
||||||
@@ -52,6 +60,10 @@ impl FilterPlugin for GrepFilter {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/// Returns the configuration options for this filter.
|
/// Returns the configuration options for this filter.
|
||||||
|
///
|
||||||
|
/// # Returns
|
||||||
|
///
|
||||||
|
/// A vector of `FilterOption` describing the filter's configurable parameters.
|
||||||
fn options(&self) -> Vec<FilterOption> {
|
fn options(&self) -> Vec<FilterOption> {
|
||||||
vec![
|
vec![
|
||||||
FilterOption {
|
FilterOption {
|
||||||
|
|||||||
@@ -13,7 +13,7 @@ impl HeadBytesFilter {
|
|||||||
///
|
///
|
||||||
/// # Arguments
|
/// # Arguments
|
||||||
///
|
///
|
||||||
/// * `count` - The maximum number of bytes to read.
|
/// * `count` - The maximum number of bytes to read from the input.
|
||||||
pub fn new(count: usize) -> Self {
|
pub fn new(count: usize) -> Self {
|
||||||
Self {
|
Self {
|
||||||
remaining: count,
|
remaining: count,
|
||||||
@@ -26,8 +26,12 @@ impl FilterPlugin for HeadBytesFilter {
|
|||||||
///
|
///
|
||||||
/// # Arguments
|
/// # Arguments
|
||||||
///
|
///
|
||||||
/// * `reader` - The input reader.
|
/// * `reader` - A boxed mutable reference to the input reader providing the data stream.
|
||||||
/// * `writer` - The output writer.
|
/// * `writer` - A boxed 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, mut reader: Box<&mut dyn Read>, mut writer: Box<&mut dyn Write>) -> Result<()> {
|
||||||
if self.remaining == 0 {
|
if self.remaining == 0 {
|
||||||
return Ok(());
|
return Ok(());
|
||||||
@@ -47,6 +51,10 @@ impl FilterPlugin for HeadBytesFilter {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/// Clones this filter into a new boxed instance.
|
/// Clones this filter into a new boxed instance.
|
||||||
|
///
|
||||||
|
/// # Returns
|
||||||
|
///
|
||||||
|
/// A new `Box<dyn FilterPlugin>` representing a clone of this filter.
|
||||||
fn clone_box(&self) -> Box<dyn FilterPlugin> {
|
fn clone_box(&self) -> Box<dyn FilterPlugin> {
|
||||||
Box::new(Self {
|
Box::new(Self {
|
||||||
remaining: self.remaining,
|
remaining: self.remaining,
|
||||||
@@ -54,6 +62,10 @@ impl FilterPlugin for HeadBytesFilter {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/// Returns the configuration options for this filter.
|
/// Returns the configuration options for this filter.
|
||||||
|
///
|
||||||
|
/// # Returns
|
||||||
|
///
|
||||||
|
/// A vector of `FilterOption` describing the filter's configurable parameters.
|
||||||
fn options(&self) -> Vec<FilterOption> {
|
fn options(&self) -> Vec<FilterOption> {
|
||||||
vec![
|
vec![
|
||||||
FilterOption {
|
FilterOption {
|
||||||
@@ -75,7 +87,7 @@ impl HeadLinesFilter {
|
|||||||
///
|
///
|
||||||
/// # Arguments
|
/// # Arguments
|
||||||
///
|
///
|
||||||
/// * `count` - The maximum number of lines to read.
|
/// * `count` - The maximum number of lines to read from the input.
|
||||||
pub fn new(count: usize) -> Self {
|
pub fn new(count: usize) -> Self {
|
||||||
Self {
|
Self {
|
||||||
remaining: count,
|
remaining: count,
|
||||||
@@ -88,8 +100,12 @@ impl FilterPlugin for HeadLinesFilter {
|
|||||||
///
|
///
|
||||||
/// # Arguments
|
/// # Arguments
|
||||||
///
|
///
|
||||||
/// * `reader` - The input reader.
|
/// * `reader` - A boxed mutable reference to the input reader providing the data stream.
|
||||||
/// * `writer` - The output writer.
|
/// * `writer` - A boxed 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, mut reader: Box<&mut dyn Read>, mut writer: Box<&mut dyn Write>) -> Result<()> {
|
||||||
if self.remaining == 0 {
|
if self.remaining == 0 {
|
||||||
return Ok(());
|
return Ok(());
|
||||||
@@ -108,6 +124,10 @@ impl FilterPlugin for HeadLinesFilter {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/// Clones this filter into a new boxed instance.
|
/// Clones this filter into a new boxed instance.
|
||||||
|
///
|
||||||
|
/// # Returns
|
||||||
|
///
|
||||||
|
/// A new `Box<dyn FilterPlugin>` representing a clone of this filter.
|
||||||
fn clone_box(&self) -> Box<dyn FilterPlugin> {
|
fn clone_box(&self) -> Box<dyn FilterPlugin> {
|
||||||
Box::new(Self {
|
Box::new(Self {
|
||||||
remaining: self.remaining,
|
remaining: self.remaining,
|
||||||
@@ -115,6 +135,10 @@ impl FilterPlugin for HeadLinesFilter {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/// Returns the configuration options for this filter.
|
/// Returns the configuration options for this filter.
|
||||||
|
///
|
||||||
|
/// # Returns
|
||||||
|
///
|
||||||
|
/// A vector of `FilterOption` describing the filter's configurable parameters.
|
||||||
fn options(&self) -> Vec<FilterOption> {
|
fn options(&self) -> Vec<FilterOption> {
|
||||||
vec![
|
vec![
|
||||||
FilterOption {
|
FilterOption {
|
||||||
|
|||||||
@@ -32,16 +32,24 @@ pub trait FilterPlugin: Send {
|
|||||||
///
|
///
|
||||||
/// # Arguments
|
/// # Arguments
|
||||||
///
|
///
|
||||||
/// * `reader` - The input reader.
|
/// * `reader` - A boxed mutable reference to the input reader providing the data to filter.
|
||||||
/// * `writer` - The output writer.
|
/// * `writer` - A boxed mutable reference to the output writer where the processed data is written.
|
||||||
///
|
///
|
||||||
/// # Returns
|
/// # Returns
|
||||||
///
|
///
|
||||||
/// A `Result` indicating success or failure.
|
/// A `Result` indicating success (`Ok(())`) or failure with an `io::Error`.
|
||||||
fn filter(&mut self, reader: Box<&mut dyn Read>, writer: Box<&mut dyn Write>) -> Result<()>;
|
fn filter(&mut self, reader: Box<&mut dyn Read>, writer: Box<&mut dyn Write>) -> Result<()>;
|
||||||
/// Clones this plugin into a new boxed instance.
|
/// Clones this plugin into a new boxed instance.
|
||||||
|
///
|
||||||
|
/// # Returns
|
||||||
|
///
|
||||||
|
/// A new `Box<dyn FilterPlugin>` clone of the current plugin.
|
||||||
fn clone_box(&self) -> Box<dyn FilterPlugin>;
|
fn clone_box(&self) -> Box<dyn FilterPlugin>;
|
||||||
/// Returns the configuration options for this plugin.
|
/// Returns the configuration options for this plugin.
|
||||||
|
///
|
||||||
|
/// # Returns
|
||||||
|
///
|
||||||
|
/// A vector of `FilterOption` structs describing the plugin's options.
|
||||||
fn options(&self) -> Vec<FilterOption>;
|
fn options(&self) -> Vec<FilterOption>;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -66,6 +74,10 @@ pub struct FilterChain {
|
|||||||
|
|
||||||
impl Clone for FilterChain {
|
impl Clone for FilterChain {
|
||||||
/// Clones this filter chain.
|
/// Clones this filter chain.
|
||||||
|
///
|
||||||
|
/// # Returns
|
||||||
|
///
|
||||||
|
/// A new `FilterChain` with cloned plugins.
|
||||||
fn clone(&self) -> Self {
|
fn clone(&self) -> Self {
|
||||||
let mut plugins = Vec::with_capacity(self.plugins.len());
|
let mut plugins = Vec::with_capacity(self.plugins.len());
|
||||||
for plugin in &self.plugins {
|
for plugin in &self.plugins {
|
||||||
@@ -77,6 +89,10 @@ impl Clone for FilterChain {
|
|||||||
|
|
||||||
impl Clone for Box<dyn FilterPlugin> {
|
impl Clone for Box<dyn FilterPlugin> {
|
||||||
/// Clones the boxed filter plugin.
|
/// Clones the boxed filter plugin.
|
||||||
|
///
|
||||||
|
/// # Returns
|
||||||
|
///
|
||||||
|
/// A new boxed clone of the filter plugin.
|
||||||
fn clone(&self) -> Self {
|
fn clone(&self) -> Self {
|
||||||
self.clone_box()
|
self.clone_box()
|
||||||
}
|
}
|
||||||
@@ -84,6 +100,10 @@ impl Clone for Box<dyn FilterPlugin> {
|
|||||||
|
|
||||||
impl FilterChain {
|
impl FilterChain {
|
||||||
/// Creates a new empty filter chain.
|
/// Creates a new empty filter chain.
|
||||||
|
///
|
||||||
|
/// # Returns
|
||||||
|
///
|
||||||
|
/// A new `FilterChain` with no plugins.
|
||||||
pub fn new() -> Self {
|
pub fn new() -> Self {
|
||||||
Self {
|
Self {
|
||||||
plugins: Vec::new(),
|
plugins: Vec::new(),
|
||||||
@@ -91,6 +111,10 @@ impl FilterChain {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/// Adds a plugin to the chain.
|
/// Adds a plugin to the chain.
|
||||||
|
///
|
||||||
|
/// # Arguments
|
||||||
|
///
|
||||||
|
/// * `plugin` - The boxed filter plugin to add to the chain.
|
||||||
pub fn add_plugin(&mut self, plugin: Box<dyn FilterPlugin>) {
|
pub fn add_plugin(&mut self, plugin: Box<dyn FilterPlugin>) {
|
||||||
self.plugins.push(plugin);
|
self.plugins.push(plugin);
|
||||||
}
|
}
|
||||||
@@ -99,12 +123,12 @@ impl FilterChain {
|
|||||||
///
|
///
|
||||||
/// # Arguments
|
/// # Arguments
|
||||||
///
|
///
|
||||||
/// * `reader` - The input reader.
|
/// * `reader` - A mutable reference to the input reader providing the data stream.
|
||||||
/// * `writer` - The output writer.
|
/// * `writer` - A mutable reference to the output writer where the fully filtered data is sent.
|
||||||
///
|
///
|
||||||
/// # Returns
|
/// # Returns
|
||||||
///
|
///
|
||||||
/// A `Result` indicating success or failure.
|
/// A `Result` indicating success (`Ok(())`) or failure with an `io::Error` if any filter in the chain fails.
|
||||||
pub fn filter(&mut self, reader: &mut dyn Read, writer: &mut dyn Write) -> Result<()> {
|
pub fn filter(&mut self, reader: &mut dyn Read, writer: &mut dyn Write) -> Result<()> {
|
||||||
if self.plugins.is_empty() {
|
if self.plugins.is_empty() {
|
||||||
// If no plugins, just copy the input to output
|
// If no plugins, just copy the input to output
|
||||||
@@ -145,11 +169,11 @@ impl FilterChain {
|
|||||||
///
|
///
|
||||||
/// # Arguments
|
/// # Arguments
|
||||||
///
|
///
|
||||||
/// * `filter_str` - The filter string (e.g., "head_lines(10)|grep(pattern=error)").
|
/// * `filter_str` - The filter string specifying the chain, e.g., "head_lines(10)|grep(pattern=error)".
|
||||||
///
|
///
|
||||||
/// # Returns
|
/// # Returns
|
||||||
///
|
///
|
||||||
/// A `Result` containing the parsed `FilterChain` or an error if invalid.
|
/// A `Result` containing the parsed `FilterChain` on success, or an `io::Error` if the string is invalid.
|
||||||
pub fn parse_filter_string(filter_str: &str) -> Result<FilterChain> {
|
pub fn parse_filter_string(filter_str: &str) -> Result<FilterChain> {
|
||||||
let mut chain = FilterChain::new();
|
let mut chain = FilterChain::new();
|
||||||
|
|
||||||
@@ -224,13 +248,13 @@ pub fn parse_filter_string(filter_str: &str) -> Result<FilterChain> {
|
|||||||
///
|
///
|
||||||
/// # Arguments
|
/// # Arguments
|
||||||
///
|
///
|
||||||
/// * `filter_type` - The type of filter to create.
|
/// * `filter_type` - The enum variant indicating the type of filter to instantiate.
|
||||||
/// * `unnamed_params` - Unnamed parameters.
|
/// * `unnamed_params` - A slice of unnamed JSON parameters passed to the filter.
|
||||||
/// * `named_options` - Named options.
|
/// * `named_options` - A hashmap of named options as key-value pairs.
|
||||||
///
|
///
|
||||||
/// # Returns
|
/// # Returns
|
||||||
///
|
///
|
||||||
/// A `Result` containing the boxed filter plugin.
|
/// A `Result` containing a boxed `FilterPlugin` on success, or an `io::Error` if creation fails.
|
||||||
fn create_filter_with_options(
|
fn create_filter_with_options(
|
||||||
filter_type: FilterType,
|
filter_type: FilterType,
|
||||||
unnamed_params: &[serde_json::Value],
|
unnamed_params: &[serde_json::Value],
|
||||||
@@ -301,12 +325,12 @@ fn create_filter_with_options(
|
|||||||
///
|
///
|
||||||
/// # Arguments
|
/// # Arguments
|
||||||
///
|
///
|
||||||
/// * `filter_type` - The type of filter.
|
/// * `filter_type` - The enum variant indicating the type of filter to instantiate.
|
||||||
/// * `options` - The processed options.
|
/// * `options` - A reference to the hashmap of processed options for the filter.
|
||||||
///
|
///
|
||||||
/// # Returns
|
/// # Returns
|
||||||
///
|
///
|
||||||
/// A `Result` containing the boxed filter plugin.
|
/// A `Result` containing a boxed `FilterPlugin` on success, or an `io::Error` if instantiation fails.
|
||||||
fn create_specific_filter(
|
fn create_specific_filter(
|
||||||
filter_type: FilterType,
|
filter_type: FilterType,
|
||||||
options: &HashMap<String, serde_json::Value>,
|
options: &HashMap<String, serde_json::Value>,
|
||||||
@@ -359,72 +383,4 @@ fn create_specific_filter(
|
|||||||
std::io::ErrorKind::InvalidInput,
|
std::io::ErrorKind::InvalidInput,
|
||||||
"tail_lines filter requires 'count' parameter"
|
"tail_lines filter requires 'count' parameter"
|
||||||
))?;
|
))?;
|
||||||
Ok(Box::new(tail::TailLinesFilter::new(count)))
|
Ok
|
||||||
}
|
|
||||||
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<serde_json::Value> {
|
|
||||||
// Remove quotes if present
|
|
||||||
let input = input.trim_matches(|c| c == '\'' || c == '"');
|
|
||||||
|
|
||||||
// Try to parse as number
|
|
||||||
if let Ok(num) = input.parse::<i64>() {
|
|
||||||
return Ok(serde_json::Value::Number(num.into()));
|
|
||||||
}
|
|
||||||
if let Ok(num) = input.parse::<f64>() {
|
|
||||||
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()))
|
|
||||||
}
|
|
||||||
@@ -13,7 +13,7 @@ impl SkipBytesFilter {
|
|||||||
///
|
///
|
||||||
/// # Arguments
|
/// # Arguments
|
||||||
///
|
///
|
||||||
/// * `count` - The number of bytes to skip.
|
/// * `count` - The number of bytes to skip from the beginning of the input.
|
||||||
pub fn new(count: usize) -> Self {
|
pub fn new(count: usize) -> Self {
|
||||||
Self {
|
Self {
|
||||||
remaining: count,
|
remaining: count,
|
||||||
@@ -21,6 +21,14 @@ impl SkipBytesFilter {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/// Creates a new instance from options.
|
/// 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>> {
|
pub fn create(options: Option<serde_json::Value>) -> Result<Box<dyn FilterPlugin>> {
|
||||||
let options = options.ok_or_else(|| {
|
let options = options.ok_or_else(|| {
|
||||||
std::io::Error::new(
|
std::io::Error::new(
|
||||||
@@ -48,8 +56,12 @@ impl FilterPlugin for SkipBytesFilter {
|
|||||||
///
|
///
|
||||||
/// # Arguments
|
/// # Arguments
|
||||||
///
|
///
|
||||||
/// * `reader` - The input reader.
|
/// * `reader` - A boxed mutable reference to the input reader providing the data stream.
|
||||||
/// * `writer` - The output writer.
|
/// * `writer` - A boxed 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, mut reader: Box<&mut dyn Read>, mut writer: Box<&mut dyn Write>) -> Result<()> {
|
||||||
// Skip bytes in chunks
|
// Skip bytes in chunks
|
||||||
if self.remaining > 0 {
|
if self.remaining > 0 {
|
||||||
@@ -70,6 +82,10 @@ impl FilterPlugin for SkipBytesFilter {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/// Clones this filter into a new boxed instance.
|
/// Clones this filter into a new boxed instance.
|
||||||
|
///
|
||||||
|
/// # Returns
|
||||||
|
///
|
||||||
|
/// A new `Box<dyn FilterPlugin>` representing a clone of this filter.
|
||||||
fn clone_box(&self) -> Box<dyn FilterPlugin> {
|
fn clone_box(&self) -> Box<dyn FilterPlugin> {
|
||||||
Box::new(Self {
|
Box::new(Self {
|
||||||
remaining: self.remaining,
|
remaining: self.remaining,
|
||||||
@@ -77,6 +93,10 @@ impl FilterPlugin for SkipBytesFilter {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/// Returns the configuration options for this filter.
|
/// Returns the configuration options for this filter.
|
||||||
|
///
|
||||||
|
/// # Returns
|
||||||
|
///
|
||||||
|
/// A vector of `FilterOption` describing the filter's configurable parameters.
|
||||||
fn options(&self) -> Vec<FilterOption> {
|
fn options(&self) -> Vec<FilterOption> {
|
||||||
vec![
|
vec![
|
||||||
FilterOption {
|
FilterOption {
|
||||||
@@ -98,7 +118,7 @@ impl SkipLinesFilter {
|
|||||||
///
|
///
|
||||||
/// # Arguments
|
/// # Arguments
|
||||||
///
|
///
|
||||||
/// * `count` - The number of lines to skip.
|
/// * `count` - The number of lines to skip from the beginning of the input.
|
||||||
pub fn new(count: usize) -> Self {
|
pub fn new(count: usize) -> Self {
|
||||||
Self {
|
Self {
|
||||||
remaining: count,
|
remaining: count,
|
||||||
@@ -106,6 +126,14 @@ impl SkipLinesFilter {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/// Creates a new instance from options.
|
/// 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>> {
|
pub fn create(options: Option<serde_json::Value>) -> Result<Box<dyn FilterPlugin>> {
|
||||||
let options = options.ok_or_else(|| {
|
let options = options.ok_or_else(|| {
|
||||||
std::io::Error::new(
|
std::io::Error::new(
|
||||||
@@ -133,8 +161,12 @@ impl FilterPlugin for SkipLinesFilter {
|
|||||||
///
|
///
|
||||||
/// # Arguments
|
/// # Arguments
|
||||||
///
|
///
|
||||||
/// * `reader` - The input reader.
|
/// * `reader` - A boxed mutable reference to the input reader providing the data stream.
|
||||||
/// * `writer` - The output writer.
|
/// * `writer` - A boxed 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, mut reader: Box<&mut dyn Read>, mut writer: Box<&mut dyn Write>) -> Result<()> {
|
||||||
let mut buf_reader = std::io::BufReader::new(&mut *reader);
|
let mut buf_reader = std::io::BufReader::new(&mut *reader);
|
||||||
for line in buf_reader.by_ref().lines() {
|
for line in buf_reader.by_ref().lines() {
|
||||||
@@ -149,6 +181,10 @@ impl FilterPlugin for SkipLinesFilter {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/// Clones this filter into a new boxed instance.
|
/// Clones this filter into a new boxed instance.
|
||||||
|
///
|
||||||
|
/// # Returns
|
||||||
|
///
|
||||||
|
/// A new `Box<dyn FilterPlugin>` representing a clone of this filter.
|
||||||
fn clone_box(&self) -> Box<dyn FilterPlugin> {
|
fn clone_box(&self) -> Box<dyn FilterPlugin> {
|
||||||
Box::new(Self {
|
Box::new(Self {
|
||||||
remaining: self.remaining,
|
remaining: self.remaining,
|
||||||
@@ -156,6 +192,10 @@ impl FilterPlugin for SkipLinesFilter {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/// Returns the configuration options for this filter.
|
/// Returns the configuration options for this filter.
|
||||||
|
///
|
||||||
|
/// # Returns
|
||||||
|
///
|
||||||
|
/// A vector of `FilterOption` describing the filter's configurable parameters.
|
||||||
fn options(&self) -> Vec<FilterOption> {
|
fn options(&self) -> Vec<FilterOption> {
|
||||||
vec![
|
vec![
|
||||||
FilterOption {
|
FilterOption {
|
||||||
|
|||||||
@@ -7,6 +7,10 @@ pub struct StripAnsiFilter;
|
|||||||
|
|
||||||
impl StripAnsiFilter {
|
impl StripAnsiFilter {
|
||||||
/// Creates a new `StripAnsiFilter`.
|
/// Creates a new `StripAnsiFilter`.
|
||||||
|
///
|
||||||
|
/// # Returns
|
||||||
|
///
|
||||||
|
/// A new instance of `StripAnsiFilter`.
|
||||||
pub fn new() -> Self {
|
pub fn new() -> Self {
|
||||||
Self
|
Self
|
||||||
}
|
}
|
||||||
@@ -17,8 +21,12 @@ impl FilterPlugin for StripAnsiFilter {
|
|||||||
///
|
///
|
||||||
/// # Arguments
|
/// # Arguments
|
||||||
///
|
///
|
||||||
/// * `reader` - The input reader.
|
/// * `reader` - A boxed mutable reference to the input reader providing the data stream with potential ANSI codes.
|
||||||
/// * `writer` - The output writer.
|
/// * `writer` - A boxed 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<()> {
|
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);
|
let mut ansi_writer = Writer::new(&mut *writer);
|
||||||
std::io::copy(&mut *reader, &mut ansi_writer)?;
|
std::io::copy(&mut *reader, &mut ansi_writer)?;
|
||||||
@@ -26,11 +34,19 @@ impl FilterPlugin for StripAnsiFilter {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/// Clones this filter into a new boxed instance.
|
/// Clones this filter into a new boxed instance.
|
||||||
|
///
|
||||||
|
/// # Returns
|
||||||
|
///
|
||||||
|
/// A new `Box<dyn FilterPlugin>` representing a clone of this filter.
|
||||||
fn clone_box(&self) -> Box<dyn FilterPlugin> {
|
fn clone_box(&self) -> Box<dyn FilterPlugin> {
|
||||||
Box::new(Self)
|
Box::new(Self)
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Returns the configuration options for this filter (none required).
|
/// Returns the configuration options for this filter (none required).
|
||||||
|
///
|
||||||
|
/// # Returns
|
||||||
|
///
|
||||||
|
/// An empty vector since this filter has no configurable options.
|
||||||
fn options(&self) -> Vec<FilterOption> {
|
fn options(&self) -> Vec<FilterOption> {
|
||||||
Vec::new() // strip_ansi doesn't take any options
|
Vec::new() // strip_ansi doesn't take any options
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -15,7 +15,7 @@ impl TailBytesFilter {
|
|||||||
///
|
///
|
||||||
/// # Arguments
|
/// # Arguments
|
||||||
///
|
///
|
||||||
/// * `count` - The number of bytes to keep from the end.
|
/// * `count` - The number of bytes to retain from the end of the input.
|
||||||
pub fn new(count: usize) -> Self {
|
pub fn new(count: usize) -> Self {
|
||||||
Self {
|
Self {
|
||||||
buffer: VecDeque::with_capacity(count),
|
buffer: VecDeque::with_capacity(count),
|
||||||
@@ -24,6 +24,14 @@ impl TailBytesFilter {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/// Creates a new instance from options.
|
/// 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>> {
|
pub fn create(options: Option<serde_json::Value>) -> Result<Box<dyn FilterPlugin>> {
|
||||||
let options = options.ok_or_else(|| {
|
let options = options.ok_or_else(|| {
|
||||||
std::io::Error::new(
|
std::io::Error::new(
|
||||||
@@ -51,8 +59,12 @@ impl FilterPlugin for TailBytesFilter {
|
|||||||
///
|
///
|
||||||
/// # Arguments
|
/// # Arguments
|
||||||
///
|
///
|
||||||
/// * `reader` - The input reader.
|
/// * `reader` - A boxed mutable reference to the input reader providing the data stream.
|
||||||
/// * `writer` - The output writer.
|
/// * `writer` - A boxed 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, mut reader: Box<&mut dyn Read>, mut writer: Box<&mut dyn Write>) -> Result<()> {
|
||||||
let mut temp_buffer = vec![0; PIPESIZE];
|
let mut temp_buffer = vec![0; PIPESIZE];
|
||||||
loop {
|
loop {
|
||||||
@@ -77,6 +89,10 @@ impl FilterPlugin for TailBytesFilter {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/// Clones this filter into a new boxed instance.
|
/// Clones this filter into a new boxed instance.
|
||||||
|
///
|
||||||
|
/// # Returns
|
||||||
|
///
|
||||||
|
/// A new `Box<dyn FilterPlugin>` representing a clone of this filter.
|
||||||
fn clone_box(&self) -> Box<dyn FilterPlugin> {
|
fn clone_box(&self) -> Box<dyn FilterPlugin> {
|
||||||
Box::new(Self {
|
Box::new(Self {
|
||||||
buffer: self.buffer.clone(),
|
buffer: self.buffer.clone(),
|
||||||
@@ -85,6 +101,10 @@ impl FilterPlugin for TailBytesFilter {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/// Returns the configuration options for this filter.
|
/// Returns the configuration options for this filter.
|
||||||
|
///
|
||||||
|
/// # Returns
|
||||||
|
///
|
||||||
|
/// A vector of `FilterOption` describing the filter's configurable parameters.
|
||||||
fn options(&self) -> Vec<FilterOption> {
|
fn options(&self) -> Vec<FilterOption> {
|
||||||
vec![
|
vec![
|
||||||
FilterOption {
|
FilterOption {
|
||||||
@@ -107,7 +127,7 @@ impl TailLinesFilter {
|
|||||||
///
|
///
|
||||||
/// # Arguments
|
/// # Arguments
|
||||||
///
|
///
|
||||||
/// * `count` - The number of lines to keep from the end.
|
/// * `count` - The number of lines to retain from the end of the input.
|
||||||
pub fn new(count: usize) -> Self {
|
pub fn new(count: usize) -> Self {
|
||||||
Self {
|
Self {
|
||||||
lines: VecDeque::with_capacity(count),
|
lines: VecDeque::with_capacity(count),
|
||||||
@@ -116,6 +136,14 @@ impl TailLinesFilter {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/// Creates a new instance from options.
|
/// 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>> {
|
pub fn create(options: Option<serde_json::Value>) -> Result<Box<dyn FilterPlugin>> {
|
||||||
let options = options.ok_or_else(|| {
|
let options = options.ok_or_else(|| {
|
||||||
std::io::Error::new(
|
std::io::Error::new(
|
||||||
@@ -143,8 +171,12 @@ impl FilterPlugin for TailLinesFilter {
|
|||||||
///
|
///
|
||||||
/// # Arguments
|
/// # Arguments
|
||||||
///
|
///
|
||||||
/// * `reader` - The input reader.
|
/// * `reader` - A boxed mutable reference to the input reader providing the data stream.
|
||||||
/// * `writer` - The output writer.
|
/// * `writer` - A boxed 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, mut reader: Box<&mut dyn Read>, mut writer: Box<&mut dyn Write>) -> Result<()> {
|
||||||
let mut buf_reader = std::io::BufReader::new(&mut *reader);
|
let mut buf_reader = std::io::BufReader::new(&mut *reader);
|
||||||
for line in buf_reader.by_ref().lines() {
|
for line in buf_reader.by_ref().lines() {
|
||||||
@@ -163,6 +195,10 @@ impl FilterPlugin for TailLinesFilter {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/// Clones this filter into a new boxed instance.
|
/// Clones this filter into a new boxed instance.
|
||||||
|
///
|
||||||
|
/// # Returns
|
||||||
|
///
|
||||||
|
/// A new `Box<dyn FilterPlugin>` representing a clone of this filter.
|
||||||
fn clone_box(&self) -> Box<dyn FilterPlugin> {
|
fn clone_box(&self) -> Box<dyn FilterPlugin> {
|
||||||
Box::new(Self {
|
Box::new(Self {
|
||||||
lines: self.lines.clone(),
|
lines: self.lines.clone(),
|
||||||
@@ -171,6 +207,10 @@ impl FilterPlugin for TailLinesFilter {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/// Returns the configuration options for this filter.
|
/// Returns the configuration options for this filter.
|
||||||
|
///
|
||||||
|
/// # Returns
|
||||||
|
///
|
||||||
|
/// A vector of `FilterOption` describing the filter's configurable parameters.
|
||||||
fn options(&self) -> Vec<FilterOption> {
|
fn options(&self) -> Vec<FilterOption> {
|
||||||
vec![
|
vec![
|
||||||
FilterOption {
|
FilterOption {
|
||||||
|
|||||||
@@ -4,11 +4,11 @@ use std::io::Result;
|
|||||||
///
|
///
|
||||||
/// # Arguments
|
/// # Arguments
|
||||||
///
|
///
|
||||||
/// * `filter_str` - The string describing the filter chain (e.g., "head_lines(10)|grep(pattern=error)").
|
/// * `filter_str` - The string describing the filter chain, such as "head_lines(10)|grep(pattern=error)".
|
||||||
///
|
///
|
||||||
/// # Returns
|
/// # Returns
|
||||||
///
|
///
|
||||||
/// A `Result` containing an optional `FilterChain` if parsing succeeds.
|
/// A `Result` containing an optional `FilterChain` if parsing succeeds, wrapped in `Some`, or an error if invalid.
|
||||||
pub fn create_filter_chain(filter_str: &str) -> Result<Option<super::FilterChain>> {
|
pub fn create_filter_chain(filter_str: &str) -> Result<Option<super::FilterChain>> {
|
||||||
super::parse_filter_string(filter_str).map(Some)
|
super::parse_filter_string(filter_str).map(Some)
|
||||||
}
|
}
|
||||||
@@ -17,11 +17,11 @@ pub fn create_filter_chain(filter_str: &str) -> Result<Option<super::FilterChain
|
|||||||
///
|
///
|
||||||
/// # Arguments
|
/// # Arguments
|
||||||
///
|
///
|
||||||
/// * `s` - The string to parse.
|
/// * `s` - The string to parse into a number.
|
||||||
///
|
///
|
||||||
/// # Returns
|
/// # Returns
|
||||||
///
|
///
|
||||||
/// A `Result` containing the parsed number or an error if invalid.
|
/// A `Result` containing the parsed value of type T on success, or an `io::Error` if the string is not a valid number.
|
||||||
pub fn parse_number<T: std::str::FromStr>(s: &str) -> Result<T> {
|
pub fn parse_number<T: std::str::FromStr>(s: &str) -> Result<T> {
|
||||||
s.parse::<T>()
|
s.parse::<T>()
|
||||||
.map_err(|_| std::io::Error::new(std::io::ErrorKind::InvalidInput, "Invalid number"))
|
.map_err(|_| std::io::Error::new(std::io::ErrorKind::InvalidInput, "Invalid number"))
|
||||||
|
|||||||
Reference in New Issue
Block a user