mirror of
https://github.com/rust-lang/cargo.git
synced 2025-09-28 11:20:36 +00:00
Auto merge of #14548 - shannmu:_cargo_test_names, r=epage
feat: Add custom completer for completing test names ### What does this PR try to resolve? Tracking issue https://github.com/rust-lang/cargo/issues/14520 Add custom completer for `cargo test --test <TAB>`
This commit is contained in:
commit
25456eadc5
@ -156,7 +156,11 @@ pub trait CommandExt: Sized {
|
|||||||
) -> Self {
|
) -> Self {
|
||||||
self.arg_targets_lib_bin_example(lib, bin, bins, example, examples)
|
self.arg_targets_lib_bin_example(lib, bin, bins, example, examples)
|
||||||
._arg(flag("tests", tests).help_heading(heading::TARGET_SELECTION))
|
._arg(flag("tests", tests).help_heading(heading::TARGET_SELECTION))
|
||||||
._arg(optional_multi_opt("test", "NAME", test).help_heading(heading::TARGET_SELECTION))
|
._arg(
|
||||||
|
optional_multi_opt("test", "NAME", test)
|
||||||
|
.help_heading(heading::TARGET_SELECTION)
|
||||||
|
.add(clap_complete::ArgValueCandidates::new(get_test_candidates)),
|
||||||
|
)
|
||||||
._arg(flag("benches", benches).help_heading(heading::TARGET_SELECTION))
|
._arg(flag("benches", benches).help_heading(heading::TARGET_SELECTION))
|
||||||
._arg(
|
._arg(
|
||||||
optional_multi_opt("bench", "NAME", bench).help_heading(heading::TARGET_SELECTION),
|
optional_multi_opt("bench", "NAME", bench).help_heading(heading::TARGET_SELECTION),
|
||||||
@ -1042,6 +1046,17 @@ pub fn lockfile_path(
|
|||||||
return Ok(Some(path));
|
return Ok(Some(path));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
fn get_test_candidates() -> Vec<clap_complete::CompletionCandidate> {
|
||||||
|
get_targets_from_metadata()
|
||||||
|
.unwrap_or_default()
|
||||||
|
.into_iter()
|
||||||
|
.filter_map(|target| match target.kind() {
|
||||||
|
TargetKind::Test => Some(clap_complete::CompletionCandidate::new(target.name())),
|
||||||
|
_ => None,
|
||||||
|
})
|
||||||
|
.collect::<Vec<_>>()
|
||||||
|
}
|
||||||
|
|
||||||
fn get_bin_candidates() -> Vec<clap_complete::CompletionCandidate> {
|
fn get_bin_candidates() -> Vec<clap_complete::CompletionCandidate> {
|
||||||
get_targets_from_metadata()
|
get_targets_from_metadata()
|
||||||
.unwrap_or_default()
|
.unwrap_or_default()
|
||||||
|
Loading…
x
Reference in New Issue
Block a user