Skip to content

Commit 08f19a9

Browse files
author
Steve Lee (POWERSHELL HE/HIM) (from Dev Box)
committed
have only export return _name
1 parent 3157dfd commit 08f19a9

File tree

4 files changed

+24
-9
lines changed

4 files changed

+24
-9
lines changed

osinfo/osinfo.dsc.resource.json

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,10 @@
1313
"executable": "osinfo"
1414
},
1515
"export": {
16-
"executable": "osinfo"
16+
"executable": "osinfo",
17+
"args": [
18+
"export"
19+
]
1720
},
1821
"schema": {
1922
"embedded": {

osinfo/src/config.rs

Lines changed: 11 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,7 @@ impl Display for Family {
6262
const ID: &str = "https://developer.microsoft.com/json-schemas/dsc/os_info/20230303/Microsoft.Dsc.OS_Info.schema.json";
6363

6464
impl OsInfo {
65-
pub fn new() -> Self {
65+
pub fn new(include_name: bool) -> Self {
6666
let os_info = os_info::get();
6767
let edition = os_info.edition().map(ToString::to_string);
6868
let codename = os_info.codename().map(ToString::to_string);
@@ -78,12 +78,16 @@ impl OsInfo {
7878
_ => Bitness::Unknown,
7979
};
8080
let version = os_info.version().to_string();
81-
let name = Some(
82-
match &architecture {
83-
Some(arch) => format!("{family} {version} {arch}"),
84-
None => format!("{family:?} {version}"),
85-
}
86-
);
81+
let name = if include_name {
82+
Some(
83+
match &architecture {
84+
Some(arch) => format!("{family} {version} {arch}"),
85+
None => format!("{family:?} {version}"),
86+
}
87+
)
88+
} else {
89+
None
90+
};
8791
Self {
8892
id: ID.to_string(),
8993
family,

osinfo/src/main.rs

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,12 @@
44
mod config;
55

66
fn main() {
7-
let json = serde_json::to_string(&config::OsInfo::new()).unwrap();
7+
let args: Vec<String> = std::env::args().collect();
8+
let include_name = if args.len() > 1 && args[1] == "export" {
9+
true
10+
} else {
11+
false
12+
};
13+
let json = serde_json::to_string(&config::OsInfo::new(include_name)).unwrap();
814
println!("{json}");
915
}

osinfo/tests/osinfo.tests.ps1

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,8 @@ Describe 'osinfo resource tests' {
2222
else {
2323
$out.actualState.bitness | Should -BeExactly '32'
2424
}
25+
26+
$out._name | Should -BeNullOrEmpty
2527
}
2628

2729
It 'should perform synthetic test' {

0 commit comments

Comments
 (0)