Skip to content

Commit

Permalink
Use Command::args with arrays
Browse files Browse the repository at this point in the history
  • Loading branch information
dullbananas committed Jun 6, 2023
1 parent 04fb5a1 commit 31751f8
Show file tree
Hide file tree
Showing 9 changed files with 18 additions and 27 deletions.
1 change: 1 addition & 0 deletions rust
Submodule rust added at ca6b00
9 changes: 3 additions & 6 deletions src/bindgen.rs
Original file line number Diff line number Diff line change
Expand Up @@ -57,10 +57,7 @@ pub fn wasm_bindgen_build(
.binary(&Tool::WasmBindgen.to_string())?;

let mut cmd = Command::new(&bindgen_path);
cmd.arg(&wasm_path)
.arg("--out-dir")
.arg(out_dir)
.arg(dts_arg);
cmd.arg(&wasm_path).args(["--out-dir", out_dir, dts_arg]);

if weak_refs {
cmd.arg("--weak-refs");
Expand All @@ -72,13 +69,13 @@ pub fn wasm_bindgen_build(

let target_arg = build_target_arg(target, &bindgen_path)?;
if supports_dash_dash_target(&bindgen_path)? {
cmd.arg("--target").arg(target_arg);
cmd.args(["--target", &target_arg]);
} else {
cmd.arg(target_arg);
}

if let Some(value) = out_name {
cmd.arg("--out-name").arg(value);
cmd.args(["--out-name", &value]);
}

let profile = data.configured_profile(profile);
Expand Down
9 changes: 4 additions & 5 deletions src/build/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,8 @@ pub fn cargo_build_wasm(
PBAR.info(&msg);

let mut cmd = Command::new("cargo");
cmd.current_dir(path).arg("build").arg("--lib");
cmd.current_dir(path)
.args(["build", "--lib", "--target", "wasm32-unknown-unknown"]);

if PBAR.quiet() {
cmd.arg("--quiet");
Expand All @@ -106,7 +107,6 @@ pub fn cargo_build_wasm(
}
}

cmd.arg("--target").arg("wasm32-unknown-unknown");
cmd.args(extra_options);
child::run(cmd, "cargo build").context("Compiling your crate to WebAssembly failed")?;
Ok(())
Expand All @@ -128,7 +128,8 @@ pub fn cargo_build_wasm(
pub fn cargo_build_wasm_tests(path: &Path, debug: bool, extra_options: &[String]) -> Result<()> {
let mut cmd = Command::new("cargo");

cmd.current_dir(path).arg("build").arg("--tests");
cmd.current_dir(path)
.args(["build", "--tests", "--target", "wasm32-unknown-unknown"]);

if PBAR.quiet() {
cmd.arg("--quiet");
Expand All @@ -138,8 +139,6 @@ pub fn cargo_build_wasm_tests(path: &Path, debug: bool, extra_options: &[String]
cmd.arg("--release");
}

cmd.arg("--target").arg("wasm32-unknown-unknown");

cmd.args(extra_options);

child::run(cmd, "cargo build").context("Compilation of your program failed")?;
Expand Down
2 changes: 1 addition & 1 deletion src/build/wasm_target.rs
Original file line number Diff line number Diff line change
Expand Up @@ -134,7 +134,7 @@ fn check_wasm32_target() -> Result<Wasm32Check> {
/// Add wasm32-unknown-unknown using `rustup`.
fn rustup_add_wasm_target() -> Result<()> {
let mut cmd = Command::new("rustup");
cmd.arg("target").arg("add").arg("wasm32-unknown-unknown");
cmd.args(["target", "add", "wasm32-unknown-unknown"]);
child::run(cmd, "rustup").context("Adding the wasm32-unknown-unknown target with rustup")?;

Ok(())
Expand Down
2 changes: 1 addition & 1 deletion src/child.rs
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ pub fn new_command(program: &str) -> Command {

if cfg!(windows) {
let mut cmd = Command::new("cmd");
cmd.arg("/c").arg(program);
cmd.args(["/c", program]);
cmd
} else {
Command::new(program)
Expand Down
4 changes: 1 addition & 3 deletions src/generate.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,7 @@ pub fn generate(template: &str, name: &str, install_status: &install::Status) ->
let bin_path = install::get_tool_path(install_status, Tool::CargoGenerate)?
.binary(&Tool::CargoGenerate.to_string())?;
let mut cmd = Command::new(&bin_path);
cmd.arg("generate");
cmd.arg("--git").arg(&template);
cmd.arg("--name").arg(&name);
cmd.args(["generate", "--git", template, "--name", name]);

println!(
"{} Generating a new rustwasm project with name '{}'...",
Expand Down
9 changes: 3 additions & 6 deletions src/install/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -253,14 +253,11 @@ pub fn cargo_install(
};
let mut cmd = Command::new("cargo");

cmd.arg("install")
.arg("--force")
.arg(crate_name)
.arg("--root")
.arg(&tmp);
cmd.args(["install", "--force", &crate_name, "--root"]);
cmd.arg(&tmp);

if version != "latest" {
cmd.arg("--version").arg(version);
cmd.args(["--version", version]);
}

let context = format!("Installing {} with cargo", tool);
Expand Down
4 changes: 2 additions & 2 deletions src/npm.rs
Original file line number Diff line number Diff line change
Expand Up @@ -20,11 +20,11 @@ pub fn npm_pack(path: &str) -> Result<()> {
pub fn npm_publish(path: &str, access: Option<Access>, tag: Option<String>) -> Result<()> {
let mut cmd = child::new_command("npm");
match access {
Some(a) => cmd.current_dir(path).arg("publish").arg(&a.to_string()),
Some(a) => cmd.current_dir(path).args(["publish", &a.to_string()]),
None => cmd.current_dir(path).arg("publish"),
};
if let Some(tag) = tag {
cmd.arg("--tag").arg(tag);
cmd.args(["--tag", &tag]);
};

child::run(cmd, "npm publish").context("Publishing to npm failed")?;
Expand Down
5 changes: 2 additions & 3 deletions src/test/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,8 @@ where
let mut cmd = Command::new("cargo");

cmd.envs(envs);
cmd.current_dir(path).arg("test");
cmd.current_dir(path)
.args(["test", "--target", "wasm32-unknown-unknown"]);

if PBAR.quiet() {
cmd.arg("--quiet");
Expand All @@ -35,8 +36,6 @@ where
cmd.arg("--release");
}

cmd.arg("--target").arg("wasm32-unknown-unknown");

cmd.args(extra_options);

child::run(cmd, "cargo test").context("Running Wasm tests with wasm-bindgen-test failed")?;
Expand Down

0 comments on commit 31751f8

Please sign in to comment.