@@ -54,7 +54,11 @@ enum Cmd {
5454 limit : u32 ,
5555 } ,
5656 /// List indexed files under a path prefix.
57- Files { path : Option < String > } ,
57+ Files {
58+ /// Path prefix filter (indexed file paths starting with this value).
59+ #[ arg( value_name = "PATH" ) ]
60+ prefix : Option < String > ,
61+ } ,
5862 /// Build markdown context for a symbol.
5963 Context {
6064 target : String ,
@@ -102,7 +106,7 @@ fn main() -> Result<()> {
102106 Cmd :: Sync => cmd_sync ( & root) ,
103107 Cmd :: Status => cmd_status ( & root) ,
104108 Cmd :: Query { query, limit } => cmd_query ( & root, & query, limit) ,
105- Cmd :: Files { path } => cmd_files ( & root, path . as_deref ( ) ) ,
109+ Cmd :: Files { prefix } => cmd_files ( & root, prefix . as_deref ( ) ) ,
106110 Cmd :: Context {
107111 target,
108112 depth,
@@ -394,10 +398,15 @@ fn cmd_query(root: &Utf8Path, q: &str, limit: u32) -> Result<()> {
394398}
395399
396400fn cmd_files ( root : & Utf8Path , prefix : Option < & str > ) -> Result < ( ) > {
401+ use std:: io:: Write ;
402+
397403 ensure_initialized ( root) ?;
398404 let db = Db :: open ( & db_path ( root) ) ?;
405+ let mut out = std:: io:: stdout ( ) . lock ( ) ;
399406 for f in db. files_under ( prefix. unwrap_or ( "" ) ) ? {
400- println ! ( "{} ({})" , f. path, f. language) ;
407+ if writeln ! ( out, "{} ({})" , f. path, f. language) . is_err ( ) {
408+ break ;
409+ }
401410 }
402411 Ok ( ( ) )
403412}
0 commit comments