Skip to content

Commit af3403e

Browse files
authored
Merge pull request #318 from SteveL-MSFT/config-result
Enable group resource output schema to simplify config output that uses groups
2 parents 31f7e17 + c8075a1 commit af3403e

19 files changed

+691
-204
lines changed

dsc/assertion.dsc.resource.json

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,14 +7,17 @@
77
"executable": "dsc",
88
"args": [
99
"config",
10-
"test"
10+
"--as-group",
11+
"test",
12+
"--as-get"
1113
],
1214
"input": "stdin"
1315
},
1416
"set": {
1517
"executable": "dsc",
1618
"args": [
1719
"config",
20+
"--as-group",
1821
"test"
1922
],
2023
"input": "stdin",
@@ -25,7 +28,9 @@
2528
"executable": "dsc",
2629
"args": [
2730
"config",
28-
"test"
31+
"--as-group",
32+
"test",
33+
"--as-get"
2934
],
3035
"input": "stdin",
3136
"return": "state"

dsc/examples/brew.dsc.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ resources:
99
- name: os_check
1010
type: Microsoft/OSInfo
1111
properties:
12-
family: MacOS
12+
family: macOS
1313
- name: brew
1414
type: DSC.PackageManagement/Brew
1515
properties:

dsc/examples/groups.dsc.yaml

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
# Example for grouping and groups in groups
2+
$schema: https://raw.githubusercontent.com/PowerShell/DSC/main/schemas/2023/08/config/document.json
3+
resources:
4+
- name: Last Group
5+
type: DSC/Group
6+
properties:
7+
$schema: https://raw.githubusercontent.com/PowerShell/DSC/main/schemas/2023/08/config/document.json
8+
resources:
9+
- name: Last
10+
type: Test/Echo
11+
properties:
12+
output: Last
13+
dependsOn:
14+
- "[resourceId('DSC/Group','First Group')]"
15+
- name: First Group
16+
type: DSC/Group
17+
properties:
18+
$schema: https://raw.githubusercontent.com/PowerShell/DSC/main/schemas/2023/08/config/document.json
19+
resources:
20+
- name: First
21+
type: Test/Echo
22+
properties:
23+
output: First
24+
- name: Nested Group
25+
type: DSC/Group
26+
properties:
27+
$schema: https://raw.githubusercontent.com/PowerShell/DSC/main/schemas/2023/08/config/document.json
28+
resources:
29+
- name: Nested Second
30+
type: Test/Echo
31+
properties:
32+
output: Nested Second
33+
dependsOn:
34+
- "[resourceId('Test/Echo','Nested First')]"
35+
- name: Nested First
36+
type: Test/Echo
37+
properties:
38+
output: Nested First

dsc/group.dsc.resource.json

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
"executable": "dsc",
88
"args": [
99
"config",
10+
"--as-group",
1011
"get"
1112
],
1213
"input": "stdin"
@@ -15,6 +16,7 @@
1516
"executable": "dsc",
1617
"args": [
1718
"config",
19+
"--as-group",
1820
"set"
1921
],
2022
"input": "stdin",
@@ -25,6 +27,7 @@
2527
"executable": "dsc",
2628
"args": [
2729
"config",
30+
"--as-group",
2831
"test"
2932
],
3033
"input": "stdin",

dsc/parallel.dsc.resource.json

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
"args": [
99
"config",
1010
"--parallel",
11+
"--as-group",
1112
"get"
1213
],
1314
"input": "stdin"
@@ -17,6 +18,7 @@
1718
"args": [
1819
"config",
1920
"--parallel",
21+
"--as-group",
2022
"set"
2123
],
2224
"input": "stdin",
@@ -28,6 +30,7 @@
2830
"args": [
2931
"config",
3032
"--parallel",
33+
"--as-group",
3134
"test"
3235
],
3336
"input": "stdin",

dsc/src/args.rs

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,8 @@ pub enum SubCommand {
5454
parameters: Option<String>,
5555
#[clap(short = 'f', long, help = "Parameters to pass to the configuration as a JSON or YAML file", conflicts_with = "parameters")]
5656
parameters_file: Option<String>,
57+
#[clap(long, hide = true)]
58+
as_group: bool,
5759
},
5860
#[clap(name = "resource", about = "Invoke a specific DSC resource")]
5961
Resource {
@@ -97,13 +99,17 @@ pub enum ConfigSubCommand {
9799
path: Option<String>,
98100
#[clap(short = 'f', long, help = "The output format to use")]
99101
format: Option<OutputFormat>,
102+
#[clap(long, hide = true)]
103+
as_get: bool,
100104
},
101105
#[clap(name = "validate", about = "Validate the current configuration", hide = true)]
102106
Validate {
103107
#[clap(short = 'd', long, help = "The document to pass to the configuration or resource", conflicts_with = "path")]
104108
document: Option<String>,
105109
#[clap(short = 'p', long, help = "The path to a file used as input to the configuration or resource", conflicts_with = "document")]
106110
path: Option<String>,
111+
#[clap(short = 'f', long, help = "The output format to use")]
112+
format: Option<OutputFormat>,
107113
},
108114
#[clap(name = "export", about = "Export the current configuration")]
109115
Export {

dsc/src/main.rs

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -65,19 +65,19 @@ fn main() {
6565
let mut cmd = Args::command();
6666
generate(shell, &mut cmd, "dsc", &mut io::stdout());
6767
},
68-
SubCommand::Config { subcommand, parameters, parameters_file } => {
68+
SubCommand::Config { subcommand, parameters, parameters_file, as_group } => {
6969
if let Some(file_name) = parameters_file {
7070
info!("Reading parameters from file {}", file_name);
7171
match std::fs::read_to_string(file_name) {
72-
Ok(parameters) => subcommand::config(&subcommand, &Some(parameters), &input),
72+
Ok(parameters) => subcommand::config(&subcommand, &Some(parameters), &input, &as_group),
7373
Err(err) => {
7474
error!("Error: Failed to read parameters file: {err}");
7575
exit(util::EXIT_INVALID_INPUT);
7676
}
7777
}
7878
}
7979
else {
80-
subcommand::config(&subcommand, &parameters, &input);
80+
subcommand::config(&subcommand, &parameters, &input, &as_group);
8181
}
8282
},
8383
SubCommand::Resource { subcommand } => {
@@ -136,7 +136,13 @@ fn check_debug() {
136136
if env::var("DEBUG_DSC").is_ok() {
137137
eprintln!("attach debugger to pid {} and press a key to continue", std::process::id());
138138
loop {
139-
let event = event::read().unwrap();
139+
let event = match event::read() {
140+
Ok(event) => event,
141+
Err(err) => {
142+
eprintln!("Error: Failed to read event: {err}");
143+
break;
144+
}
145+
};
140146
if let event::Event::Key(key) = event {
141147
// workaround bug in 0.26+ https://github.com/crossterm-rs/crossterm/issues/752#issuecomment-1414909095
142148
if key.kind == event::KeyEventKind::Press {

dsc/src/resource_command.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ use crate::args::OutputFormat;
55
use crate::util::{EXIT_DSC_ERROR, EXIT_INVALID_ARGS, EXIT_JSON_ERROR, add_type_name_to_json, write_output};
66
use dsc_lib::configure::config_doc::Configuration;
77
use dsc_lib::configure::add_resource_export_results_to_configuration;
8-
use dsc_lib::dscresources::invoke_result::GetResult;
8+
use dsc_lib::dscresources::invoke_result::{GetResult, ResourceGetResponse};
99
use dsc_lib::dscerror::DscError;
1010
use tracing::{error, debug};
1111

@@ -79,9 +79,9 @@ pub fn get_all(dsc: &DscManager, resource_type: &str, format: &Option<OutputForm
7979

8080
for instance in export_result.actual_state
8181
{
82-
let get_result = GetResult {
82+
let get_result = GetResult::Resource(ResourceGetResponse {
8383
actual_state: instance.clone(),
84-
};
84+
});
8585

8686
let json = match serde_json::to_string(&get_result) {
8787
Ok(json) => json,

0 commit comments

Comments
 (0)