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

@@ -8,6 +8,7 @@ use crate::services::item_service::ItemService;
use clap::Command;
use is_terminal::IsTerminal;
use std::path::PathBuf;
use std::io::Read;
pub fn mode_get(
cmd: &mut Command,
@@ -16,6 +17,7 @@ pub fn mode_get(
tags: &mut Vec<String>,
conn: &mut rusqlite::Connection,
data_path: PathBuf,
filters: &Vec<String>,
) -> Result<()> {
if !ids.is_empty() && !tags.is_empty() {
cmd.error(clap::error::ErrorKind::InvalidValue, "Both ID and tags given, you must supply either IDs or tags when using --get").exit();
@@ -46,10 +48,27 @@ pub fn mode_get(
}
}
// Use streaming approach to handle large files
let mut reader = item_service.get_compression_service().stream_item_content(
data_path.join(item_id.to_string()),
&item_with_meta.item.compression
// Join all filter strings with | to create a single filter string
let filter_str = if filters.is_empty() {
None
} else {
Some(filters.join(" | "))
};
// Get a reader that applies the filters
let (mut reader, _, _) = item_service.get_item_content_info_streaming(
conn,
item_id,
None, // head_bytes
None, // head_words
None, // head_lines
None, // tail_bytes
None, // tail_words
None, // tail_lines
None, // line_start
None, // line_end
None, // grep
filter_str,
)?;
if detect_binary {
@@ -62,10 +81,21 @@ pub fn mode_get(
));
}
// We need to create a new reader since we consumed some bytes
reader = item_service.get_compression_service().stream_item_content(
data_path.join(item_id.to_string()),
&item_with_meta.item.compression
let (new_reader, _, _) = item_service.get_item_content_info_streaming(
conn,
item_id,
None,
None,
None,
None,
None,
None,
None,
None,
None,
filter_str,
)?;
reader = new_reader;
}
// Stream the content to stdout