mirror of
https://github.com/rust-lang/cargo.git
synced 2025-10-01 11:30:39 +00:00
Show --help if there is no man page for subcommand
Signed-off-by: hi-rustin <rustin.liu@gmail.com>
This commit is contained in:
parent
c994a4a638
commit
b514b1313c
@ -22,11 +22,21 @@ pub fn exec(config: &mut Config, args: &ArgMatches) -> CliResult {
|
|||||||
let subcommand = args.get_one::<String>("COMMAND");
|
let subcommand = args.get_one::<String>("COMMAND");
|
||||||
if let Some(subcommand) = subcommand {
|
if let Some(subcommand) = subcommand {
|
||||||
if !try_help(config, subcommand)? {
|
if !try_help(config, subcommand)? {
|
||||||
crate::execute_external_subcommand(
|
match check_builtin(&subcommand) {
|
||||||
config,
|
Some(s) => {
|
||||||
subcommand,
|
crate::execute_internal_subcommand(
|
||||||
&[OsStr::new(subcommand), OsStr::new("--help")],
|
config,
|
||||||
)?;
|
&[OsStr::new(s), OsStr::new("--help")],
|
||||||
|
)?;
|
||||||
|
}
|
||||||
|
None => {
|
||||||
|
crate::execute_external_subcommand(
|
||||||
|
config,
|
||||||
|
subcommand,
|
||||||
|
&[OsStr::new(subcommand), OsStr::new("--help")],
|
||||||
|
)?;
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
let mut cmd = crate::cli::cli();
|
let mut cmd = crate::cli::cli();
|
||||||
|
@ -189,9 +189,22 @@ fn execute_external_subcommand(config: &Config, cmd: &str, args: &[&OsStr]) -> C
|
|||||||
return Err(CliError::new(err, 101));
|
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 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);
|
cmd.env(cargo::CARGO_ENV, cargo_exe).args(args);
|
||||||
if let Some(client) = config.jobserver_from_env() {
|
if let Some(client) = config.jobserver_from_env() {
|
||||||
cmd.inherit_jobserver(client);
|
cmd.inherit_jobserver(client);
|
||||||
|
Loading…
x
Reference in New Issue
Block a user