Skip to content
Merged
Show file tree
Hide file tree
Changes from 4 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 22 additions & 1 deletion osinfo/src/config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
// Licensed under the MIT License.

use serde::Serialize;
use std::fmt::Display;
use std::string::ToString;

/// Returns information about the operating system.
Expand All @@ -24,6 +25,8 @@ pub struct OsInfo {
/// Defines the processor architecture as reported by `uname -m` on the operating system.
#[serde(skip_serializing_if = "Option::is_none")]
architecture: Option<String>,
#[serde(rename = "_name", skip_serializing_if = "Option::is_none")]
name: Option<String>,
}

/// Defines whether the operating system is a 32-bit or 64-bit operating system.
Expand All @@ -46,6 +49,16 @@ pub enum Family {
Windows,
}

impl Display for Family {
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
match self {
Family::Linux => write!(f, "Linux"),
Family::MacOS => write!(f, "macOS"),
Family::Windows => write!(f, "Windows"),
}
}
}

const ID: &str = "https://developer.microsoft.com/json-schemas/dsc/os_info/20230303/Microsoft.Dsc.OS_Info.schema.json";

impl OsInfo {
Expand All @@ -64,14 +77,22 @@ impl OsInfo {
os_info::Bitness::X64 => Bitness::Bit64,
_ => Bitness::Unknown,
};
let version = os_info.version().to_string();
let name = Some(
match &architecture {
Some(arch) => format!("{family} {version} {arch}"),
None => format!("{family:?} {version}"),
}
);
Self {
id: ID.to_string(),
family,
version: os_info.version().to_string(),
version,
edition,
codename,
bitness: bits,
architecture,
name,
}
}
}
1 change: 1 addition & 0 deletions osinfo/tests/osinfo.tests.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -52,5 +52,6 @@ Describe 'osinfo resource tests' {
elseif ($IsMacOS) {
$out.resources[0].properties.family | Should -BeExactly 'macOS'
}
$out.resources[0].name | Should -BeExactly "$($out.resources[0].properties.family) $($out.resources[0].properties.version) $($out.resources[0].properties.architecture)"
}
}
Loading