Skip to content

Commit 4cb9d28

Browse files
committed
Use an enum instead of strings
1 parent ebf1dfc commit 4cb9d28

File tree

1 file changed

+14
-11
lines changed

1 file changed

+14
-11
lines changed

src/main.rs

Lines changed: 14 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -483,10 +483,8 @@ fn try_main() -> MainResult<i32> {
483483
#[cfg(unix)]
484484
{
485485
if action.execute {
486-
let cmd_name = action.build_kind.exec_command();
487-
info!("running `cargo {}`", cmd_name);
488486
let run_quietly = !action.cargo_output;
489-
let mut cmd = action.cargo(cmd_name, &args.script_args, run_quietly)?;
487+
let mut cmd = action.cargo(action.build_kind, &args.script_args, run_quietly)?;
490488

491489
let err = cmd.exec();
492490
Err(MainError::from(err))
@@ -716,9 +714,14 @@ impl InputAction {
716714
self.pkg_path.join("Cargo.toml")
717715
}
718716

719-
fn cargo(&self, cmd: &str, script_args: &[String], run_quietly: bool) -> MainResult<Command> {
717+
fn cargo(
718+
&self,
719+
build_kind: BuildKind,
720+
script_args: &[String],
721+
run_quietly: bool,
722+
) -> MainResult<Command> {
720723
cargo(
721-
cmd,
724+
build_kind,
722725
&*self.manifest_path().to_string_lossy(),
723726
self.toolchain_version.as_deref(),
724727
&self.metadata,
@@ -803,7 +806,7 @@ fn decide_action_for(
803806
Input::File(_, path, _, mtime) => {
804807
(Some(path.to_string_lossy().into_owned()), Some(mtime))
805808
}
806-
_ => (None, None)
809+
_ => (None, None),
807810
};
808811
PackageMetadata {
809812
path,
@@ -1162,7 +1165,7 @@ where
11621165
Constructs a Cargo command that runs on the script package.
11631166
*/
11641167
fn cargo(
1165-
cmd_name: &str,
1168+
build_kind: BuildKind,
11661169
manifest: &str,
11671170
maybe_toolchain_version: Option<&str>,
11681171
meta: &PackageMetadata,
@@ -1173,9 +1176,9 @@ fn cargo(
11731176
if let Some(toolchain_version) = maybe_toolchain_version {
11741177
cmd.arg(format!("+{}", toolchain_version));
11751178
}
1176-
cmd.arg(cmd_name);
1179+
cmd.arg(build_kind.exec_command());
11771180

1178-
if cmd_name == "run" && run_quietly {
1181+
if matches!(build_kind, BuildKind::Normal) && run_quietly {
11791182
cmd.arg("-q");
11801183
}
11811184

@@ -1190,15 +1193,15 @@ fn cargo(
11901193
cmd.arg(cargo_target_dir);
11911194

11921195
// Block `--release` on `bench`.
1193-
if !meta.debug && cmd_name != "bench" {
1196+
if !meta.debug && !matches!(build_kind, BuildKind::Bench) {
11941197
cmd.arg("--release");
11951198
}
11961199

11971200
if let Some(ref features) = meta.features {
11981201
cmd.arg("--features").arg(features);
11991202
}
12001203

1201-
if cmd_name == "run" && !script_args.is_empty() {
1204+
if matches!(build_kind, BuildKind::Normal) && !script_args.is_empty() {
12021205
cmd.arg("--");
12031206
cmd.args(script_args.iter());
12041207
}

0 commit comments

Comments
 (0)