blob: 4b2181fc2348d687c17c9823bca45770dd0ef9c4 (
plain)
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
|
mod command;
use command::command_stdout_lossy;
pub fn version() -> String {
let version = run_sw_vers().unwrap_or(String::from("N/A"));
format!("macOS {}", version)
}
pub fn short_version() -> String {
let version = run_sw_vers()
.and_then(parse_short_version_output)
.map(|(major, minor)| format!("{}.{}", major, minor))
.unwrap_or(String::from("N/A"));
format!("macOS {}", version)
}
pub fn extra_metadata() -> impl Iterator<Item = (String, String)> {
std::iter::empty()
}
/// Outputs a string in a format `$major.$minor.$patch`, e.g. `11.0.1`
fn run_sw_vers() -> Option<String> {
command_stdout_lossy("sw_vers", &["-productVersion"])
}
fn parse_short_version_output(output: String) -> Option<(u32, u32)> {
let mut parts = output.split('.');
let major = parts.next()?.parse().ok()?;
let minor = parts.next()?.parse().ok()?;
Some((major, minor))
}
|