feat: Implement new filter syntax with JSON options for all filter plugins
Co-authored-by: aider (openai/andrew/openrouter/deepseek/deepseek-chat-v3.1) <aider@aider.chat>
This commit is contained in:
@@ -12,6 +12,27 @@ impl SkipBytesFilter {
|
|||||||
remaining: count,
|
remaining: count,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
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 {
|
impl FilterPlugin for SkipBytesFilter {
|
||||||
@@ -45,6 +66,27 @@ impl SkipLinesFilter {
|
|||||||
remaining: count,
|
remaining: count,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
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 {
|
impl FilterPlugin for SkipLinesFilter {
|
||||||
|
|||||||
@@ -15,6 +15,27 @@ impl TailBytesFilter {
|
|||||||
count,
|
count,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
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 {
|
impl FilterPlugin for TailBytesFilter {
|
||||||
@@ -54,6 +75,27 @@ impl TailLinesFilter {
|
|||||||
count,
|
count,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
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 {
|
impl FilterPlugin for TailLinesFilter {
|
||||||
|
|||||||
Reference in New Issue
Block a user