1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
use crate::{Command, CommandExt};
use std::io;
#[cfg(feature = "version")]
#[cfg_attr(doc_cfg, doc(cfg(feature = "version")))]
pub fn version() -> io::Result<crate::Version> {
Command::new("wasm-bindgen").arg("--version").stdout0()?.parse()
}
#[cfg(feature = "version")]
#[cfg_attr(doc_cfg, doc(cfg(feature = "version")))]
pub fn install_at_least(requested: &str) -> io::Result<()> {
let requested = semver::Version::parse(requested).map_err(|err| io::Error::new(io::ErrorKind::InvalidInput, err))?;
if let Ok(installed) = version() {
if requested <= installed.version { return Ok(()); }
}
Command::new("cargo").arg("install").arg("--version").arg(format!("^{}", requested)).arg("wasm-bindgen-cli").status0()
}