mirror of
https://github.com/rust-lang/cargo.git
synced 2025-10-01 11:30:39 +00:00
feat: Add custom completer for cargo +<TAB> to complete toolchain name
This commit is contained in:
parent
611b7c4ee4
commit
1cea458703
@ -691,9 +691,32 @@ See '<cyan,bold>cargo help</> <cyan><<command>></>' for more information on a sp
|
||||
}))
|
||||
}).collect()
|
||||
})))
|
||||
.add(clap_complete::engine::SubcommandCandidates::new(|| {
|
||||
get_toolchains_from_rustup()
|
||||
.into_iter()
|
||||
.map(|t| clap_complete::CompletionCandidate::new(t))
|
||||
.collect()
|
||||
}))
|
||||
.subcommands(commands::builtin())
|
||||
}
|
||||
|
||||
fn get_toolchains_from_rustup() -> Vec<String> {
|
||||
let output = std::process::Command::new("rustup")
|
||||
.arg("toolchain")
|
||||
.arg("list")
|
||||
.arg("-q")
|
||||
.output()
|
||||
.unwrap();
|
||||
|
||||
if !output.status.success() {
|
||||
return vec![];
|
||||
}
|
||||
|
||||
let stdout = String::from_utf8(output.stdout).unwrap();
|
||||
|
||||
stdout.lines().map(|line| format!("+{}", line)).collect()
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn verify_cli() {
|
||||
let gctx = GlobalContext::default().unwrap();
|
||||
|
Loading…
x
Reference in New Issue
Block a user