Skip to content

Commit 8e77258

Browse files
committed
fix(completions): include all in cargo tree --target candidates
The `all` meta-target was missing from native completions for `cargo tree --target`. Added `arg_target_triple_with_candidates` to allow commands to provide custom completion candidates, following the pattern established for `--package`. Fixes #16295 Signed-off-by: Charalampos Mitrodimas <charmitro@posteo.net>
1 parent 47a6c04 commit 8e77258

File tree

2 files changed

+19
-2
lines changed

2 files changed

+19
-2
lines changed

src/bin/cargo/commands/tree.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -108,9 +108,10 @@ pub fn cli() -> Command {
108108
)
109109
.arg_features()
110110
.arg(flag("all-targets", "Deprecated, use --target=all instead").hide(true))
111-
.arg_target_triple(
111+
.arg_target_triple_with_candidates(
112112
"Filter dependencies matching the given target-triple (default host platform). \
113113
Pass `all` to include all targets.",
114+
ArgValueCandidates::new(get_target_triples_with_all),
114115
)
115116
.arg_manifest_path()
116117
.arg_lockfile_path()

src/cargo/util/command_prelude.rs

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -327,6 +327,14 @@ pub trait CommandExt: Sized {
327327
}
328328

329329
fn arg_target_triple(self, target: &'static str) -> Self {
330+
self.arg_target_triple_with_candidates(target, ArgValueCandidates::new(get_target_triples))
331+
}
332+
333+
fn arg_target_triple_with_candidates(
334+
self,
335+
target: &'static str,
336+
target_completion: ArgValueCandidates,
337+
) -> Self {
330338
let unsupported_short_arg = {
331339
let value_parser = UnknownArgumentValueParser::suggest_arg("--target");
332340
Arg::new("unsupported-short-target-flag")
@@ -339,7 +347,7 @@ pub trait CommandExt: Sized {
339347
self._arg(
340348
optional_multi_opt("target", "TRIPLE", target)
341349
.help_heading(heading::COMPILATION_OPTIONS)
342-
.add(clap_complete::ArgValueCandidates::new(get_target_triples)),
350+
.add(target_completion),
343351
)
344352
._arg(unsupported_short_arg)
345353
}
@@ -1283,6 +1291,14 @@ fn get_target_triples() -> Vec<clap_complete::CompletionCandidate> {
12831291
candidates
12841292
}
12851293

1294+
pub fn get_target_triples_with_all() -> Vec<clap_complete::CompletionCandidate> {
1295+
let mut candidates = vec![
1296+
clap_complete::CompletionCandidate::new("all").help(Some("Include all targets".into())),
1297+
];
1298+
candidates.extend(get_target_triples());
1299+
candidates
1300+
}
1301+
12861302
fn get_target_triples_from_rustup() -> CargoResult<Vec<clap_complete::CompletionCandidate>> {
12871303
let output = std::process::Command::new("rustup")
12881304
.arg("target")

0 commit comments

Comments
 (0)