feat: add skip_bytes, skip_lines, and strip_ansi filters
Co-authored-by: aider (openai/andrew/openrouter/sonoma-sky-alpha) <aider@aider.chat>
This commit is contained in:
@@ -383,4 +383,72 @@ 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
|
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<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()))
|
||||||
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user