Skip to content

Commit

Permalink
refactor(cli): Align the two run's params
Browse files Browse the repository at this point in the history
  • Loading branch information
epage committed Jun 9, 2023
1 parent 222d768 commit 9b5ba08
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 8 deletions.
26 changes: 19 additions & 7 deletions src/bin/cargo/cli.rs
Original file line number Diff line number Diff line change
Expand Up @@ -412,13 +412,6 @@ fn execute_subcommand(config: &mut Config, cmd: &str, subcommand_args: &ArgMatch
return exec(config, subcommand_args);
}

let mut ext_args: Vec<&OsStr> = vec![OsStr::new(cmd)];
ext_args.extend(
subcommand_args
.get_many::<OsString>("")
.unwrap_or_default()
.map(OsString::as_os_str),
);
if commands::run::is_manifest_command(cmd) {
let ext_path = super::find_external_subcommand(config, cmd);
if !config.cli_unstable().script && ext_path.is_some() {
Expand All @@ -429,11 +422,30 @@ This was previously accepted but will be phased out when `-Zscript` is stabilize
For more information, see issue #12207 <https://github.com/rust-lang/cargo/issues/12207>.",
cmd,
))?;
let mut ext_args: Vec<&OsStr> = vec![OsStr::new(cmd)];
ext_args.extend(
subcommand_args
.get_many::<OsString>("")
.unwrap_or_default()
.map(OsString::as_os_str),
);
super::execute_external_subcommand(config, cmd, &ext_args)
} else {
let ext_args: Vec<OsString> = subcommand_args
.get_many::<OsString>("")
.unwrap_or_default()
.cloned()
.collect();
return commands::run::exec_manifest_command(config, cmd, &ext_args);
}
} else {
let mut ext_args: Vec<&OsStr> = vec![OsStr::new(cmd)];
ext_args.extend(
subcommand_args
.get_many::<OsString>("")
.unwrap_or_default()
.map(OsString::as_os_str),
);
super::execute_external_subcommand(config, cmd, &ext_args)
}
}
Expand Down
2 changes: 1 addition & 1 deletion src/bin/cargo/commands/run.rs
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,7 @@ pub fn is_manifest_command(arg: &str) -> bool {
1 < path.components().count() || path.extension() == Some(OsStr::new("rs"))
}

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

0 comments on commit 9b5ba08

Please sign in to comment.