From b514b1313cda4f0d34fb5ef81557a62f89edea58 Mon Sep 17 00:00:00 2001 From: hi-rustin Date: Mon, 19 Dec 2022 19:03:24 +0800 Subject: [PATCH 1/2] Show --help if there is no man page for subcommand Signed-off-by: hi-rustin --- src/bin/cargo/commands/help.rs | 20 +++++++++++++++----- src/bin/cargo/main.rs | 15 ++++++++++++++- 2 files changed, 29 insertions(+), 6 deletions(-) diff --git a/src/bin/cargo/commands/help.rs b/src/bin/cargo/commands/help.rs index 523268dbc19..2839b931e24 100644 --- a/src/bin/cargo/commands/help.rs +++ b/src/bin/cargo/commands/help.rs @@ -22,11 +22,21 @@ pub fn exec(config: &mut Config, args: &ArgMatches) -> CliResult { let subcommand = args.get_one::("COMMAND"); if let Some(subcommand) = subcommand { if !try_help(config, subcommand)? { - crate::execute_external_subcommand( - config, - subcommand, - &[OsStr::new(subcommand), OsStr::new("--help")], - )?; + match check_builtin(&subcommand) { + Some(s) => { + crate::execute_internal_subcommand( + config, + &[OsStr::new(s), OsStr::new("--help")], + )?; + } + None => { + crate::execute_external_subcommand( + config, + subcommand, + &[OsStr::new(subcommand), OsStr::new("--help")], + )?; + } + } } } else { let mut cmd = crate::cli::cli(); diff --git a/src/bin/cargo/main.rs b/src/bin/cargo/main.rs index aaac0d12610..ff691095187 100644 --- a/src/bin/cargo/main.rs +++ b/src/bin/cargo/main.rs @@ -189,9 +189,22 @@ fn execute_external_subcommand(config: &Config, cmd: &str, args: &[&OsStr]) -> C return Err(CliError::new(err, 101)); } }; + execute_subcommand(config, Some(&command), args) +} + +fn execute_internal_subcommand(config: &Config, args: &[&OsStr]) -> CliResult { + execute_subcommand(config, None, args) +} +// This function is used to execute a subcommand. It is used to execute both +// internal and external subcommands. +// If `cmd_path` is `None`, then the subcommand is an internal subcommand. +fn execute_subcommand(config: &Config, cmd_path: Option<&PathBuf>, args: &[&OsStr]) -> CliResult { let cargo_exe = config.cargo_exe()?; - let mut cmd = ProcessBuilder::new(&command); + let mut cmd = match cmd_path { + Some(cmd_path) => ProcessBuilder::new(cmd_path), + None => ProcessBuilder::new(&cargo_exe), + }; cmd.env(cargo::CARGO_ENV, cargo_exe).args(args); if let Some(client) = config.jobserver_from_env() { cmd.inherit_jobserver(client); From 53fd81552299d0c0a04bc5bfe682c868262d15b0 Mon Sep 17 00:00:00 2001 From: hi-rustin Date: Mon, 19 Dec 2022 19:04:38 +0800 Subject: [PATCH 2/2] Remove update help for config subcommand Signed-off-by: hi-rustin --- src/bin/cargo/commands/config.rs | 1 - 1 file changed, 1 deletion(-) diff --git a/src/bin/cargo/commands/config.rs b/src/bin/cargo/commands/config.rs index 87122d4282a..84c5e9209b8 100644 --- a/src/bin/cargo/commands/config.rs +++ b/src/bin/cargo/commands/config.rs @@ -4,7 +4,6 @@ use cargo::ops::cargo_config; pub fn cli() -> Command { subcommand("config") .about("Inspect configuration values") - .after_help("Run `cargo help config` for more detailed information.\n") .subcommand_required(true) .arg_required_else_help(true) .subcommand(