Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Show --help if there is no man page for subcommand #11473

Merged
merged 2 commits into from
Dec 19, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 0 additions & 1 deletion src/bin/cargo/commands/config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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")
epage marked this conversation as resolved.
Show resolved Hide resolved
.subcommand_required(true)
.arg_required_else_help(true)
.subcommand(
Expand Down
20 changes: 15 additions & 5 deletions src/bin/cargo/commands/help.rs
Original file line number Diff line number Diff line change
Expand Up @@ -22,11 +22,21 @@ pub fn exec(config: &mut Config, args: &ArgMatches) -> CliResult {
let subcommand = args.get_one::<String>("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")],
)?;
epage marked this conversation as resolved.
Show resolved Hide resolved
}
None => {
crate::execute_external_subcommand(
config,
subcommand,
&[OsStr::new(subcommand), OsStr::new("--help")],
)?;
}
}
}
} else {
let mut cmd = crate::cli::cli();
Expand Down
15 changes: 14 additions & 1 deletion src/bin/cargo/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Rustin170506 marked this conversation as resolved.
Show resolved Hide resolved
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);
Expand Down