Skip to content

Commit

Permalink
Auto merge of #14532 - shannmu:_cargo_benchmark_names, r=epage
Browse files Browse the repository at this point in the history
feat: Add custom completer for completing benchmark names

### What does this PR try to resolve?
Tracking issue #14520

Add custom completer for `cargo build --bench=<TAB>`
  • Loading branch information
bors committed Sep 17, 2024
2 parents 1eb49a1 + 9d08d4a commit 60fbfb9
Showing 1 changed file with 14 additions and 1 deletion.
15 changes: 14 additions & 1 deletion src/cargo/util/command_prelude.rs
Original file line number Diff line number Diff line change
Expand Up @@ -163,7 +163,9 @@ pub trait CommandExt: Sized {
)
._arg(flag("benches", benches).help_heading(heading::TARGET_SELECTION))
._arg(
optional_multi_opt("bench", "NAME", bench).help_heading(heading::TARGET_SELECTION),
optional_multi_opt("bench", "NAME", bench)
.help_heading(heading::TARGET_SELECTION)
.add(clap_complete::ArgValueCandidates::new(get_bench_candidates)),
)
._arg(flag("all-targets", all).help_heading(heading::TARGET_SELECTION))
}
Expand Down Expand Up @@ -1046,6 +1048,17 @@ pub fn lockfile_path(
return Ok(Some(path));
}

fn get_bench_candidates() -> Vec<clap_complete::CompletionCandidate> {
get_targets_from_metadata()
.unwrap_or_default()
.into_iter()
.filter_map(|target| match target.kind() {
TargetKind::Bench => Some(clap_complete::CompletionCandidate::new(target.name())),
_ => None,
})
.collect::<Vec<_>>()
}

fn get_test_candidates() -> Vec<clap_complete::CompletionCandidate> {
get_targets_from_metadata()
.unwrap_or_default()
Expand Down

0 comments on commit 60fbfb9

Please sign in to comment.