Skip to content

Commit

Permalink
Auto merge of #14557 - shannmu:_cargo_cmds, r=epage
Browse files Browse the repository at this point in the history
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?
  • Loading branch information
bors committed Sep 18, 2024
2 parents 0461165 + f64411c commit f137aba
Showing 1 changed file with 13 additions and 1 deletion.
14 changes: 13 additions & 1 deletion src/bin/cargo/commands/help.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,19 @@ const COMPRESSED_MAN: &[u8] = include_bytes!(concat!(env!("OUT_DIR"), "/man.tgz"
pub fn cli() -> Command {
subcommand("help")
.about("Displays help for a cargo subcommand")
.arg(Arg::new("COMMAND").action(ArgAction::Set))
.arg(Arg::new("COMMAND").action(ArgAction::Set).add(
clap_complete::ArgValueCandidates::new(|| {
super::builtin()
.iter()
.map(|cmd| {
let name = cmd.get_name();
clap_complete::CompletionCandidate::new(name)
.help(cmd.get_about().cloned())
.hide(cmd.is_hide_set())
})
.collect()
}),
))
}

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

0 comments on commit f137aba

Please sign in to comment.