Skip to content

Commit af60e6c

Browse files
committed
Add object separator when using YAML output
1 parent 894d88d commit af60e6c

File tree

2 files changed

+21
-0
lines changed

2 files changed

+21
-0
lines changed

dsc/src/util.rs

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -208,6 +208,8 @@ pub fn get_schema(dsc_type: DscType) -> RootSchema {
208208
}
209209
}
210210

211+
static mut FIRST_WRITE: bool = true;
212+
211213
/// Write the output to the console
212214
///
213215
/// # Arguments
@@ -248,6 +250,11 @@ pub fn write_output(json: &str, format: Option<&OutputFormat>) {
248250
},
249251
Some(OutputFormat::Yaml) | None => {
250252
is_json = false;
253+
if !unsafe { FIRST_WRITE } {
254+
// include YAML document separator for subsequent outputs
255+
println!("---");
256+
}
257+
251258
let value: serde_json::Value = match serde_json::from_str(json) {
252259
Ok(value) => value,
253260
Err(err) => {
@@ -290,6 +297,10 @@ pub fn write_output(json: &str, format: Option<&OutputFormat>) {
290297
else {
291298
println!("{output}");
292299
}
300+
301+
unsafe {
302+
FIRST_WRITE = false;
303+
}
293304
}
294305

295306
#[allow(clippy::too_many_lines)]

dsc/tests/dsc_args.tests.ps1

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -91,6 +91,16 @@ actualState:
9191
$out.Trim() | Should -BeExactly $expected
9292
}
9393

94+
It 'YAML output includes object separator' {
95+
$out = dsc resource list -o yaml | Out-String
96+
foreach ($obj in $out.Split('---')) {
97+
$resource = $obj | y2j | ConvertFrom-Json
98+
$resource | Should -Not -BeNullOrEmpty
99+
$resource.Type | Should -BeLike '*/*'
100+
$resource.Kind | Should -BeIn ('Resource', 'Group', 'Importer', 'Adapter')
101+
}
102+
}
103+
94104
It 'can generate PowerShell completer' {
95105
$out = dsc completer powershell | Out-String
96106
Invoke-Expression $out

0 commit comments

Comments
 (0)