docs: Add comprehensive Rustdoc for ExecFilter and its methods

Co-authored-by: aider (openai/andrew/openrouter/sonoma-sky-alpha) <aider@aider.chat>
This commit is contained in:
Andrew Phillips
2025-09-10 15:12:49 -03:00
parent f3a4894699
commit 3ddecc9ed5

View File

@@ -5,6 +5,10 @@ use which::which;
use log::*; use log::*;
/// A filter that executes an external program and pipes input through it. /// A filter that executes an external program and pipes input through it.
///
/// This filter spawns an external command, pipes the input stream to its stdin,
/// and writes the stdout to the output stream. Supports async-like behavior via
/// threads for concurrent I/O. Requires the program to be available on PATH.
#[derive(Debug, Clone)] #[derive(Debug, Clone)]
pub struct ExecFilter { pub struct ExecFilter {
program: String, program: String,
@@ -19,11 +23,26 @@ pub struct ExecFilter {
impl ExecFilter { impl ExecFilter {
/// Creates a new `ExecFilter` for the specified program and arguments. /// Creates a new `ExecFilter` for the specified program and arguments.
/// ///
/// Checks if the program is available using `which` and stores the resolved path.
///
/// # Arguments /// # Arguments
/// ///
/// * `program` - The name or path of the program to execute. /// * `program` - The name or path of the program to execute.
/// * `args` - A slice of string slices representing 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 when parsing. /// * `split_whitespace` - Whether to split arguments on whitespace when parsing (unused in this context).
///
/// # Returns
///
/// A new `ExecFilter` instance.
///
/// # Examples
///
/// ```
/// use keep::filter_plugin::exec::ExecFilter;
///
/// let filter = ExecFilter::new("grep", vec!["-i", "error"], false);
/// assert!(filter.supported);
/// ```
pub fn new( pub fn new(
program: &str, program: &str,
args: Vec<&str>, args: Vec<&str>,
@@ -47,6 +66,9 @@ impl ExecFilter {
impl FilterPlugin for ExecFilter { impl FilterPlugin for ExecFilter {
/// Filters the input by piping it through the external program and writing the output. /// Filters the input by piping it through the external program and writing the output.
/// ///
/// Spawns the process with piped I/O, uses threads for concurrent input/output
/// copying, and waits for completion. Errors if the program isn't found or fails.
///
/// # Arguments /// # Arguments
/// ///
/// * `reader` - A boxed mutable reference to the input reader providing the data stream to pipe to the program. /// * `reader` - A boxed mutable reference to the input reader providing the data stream to pipe to the program.
@@ -55,6 +77,22 @@ impl FilterPlugin for ExecFilter {
/// # Returns /// # Returns
/// ///
/// Returns `Ok(())` on success, or an `io::Error` if process spawning, piping, or execution fails. /// Returns `Ok(())` on success, or an `io::Error` if process spawning, piping, or execution fails.
///
/// # Errors
///
/// * NotFound - Program not available.
/// * Other - Spawn, I/O, or wait failures.
///
/// # Examples
///
/// ```
/// use keep::filter_plugin::exec::ExecFilter;
/// use std::io::{Read, Write};
///
/// let mut filter = ExecFilter::new("cat", vec![], false);
/// // In filter context:
/// filter.filter(Box::new(&mut input), Box::new(&mut output)).unwrap();
/// ```
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(
@@ -166,6 +204,8 @@ impl FilterPlugin for ExecFilter {
/// Clones this filter into a new boxed instance. /// Clones this filter into a new boxed instance.
/// ///
/// Creates a new instance without active process handles.
///
/// # Returns /// # Returns
/// ///
/// A new `Box<dyn FilterPlugin>` representing a clone of this filter. /// A new `Box<dyn FilterPlugin>` representing a clone of this filter.
@@ -183,6 +223,8 @@ impl FilterPlugin for ExecFilter {
/// Returns the configuration options for this filter. /// Returns the configuration options for this filter.
/// ///
/// Defines "command" as required and "split_whitespace" as optional.
///
/// # Returns /// # Returns
/// ///
/// A vector of `FilterOption` describing the filter's configurable parameters. /// A vector of `FilterOption` describing the filter's configurable parameters.