Skip to content

Commit f137aba

Browse files
committed
Auto merge of #14557 - shannmu:_cargo_cmds, r=epage
feat: Add custom completer for `cargo help <TAB>` ### What does this PR try to resolve? Tracking issue #14520 Add custom completer for `cargo help <TAB>` ### Additional information The current completer function is quite slow because it executes too many functions. One idea I have is to use the file!() macro to list the filenames under the commands directory, excluding mod.rs, and return them as the completion results. Would this approach be too hacky?
2 parents 0461165 + f64411c commit f137aba

File tree

1 file changed

+13
-1
lines changed

1 file changed

+13
-1
lines changed

src/bin/cargo/commands/help.rs

+13-1
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,19 @@ const COMPRESSED_MAN: &[u8] = include_bytes!(concat!(env!("OUT_DIR"), "/man.tgz"
1515
pub fn cli() -> Command {
1616
subcommand("help")
1717
.about("Displays help for a cargo subcommand")
18-
.arg(Arg::new("COMMAND").action(ArgAction::Set))
18+
.arg(Arg::new("COMMAND").action(ArgAction::Set).add(
19+
clap_complete::ArgValueCandidates::new(|| {
20+
super::builtin()
21+
.iter()
22+
.map(|cmd| {
23+
let name = cmd.get_name();
24+
clap_complete::CompletionCandidate::new(name)
25+
.help(cmd.get_about().cloned())
26+
.hide(cmd.is_hide_set())
27+
})
28+
.collect()
29+
}),
30+
))
1931
}
2032

2133
pub fn exec(gctx: &mut GlobalContext, args: &ArgMatches) -> CliResult {

0 commit comments

Comments
 (0)