Skip to content

Commit 1cea458

Browse files
committed
feat: Add custom completer for cargo +<TAB> to complete toolchain name
1 parent 611b7c4 commit 1cea458

File tree

1 file changed

+23
-0
lines changed

1 file changed

+23
-0
lines changed

src/bin/cargo/cli.rs

+23
Original file line numberDiff line numberDiff line change
@@ -691,9 +691,32 @@ See '<cyan,bold>cargo help</> <cyan><<command>></>' for more information on a sp
691691
}))
692692
}).collect()
693693
})))
694+
.add(clap_complete::engine::SubcommandCandidates::new(|| {
695+
get_toolchains_from_rustup()
696+
.into_iter()
697+
.map(|t| clap_complete::CompletionCandidate::new(t))
698+
.collect()
699+
}))
694700
.subcommands(commands::builtin())
695701
}
696702

703+
fn get_toolchains_from_rustup() -> Vec<String> {
704+
let output = std::process::Command::new("rustup")
705+
.arg("toolchain")
706+
.arg("list")
707+
.arg("-q")
708+
.output()
709+
.unwrap();
710+
711+
if !output.status.success() {
712+
return vec![];
713+
}
714+
715+
let stdout = String::from_utf8(output.stdout).unwrap();
716+
717+
stdout.lines().map(|line| format!("+{}", line)).collect()
718+
}
719+
697720
#[test]
698721
fn verify_cli() {
699722
let gctx = GlobalContext::default().unwrap();

0 commit comments

Comments
 (0)