feat(install): break out get cli version function

master
Ashley Williams 6 years ago
parent c293720fe1
commit 22a63ea86f
  1. 32
      src/install/mod.rs

@ -75,24 +75,24 @@ pub fn check_version(
expected_version.to_string() expected_version.to_string()
}; };
let v = get_cli_version(tool, path)?;
info!(
"Checking installed `{}` version == expected version: {} == {}",
tool, v, &expected_version
);
Ok(v == expected_version)
}
/// Fetches the version of a CLI tool
pub fn get_cli_version(tool: &Tool, path: &PathBuf) -> Result<String, failure::Error> {
let mut cmd = Command::new(path); let mut cmd = Command::new(path);
cmd.arg("--version"); cmd.arg("--version");
child::run_capture_stdout(cmd, tool) let stdout = child::run_capture_stdout(cmd, tool)?;
.map(|stdout| { let version = stdout.trim().split_whitespace().nth(1);
stdout match version {
.trim() Some(v) => Ok(v.to_string()),
.split_whitespace() None => bail!("Something went wrong! We couldn't determine your version of the wasm-bindgen CLI. We were supposed to set that up for you, so it's likely not your fault! You should file an issue: https://github.com/rustwasm/wasm-pack/issues/new?template=bug_report.md.")
.nth(1) }
.map(|v| {
info!(
"Checking installed `{}` version == expected version: {} == {}",
tool, v, &expected_version
);
Ok(v == expected_version)
})
.unwrap_or(Ok(false))
})
.unwrap_or(Ok(false))
} }
/// Downloads a precompiled copy of the tool, if available. /// Downloads a precompiled copy of the tool, if available.

Loading…
Cancel
Save