Skip to content

Commit 6ab160b

Browse files
committed
Auto merge of #11473 - hi-rustin:rustin-patch-help, r=epage
Show `--help` if there is no man page for subcommand
2 parents c994a4a + 53fd815 commit 6ab160b

File tree

3 files changed

+29
-7
lines changed

3 files changed

+29
-7
lines changed

src/bin/cargo/commands/config.rs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@ use cargo::ops::cargo_config;
44
pub fn cli() -> Command {
55
subcommand("config")
66
.about("Inspect configuration values")
7-
.after_help("Run `cargo help config` for more detailed information.\n")
87
.subcommand_required(true)
98
.arg_required_else_help(true)
109
.subcommand(

src/bin/cargo/commands/help.rs

Lines changed: 15 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -22,11 +22,21 @@ pub fn exec(config: &mut Config, args: &ArgMatches) -> CliResult {
2222
let subcommand = args.get_one::<String>("COMMAND");
2323
if let Some(subcommand) = subcommand {
2424
if !try_help(config, subcommand)? {
25-
crate::execute_external_subcommand(
26-
config,
27-
subcommand,
28-
&[OsStr::new(subcommand), OsStr::new("--help")],
29-
)?;
25+
match check_builtin(&subcommand) {
26+
Some(s) => {
27+
crate::execute_internal_subcommand(
28+
config,
29+
&[OsStr::new(s), OsStr::new("--help")],
30+
)?;
31+
}
32+
None => {
33+
crate::execute_external_subcommand(
34+
config,
35+
subcommand,
36+
&[OsStr::new(subcommand), OsStr::new("--help")],
37+
)?;
38+
}
39+
}
3040
}
3141
} else {
3242
let mut cmd = crate::cli::cli();

src/bin/cargo/main.rs

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -189,9 +189,22 @@ fn execute_external_subcommand(config: &Config, cmd: &str, args: &[&OsStr]) -> C
189189
return Err(CliError::new(err, 101));
190190
}
191191
};
192+
execute_subcommand(config, Some(&command), args)
193+
}
194+
195+
fn execute_internal_subcommand(config: &Config, args: &[&OsStr]) -> CliResult {
196+
execute_subcommand(config, None, args)
197+
}
192198

199+
// This function is used to execute a subcommand. It is used to execute both
200+
// internal and external subcommands.
201+
// If `cmd_path` is `None`, then the subcommand is an internal subcommand.
202+
fn execute_subcommand(config: &Config, cmd_path: Option<&PathBuf>, args: &[&OsStr]) -> CliResult {
193203
let cargo_exe = config.cargo_exe()?;
194-
let mut cmd = ProcessBuilder::new(&command);
204+
let mut cmd = match cmd_path {
205+
Some(cmd_path) => ProcessBuilder::new(cmd_path),
206+
None => ProcessBuilder::new(&cargo_exe),
207+
};
195208
cmd.env(cargo::CARGO_ENV, cargo_exe).args(args);
196209
if let Some(client) = config.jobserver_from_env() {
197210
cmd.inherit_jobserver(client);

0 commit comments

Comments
 (0)