| 47 | |
| 48 | impl OsInfo { |
| 49 | pub fn new(include_name: bool) -> Self { |
| 50 | let os_info = os_info::get(); |
| 51 | let edition = os_info.edition().map(ToString::to_string); |
| 52 | let codename = os_info.codename().map(ToString::to_string); |
| 53 | let architecture = os_info.architecture().map(ToString::to_string); |
| 54 | let family = match os_info.os_type() { |
| 55 | os_info::Type::Macos => Family::MacOS, |
| 56 | os_info::Type::Windows => Family::Windows, |
| 57 | _ => Family::Linux, |
| 58 | }; |
| 59 | let bits = match os_info.bitness() { |
| 60 | os_info::Bitness::X32 => Some(32), |
| 61 | os_info::Bitness::X64 => Some(64), |
| 62 | _ => None, |
| 63 | }; |
| 64 | let version = os_info.version().to_string(); |
| 65 | let name = if include_name { |
| 66 | Some( |
| 67 | match &architecture { |
| 68 | Some(arch) => format!("{family} {version} {arch}"), |
| 69 | None => format!("{family:?} {version}"), |
| 70 | } |
| 71 | ) |
| 72 | } else { |
| 73 | None |
| 74 | }; |
| 75 | Self { |
| 76 | family, |
| 77 | version, |
| 78 | edition, |
| 79 | codename, |
| 80 | bitness: bits, |
| 81 | architecture, |
| 82 | name, |
| 83 | } |
| 84 | } |
| 85 | } |