Skip to content

Commit 3a42e5b

Browse files
committed
fix(cli): resolve clap path name clash in files subcommand
Rename the files positional arg to avoid conflicting with the global --path flag, and exit cleanly on broken pipe when stdout is closed.
1 parent d1a9199 commit 3a42e5b

1 file changed

Lines changed: 12 additions & 3 deletions

File tree

crates/codegraph/src/main.rs

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -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

396400
fn 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

Comments
 (0)