|
1 | | -use std::process::Command; |
| 1 | +use semver::{BuildMetadata, Prerelease, Version}; |
| 2 | +use std::io::ErrorKind; |
| 3 | +use std::process::{Command, Stdio}; |
2 | 4 |
|
3 | | -pub fn check(_bad: &mut bool) { |
4 | | - let result = Command::new("x").arg("--version").output(); |
5 | | - let output = match result { |
6 | | - Ok(output) => output, |
7 | | - Err(_e) => todo!(), |
| 5 | +pub fn check(bad: &mut bool) { |
| 6 | + let result = Command::new("x") |
| 7 | + .arg("--version") |
| 8 | + .stdout(Stdio::piped()) |
| 9 | + .spawn(); |
| 10 | + let child = match result { |
| 11 | + Ok(child) => child, |
| 12 | + Err(e) => match e.kind() { |
| 13 | + ErrorKind::NotFound => return (), |
| 14 | + _ => return tidy_error!(bad, "{}", e), |
| 15 | + }, |
8 | 16 | }; |
9 | 17 |
|
| 18 | + let output = child.wait_with_output().unwrap(); |
| 19 | + |
10 | 20 | if output.status.success() { |
11 | 21 | let version = String::from_utf8_lossy(&output.stdout); |
12 | | - assert_eq!("0.1.0", version.trim_end()); |
| 22 | + let version = Version::parse(version.trim_end()).unwrap(); |
| 23 | + let expected = Version { |
| 24 | + major: 0, |
| 25 | + minor: 1, |
| 26 | + patch: 0, |
| 27 | + pre: Prerelease::new("").unwrap(), |
| 28 | + build: BuildMetadata::EMPTY, |
| 29 | + }; |
| 30 | + if version < expected { |
| 31 | + return tidy_error!(bad, "Current version of x is {version} Consider updating to the newer version of x by running `cargo install --path src/tools/x`"); |
| 32 | + } |
| 33 | + } else { |
| 34 | + return tidy_error!(bad, "{}", output.status); |
13 | 35 | } |
14 | | - // FIXME: throw some kind of tidy error when the version of x isn't |
15 | | - // greater than or equal to the version we'd expect. |
16 | | - //tidy_error!(bad, "Current version of x is {version} Consider updating to the newer version of x by running `cargo install --path src/tools/x`") |
17 | 36 | } |
0 commit comments