Skip to content
Merged
Changes from 1 commit
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
Prev Previous commit
Next Next commit
refactor(help): move alias expansion out from try_help
  • Loading branch information
weihanglo committed Feb 12, 2026
commit db87b6ce45176d2db61bd9af3f071c15d31c4dd4
39 changes: 20 additions & 19 deletions src/bin/cargo/commands/help.rs
Original file line number Diff line number Diff line change
Expand Up @@ -36,29 +36,13 @@ pub fn exec(gctx: &mut GlobalContext, args: &ArgMatches) -> CliResult {
return Ok(());
};

if try_help(gctx, subcommand)? {
return Ok(());
}

if super::builtin_exec(subcommand).is_some() {
crate::execute_internal_subcommand(gctx, &[OsStr::new(subcommand), OsStr::new("--help")])?;
} else {
crate::execute_external_subcommand(
gctx,
subcommand,
&[OsStr::new(subcommand), OsStr::new("--help")],
)?;
}
Ok(())
}

fn try_help(gctx: &GlobalContext, subcommand: &str) -> CargoResult<bool> {
let subcommand = &match aliased_command(gctx, subcommand).ok().flatten() {
// Expand alias first
let subcommand = match aliased_command(gctx, subcommand).ok().flatten() {
// If this alias is more than a simple subcommand pass-through, show the alias.
Some(argv) if argv.len() > 1 => {
let alias = argv.join(" ");
drop_println!(gctx, "`{}` is aliased to `{}`", subcommand, alias);
return Ok(true);
return Ok(());
}
// Otherwise, resolve the alias into its subcommand.
Some(argv) => {
Expand All @@ -69,6 +53,23 @@ fn try_help(gctx: &GlobalContext, subcommand: &str) -> CargoResult<bool> {
None => subcommand.to_string(),
};

if try_help(&subcommand)? {
return Ok(());
}

if super::builtin_exec(&subcommand).is_some() {
crate::execute_internal_subcommand(gctx, &[OsStr::new(&subcommand), OsStr::new("--help")])?;
} else {
crate::execute_external_subcommand(
gctx,
&subcommand,
&[OsStr::new(&subcommand), OsStr::new("--help")],
)?;
}
Ok(())
}

fn try_help(subcommand: &str) -> CargoResult<bool> {
if super::builtin_exec(subcommand).is_none() {
Comment thread
epage marked this conversation as resolved.
Outdated
return Ok(false);
}
Expand Down