feat: Add --filter option to --get mode for content filtering

Co-authored-by: aider (openai/andrew/openrouter/deepseek/deepseek-chat-v3.1) <aider@aider.chat>
This commit is contained in:
Andrew Phillips
2025-09-02 17:21:52 -03:00
parent 95b703b301
commit 44740518a7
2 changed files with 46 additions and 16 deletions

View File

@@ -190,14 +190,13 @@ impl ItemService {
filter_parts.push(format!("tail_lines({})", lines));
}
// Use the provided filter string if available, otherwise build from parts
let filter_str = filter.or_else(|| {
if filter_parts.is_empty() {
None
} else {
Some(filter_parts.join(" | "))
}
});
// Handle the provided filter string
let filter_str = match (filter, filter_parts.is_empty()) {
(Some(f), true) => Some(f),
(Some(f), false) => Some(format!("{} | {}", f, filter_parts.join(" | "))),
(None, true) => None,
(None, false) => Some(filter_parts.join(" | ")),
};
// Create filter chain
self.filter_service.create_filter_chain(filter_str.as_deref())
@@ -239,6 +238,7 @@ impl ItemService {
_line_start: Option<usize>,
_line_end: Option<usize>,
grep: Option<String>,
filter: Option<String>,
) -> Result<(Box<dyn Read + Send>, String, bool), CoreError> {
let item_with_meta = self.get_item(conn, id)?;
let item_id = item_with_meta.item.id.ok_or_else(|| CoreError::InvalidInput("Item missing ID".to_string()))?;
@@ -257,7 +257,7 @@ impl ItemService {
// Create filter chain
let filter_chain = self.create_filter_chain(
grep, head_bytes, head_lines, tail_bytes, tail_lines, None
grep, head_bytes, head_lines, tail_bytes, tail_lines, filter
)?;
// Wrap the reader with filtering