Skip to content

Commit

Permalink
feat: Add custom completer for cargo help <TAB>
Browse files Browse the repository at this point in the history
  • Loading branch information
shannmu committed Sep 17, 2024
1 parent 25456ea commit ef028f7
Showing 1 changed file with 14 additions and 1 deletion.
15 changes: 14 additions & 1 deletion src/bin/cargo/commands/help.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,20 @@ 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(|| {
// TODO: Need a faster way to get all subcommand names.
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 ef028f7

Please sign in to comment.