From 81374f6eac473d864dfa7097e7825021debce998 Mon Sep 17 00:00:00 2001 From: Bilal Khan Date: Sat, 25 Jan 2025 00:22:09 +0500 Subject: [PATCH] added the third_party_subcommands function in the cli.rs file --- src/bin/cargo/cli.rs | 7 +++++++ src/bin/cargo/main.rs | 2 +- 2 files changed, 8 insertions(+), 1 deletion(-) diff --git a/src/bin/cargo/cli.rs b/src/bin/cargo/cli.rs index aa72d7c1a3b..9fad3c87f09 100644 --- a/src/bin/cargo/cli.rs +++ b/src/bin/cargo/cli.rs @@ -15,6 +15,9 @@ use crate::command_prelude::*; use crate::util::is_rustup; use cargo::core::shell::ColorChoice; use cargo::util::style; +use crate::third_party_subcommands; +use clap_complete::engine::SubcommandCandidates; +use clap_complete::CompletionCandidate; #[tracing::instrument(skip_all)] pub fn main(gctx: &mut GlobalContext) -> CliResult { @@ -578,6 +581,10 @@ pub fn cli(gctx: &GlobalContext) -> Command { // We also want these to come before auto-generated `--help` .next_display_order(800) .allow_external_subcommands(true) + .add(SubcommandCandidates::new(|| { + let third_party = third_party_subcommands(gctx); + vec![CompletionCandidate::new(third_party)] + })) .color(color) .styles(styles) // Provide a custom help subcommand for calling into man pages diff --git a/src/bin/cargo/main.rs b/src/bin/cargo/main.rs index d36e8243f09..ae8893b48a4 100644 --- a/src/bin/cargo/main.rs +++ b/src/bin/cargo/main.rs @@ -219,7 +219,7 @@ fn list_commands(gctx: &GlobalContext) -> BTreeMap { commands } -fn third_party_subcommands(gctx: &GlobalContext) -> BTreeMap { +pub fn third_party_subcommands(gctx: &GlobalContext) -> BTreeMap { let prefix = "cargo-"; let suffix = env::consts::EXE_SUFFIX; let mut commands = BTreeMap::new();