Skip to content

Commit c421e0b

Browse files
committed
refactor(cli): Align the two run's params
1 parent 2bd9f14 commit c421e0b

File tree

2 files changed

+20
-8
lines changed

2 files changed

+20
-8
lines changed

src/bin/cargo/cli.rs

Lines changed: 19 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -412,13 +412,6 @@ fn execute_subcommand(config: &mut Config, cmd: &str, subcommand_args: &ArgMatch
412412
return exec(config, subcommand_args);
413413
}
414414

415-
let mut ext_args: Vec<&OsStr> = vec![OsStr::new(cmd)];
416-
ext_args.extend(
417-
subcommand_args
418-
.get_many::<OsString>("")
419-
.unwrap_or_default()
420-
.map(OsString::as_os_str),
421-
);
422415
if commands::run::is_manifest_command(cmd) {
423416
let ext_path = super::find_external_subcommand(config, cmd);
424417
if !config.cli_unstable().script && ext_path.is_some() {
@@ -428,11 +421,30 @@ external subcommand `{cmd}` has the appearance of a manfiest-command
428421
This was previously accepted but will be phased out when `-Zscript` is stabilized.
429422
For more information, see issue #12207 <https://github.com/rust-lang/cargo/issues/12207>.",
430423
))?;
424+
let mut ext_args = vec![OsStr::new(cmd)];
425+
ext_args.extend(
426+
subcommand_args
427+
.get_many::<OsString>("")
428+
.unwrap_or_default()
429+
.map(OsString::as_os_str),
430+
);
431431
super::execute_external_subcommand(config, cmd, &ext_args)
432432
} else {
433+
let ext_args: Vec<OsString> = subcommand_args
434+
.get_many::<OsString>("")
435+
.unwrap_or_default()
436+
.cloned()
437+
.collect();
433438
commands::run::exec_manifest_command(config, cmd, &ext_args)
434439
}
435440
} else {
441+
let mut ext_args = vec![OsStr::new(cmd)];
442+
ext_args.extend(
443+
subcommand_args
444+
.get_many::<OsString>("")
445+
.unwrap_or_default()
446+
.map(OsString::as_os_str),
447+
);
436448
super::execute_external_subcommand(config, cmd, &ext_args)
437449
}
438450
}

src/bin/cargo/commands/run.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -89,7 +89,7 @@ pub fn is_manifest_command(arg: &str) -> bool {
8989
1 < path.components().count() || path.extension() == Some(OsStr::new("rs"))
9090
}
9191

92-
pub fn exec_manifest_command(config: &Config, cmd: &str, _args: &[&OsStr]) -> CliResult {
92+
pub fn exec_manifest_command(config: &Config, cmd: &str, _args: &[OsString]) -> CliResult {
9393
if !config.cli_unstable().script {
9494
return Err(anyhow::anyhow!("running `{cmd}` requires `-Zscript`").into());
9595
}

0 commit comments

Comments
 (0)