Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix progress display when using JSON, add None option; exhance progress schema #644

Open
wants to merge 11 commits into
base: main
Choose a base branch
from
Open
44 changes: 39 additions & 5 deletions dsc/Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion dsc/src/args.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
use clap::{Parser, Subcommand, ValueEnum};
use clap_complete::Shell;
use dsc_lib::dscresources::command_resource::TraceLevel;
use dsc_lib::util::ProgressFormat;
use dsc_lib::progress::ProgressFormat;
use rust_i18n::t;
use serde::Deserialize;

Expand Down
2 changes: 1 addition & 1 deletion dsc/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ use rust_i18n::{i18n, t};
use std::{io, process::exit};
use sysinfo::{Process, RefreshKind, System, get_current_pid, ProcessRefreshKind};
use tracing::{error, info, warn, debug};
use dsc_lib::util::ProgressFormat;
use dsc_lib::progress::ProgressFormat;

#[cfg(debug_assertions)]
use crossterm::event;
Expand Down
6 changes: 2 additions & 4 deletions dsc/src/subcommand.rs
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ use dsc_lib::{
},
dscresources::dscresource::{Capability, ImplementedAs, Invoke},
dscresources::resource_manifest::{import_manifest, ResourceManifest},
util::ProgressFormat,
progress::ProgressFormat,
};
use rust_i18n::t;
use std::{
Expand Down Expand Up @@ -288,16 +288,14 @@ pub fn config(subcommand: &ConfigSubCommand, parameters: &Option<String>, mounte
}
};

let mut configurator = match Configurator::new(&json_string) {
let mut configurator = match Configurator::new(&json_string, progress_format) {
Ok(configurator) => configurator,
Err(err) => {
error!("Error: {err}");
exit(EXIT_DSC_ERROR);
}
};

configurator.set_progress_format(progress_format);

if let ConfigSubCommand::Set { what_if , .. } = subcommand {
if *what_if {
configurator.context.execution_type = ExecutionKind::WhatIf;
Expand Down
6 changes: 6 additions & 0 deletions dsc/tests/dsc_args.tests.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -303,4 +303,10 @@ resources:
$LASTEXITCODE | Should -Be 1
"$TestDrive/tracing.txt" | Should -FileContentMatchExactly "Target path does not exist: '/invalid/path'"
}

It '--progress-format can be None' {
dsc -p none resource list 2> $TestDrive/tracing.txt
$LASTEXITCODE | Should -Be 0
(Get-Content $TestDrive/tracing.txt -Raw) | Should -BeNullOrEmpty
}
}
27 changes: 23 additions & 4 deletions dsc/tests/dsc_config_get.tests.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -60,23 +60,42 @@ Describe 'dsc config get tests' {
$config_yaml = @"
`$schema: https://raw.githubusercontent.com/PowerShell/DSC/main/schemas/2024/04/config/document.json
resources:
- name: Echo
- name: Echo 1
type: Microsoft.DSC.Debug/Echo
properties:
output: hello
- name: Echo 2
type: Microsoft.DSC.Debug/Echo
properties:
output: world
"@
$config_yaml | dsc --progress-format json config get -f - 2> $TestDrive/ErrorStream.txt
$LASTEXITCODE | Should -Be 0
$lines = Get-Content $TestDrive/ErrorStream.txt
$ProgressMessagesFound = $False
$ProgressMessagesFound = $false
$InstanceOneFound = $false
$InstanceTwoFound = $false
foreach ($line in $lines) {
$jp = $line | ConvertFrom-Json
if ($jp.activity) { # if line is a progress message
$jp.percent_complete | Should -BeIn (0..100)
$ProgressMessagesFound = $True
$jp.id | Should -Not -BeNullOrEmpty
$jp.percentComplete | Should -BeIn (0..100)
$ProgressMessagesFound = $true
}

if ($null -ne $jp.result -and $jp.resourceType -eq 'Microsoft.DSC.Debug/Echo') {
if ($jp.resourceName -eq 'Echo 1') {
$InstanceOneFound = $true
$jp.result.actualState.output | Should -BeExactly 'hello'
} elseif ($jp.resourceName -eq 'Echo 2') {
$InstanceTwoFound = $true
$jp.result.actualState.output | Should -BeExactly 'world'
}
}
}
$ProgressMessagesFound | Should -BeTrue
$InstanceOneFound | Should -BeTrue
$InstanceTwoFound | Should -BeTrue
}

It 'contentVersion is ignored' {
Expand Down
3 changes: 2 additions & 1 deletion dsc/tests/dsc_resource_list.tests.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,8 @@ Describe 'Tests for listing resources' {
foreach ($line in $lines) {
$jp = $line | ConvertFrom-Json
if ($jp.activity) { # if line is a progress message
$jp.percent_complete | Should -BeIn (0..100)
$jp.id | Should -Not -BeNullOrEmpty
$jp.percentComplete | Should -BeIn (0..100)
$ProgressMessagesFound = $True
}
}
Expand Down
8 changes: 6 additions & 2 deletions dsc_lib/Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions dsc_lib/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ tracing-indicatif = { version = "0.3" }
tree-sitter = "0.25"
tree-sitter-rust = "0.23"
tree-sitter-dscexpression = { path = "../tree-sitter-dscexpression" }
uuid = { version = "1.13", features = ["v4"] }

[dev-dependencies]
serde_yaml = "0.9"
Expand Down
3 changes: 3 additions & 0 deletions dsc_lib/locales/en-us.toml
Original file line number Diff line number Diff line change
Expand Up @@ -314,6 +314,9 @@ unknown = "Unknown"
validation = "Validation"
setting = "Setting"

[progress]
failedToSerialize = "Failed to serialize progress JSON: %{json}"

[util]
foundSetting = "Found setting '%{name}' in %{path}"
notFoundSetting = "Setting '%{name}' not found in %{path}"
Expand Down
Loading