Skip to content

Commit fa666b8

Browse files
committed
Fix progress display when using JSON, add None option; exhance progress schema
1 parent 7fe6eb5 commit fa666b8

File tree

18 files changed

+323
-193
lines changed

18 files changed

+323
-193
lines changed

dsc/Cargo.lock

Lines changed: 39 additions & 5 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

dsc/src/args.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
use clap::{Parser, Subcommand, ValueEnum};
55
use clap_complete::Shell;
66
use dsc_lib::dscresources::command_resource::TraceLevel;
7-
use dsc_lib::util::ProgressFormat;
7+
use dsc_lib::progress::ProgressFormat;
88
use rust_i18n::t;
99
use serde::Deserialize;
1010

dsc/src/main.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ use rust_i18n::{i18n, t};
88
use std::{io, process::exit};
99
use sysinfo::{Process, RefreshKind, System, get_current_pid, ProcessRefreshKind};
1010
use tracing::{error, info, warn, debug};
11-
use dsc_lib::util::ProgressFormat;
11+
use dsc_lib::progress::ProgressFormat;
1212

1313
#[cfg(debug_assertions)]
1414
use crossterm::event;

dsc/src/subcommand.rs

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ use dsc_lib::{
2525
},
2626
dscresources::dscresource::{Capability, ImplementedAs, Invoke},
2727
dscresources::resource_manifest::{import_manifest, ResourceManifest},
28-
util::ProgressFormat,
28+
progress::ProgressFormat,
2929
};
3030
use rust_i18n::t;
3131
use std::{
@@ -288,16 +288,14 @@ pub fn config(subcommand: &ConfigSubCommand, parameters: &Option<String>, mounte
288288
}
289289
};
290290

291-
let mut configurator = match Configurator::new(&json_string) {
291+
let mut configurator = match Configurator::new(&json_string, progress_format) {
292292
Ok(configurator) => configurator,
293293
Err(err) => {
294294
error!("Error: {err}");
295295
exit(EXIT_DSC_ERROR);
296296
}
297297
};
298298

299-
configurator.set_progress_format(progress_format);
300-
301299
if let ConfigSubCommand::Set { what_if , .. } = subcommand {
302300
if *what_if {
303301
configurator.context.execution_type = ExecutionKind::WhatIf;

dsc/tests/dsc_args.tests.ps1

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -303,4 +303,10 @@ resources:
303303
$LASTEXITCODE | Should -Be 1
304304
"$TestDrive/tracing.txt" | Should -FileContentMatchExactly "Target path does not exist: '/invalid/path'"
305305
}
306+
307+
It '--progress-format can be None' {
308+
dsc -p none resource list 2> $TestDrive/tracing.txt
309+
$LASTEXITCODE | Should -Be 0
310+
(Get-Content $TestDrive/tracing.txt -Raw) | Should -BeNullOrEmpty
311+
}
306312
}

dsc/tests/dsc_config_get.tests.ps1

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -68,15 +68,25 @@ Describe 'dsc config get tests' {
6868
$config_yaml | dsc --progress-format json config get -f - 2> $TestDrive/ErrorStream.txt
6969
$LASTEXITCODE | Should -Be 0
7070
$lines = Get-Content $TestDrive/ErrorStream.txt
71-
$ProgressMessagesFound = $False
71+
$ProgressMessagesFound = $false
72+
$ProgressResultFound = $false
7273
foreach ($line in $lines) {
7374
$jp = $line | ConvertFrom-Json
7475
if ($jp.activity) { # if line is a progress message
76+
$jp.id | Should -Not -BeNullOrEmpty
7577
$jp.percent_complete | Should -BeIn (0..100)
76-
$ProgressMessagesFound = $True
78+
$ProgressMessagesFound = $true
79+
}
80+
81+
if ($jp.percent_complete -eq 100 -and $jp.resourceType -eq 'Microsoft.DSC.Debug/Echo') {
82+
$ProgressResultFound = $true
83+
$jp.resourceName | Should -BeExactly 'Echo'
84+
$jp.result | Should -Not -BeNullOrEmpty
85+
$jp.result.output | Should -BeExactly 'hello'
7786
}
7887
}
7988
$ProgressMessagesFound | Should -BeTrue
89+
$ProgressResultFound | Should -BeTrue
8090
}
8191

8292
It 'contentVersion is ignored' {

dsc/tests/dsc_resource_list.tests.ps1

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -66,6 +66,7 @@ Describe 'Tests for listing resources' {
6666
foreach ($line in $lines) {
6767
$jp = $line | ConvertFrom-Json
6868
if ($jp.activity) { # if line is a progress message
69+
$jp.id | Should -Not -BeNullOrEmpty
6970
$jp.percent_complete | Should -BeIn (0..100)
7071
$ProgressMessagesFound = $True
7172
}

dsc_lib/Cargo.lock

Lines changed: 6 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

dsc_lib/Cargo.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,7 @@ tracing-indicatif = { version = "0.3" }
3535
tree-sitter = "0.25"
3636
tree-sitter-rust = "0.23"
3737
tree-sitter-dscexpression = { path = "../tree-sitter-dscexpression" }
38+
uuid = { version = "1.13", features = ["v4"] }
3839

3940
[dev-dependencies]
4041
serde_yaml = "0.9"

dsc_lib/locales/en-us.toml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -314,6 +314,9 @@ unknown = "Unknown"
314314
validation = "Validation"
315315
setting = "Setting"
316316

317+
[progress]
318+
failedToSerialize = "Failed to serialize progress JSON: %{json}"
319+
317320
[util]
318321
foundSetting = "Found setting '%{name}' in %{path}"
319322
notFoundSetting = "Setting '%{name}' not found in %{path}"

0 commit comments

Comments
 (0)