Skip to content

Commit 3ca2dca

Browse files
committed
refactor(cli): Align the two run's params
1 parent 3bf87ee commit 3ca2dca

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() {
@@ -429,11 +422,30 @@ This was previously accepted but will be phased out when `-Zscript` is stabilize
429422
For more information, see issue #12207 <https://github.com/rust-lang/cargo/issues/12207>.",
430423
cmd,
431424
))?;
425+
let mut ext_args: Vec<&OsStr> = vec![OsStr::new(cmd)];
426+
ext_args.extend(
427+
subcommand_args
428+
.get_many::<OsString>("")
429+
.unwrap_or_default()
430+
.map(OsString::as_os_str),
431+
);
432432
super::execute_external_subcommand(config, cmd, &ext_args)
433433
} else {
434+
let ext_args: Vec<OsString> = subcommand_args
435+
.get_many::<OsString>("")
436+
.unwrap_or_default()
437+
.cloned()
438+
.collect();
434439
return commands::run::exec_manifest_command(config, cmd, &ext_args);
435440
}
436441
} else {
442+
let mut ext_args: Vec<&OsStr> = vec![OsStr::new(cmd)];
443+
ext_args.extend(
444+
subcommand_args
445+
.get_many::<OsString>("")
446+
.unwrap_or_default()
447+
.map(OsString::as_os_str),
448+
);
437449
super::execute_external_subcommand(config, cmd, &ext_args)
438450
}
439451
}

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)