mirror of
https://github.com/rust-lang/cargo.git
synced 2025-09-28 11:20:36 +00:00
refactor(cli): Pull out completion context creation
This commit is contained in:
parent
6d221efc4d
commit
09a472e32b
@ -703,7 +703,9 @@ See '<bright-cyan,bold>cargo help</> <cyan><<command>></>' for more information
|
|||||||
.into_iter()
|
.into_iter()
|
||||||
.map(|t| clap_complete::CompletionCandidate::new(t))
|
.map(|t| clap_complete::CompletionCandidate::new(t))
|
||||||
.collect::<Vec<_>>();
|
.collect::<Vec<_>>();
|
||||||
candidates.extend(get_alias_candidates());
|
if let Ok(gctx) = new_gctx_for_completions() {
|
||||||
|
candidates.extend(get_alias_candidates(&gctx));
|
||||||
|
}
|
||||||
candidates
|
candidates
|
||||||
}))
|
}))
|
||||||
.subcommands(commands::builtin())
|
.subcommands(commands::builtin())
|
||||||
@ -726,10 +728,9 @@ fn get_toolchains_from_rustup() -> Vec<String> {
|
|||||||
stdout.lines().map(|line| format!("+{}", line)).collect()
|
stdout.lines().map(|line| format!("+{}", line)).collect()
|
||||||
}
|
}
|
||||||
|
|
||||||
fn get_alias_candidates() -> Vec<clap_complete::CompletionCandidate> {
|
fn get_alias_candidates(gctx: &GlobalContext) -> Vec<clap_complete::CompletionCandidate> {
|
||||||
if let Ok(gctx) = new_gctx_for_completions() {
|
let alias_map = user_defined_aliases(gctx);
|
||||||
let alias_map = user_defined_aliases(&gctx);
|
alias_map
|
||||||
return alias_map
|
|
||||||
.iter()
|
.iter()
|
||||||
.map(|(alias, cmd_info)| {
|
.map(|(alias, cmd_info)| {
|
||||||
let help_text = match cmd_info {
|
let help_text = match cmd_info {
|
||||||
@ -750,9 +751,7 @@ fn get_alias_candidates() -> Vec<clap_complete::CompletionCandidate> {
|
|||||||
};
|
};
|
||||||
clap_complete::CompletionCandidate::new(alias.clone()).help(Some(help_text.into()))
|
clap_complete::CompletionCandidate::new(alias.clone()).help(Some(help_text.into()))
|
||||||
})
|
})
|
||||||
.collect();
|
.collect()
|
||||||
}
|
|
||||||
Vec::new()
|
|
||||||
}
|
}
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
|
Loading…
x
Reference in New Issue
Block a user