@@ -50,7 +50,7 @@ pub fn invoke_get(resource: &ResourceManifest, cwd: &str, filter: &str) -> Resul
50
50
let Some ( get) = & resource. get else {
51
51
return Err ( DscError :: NotImplemented ( "get" . to_string ( ) ) ) ;
52
52
} ;
53
- let args = process_args ( & get. args , filter) ;
53
+ let args = process_args ( & get. args , filter, & ExecutionKind :: Actual ) ;
54
54
if !filter. is_empty ( ) {
55
55
verify_json ( resource, cwd, filter) ?;
56
56
command_input = get_command_input ( & get. input , filter) ?;
@@ -105,7 +105,7 @@ pub fn invoke_set(resource: &ResourceManifest, cwd: &str, desired: &str, skip_te
105
105
if !skip_test && set. pre_test != Some ( true ) {
106
106
info ! ( "No pretest, invoking test {}" , & resource. resource_type) ;
107
107
let test_result = invoke_test ( resource, cwd, desired) ?;
108
- if execution_type == & ExecutionKind :: WhatIf && set . handles_what_if != Some ( true ) {
108
+ if execution_type == & ExecutionKind :: WhatIfDSC {
109
109
return Ok ( test_result. into ( ) ) ;
110
110
}
111
111
let ( in_desired_state, actual_state) = match test_result {
@@ -130,14 +130,14 @@ pub fn invoke_set(resource: &ResourceManifest, cwd: &str, desired: &str, skip_te
130
130
}
131
131
}
132
132
133
- if ExecutionKind :: WhatIf == * execution_type && set . handles_what_if != Some ( true ) {
133
+ if ExecutionKind :: WhatIfDSC == * execution_type {
134
134
return Err ( DscError :: NotImplemented ( "cannot process what-if execution type, resource does not implement what-if or pre-test" . to_string ( ) ) ) ;
135
135
}
136
136
137
137
let Some ( get) = & resource. get else {
138
138
return Err ( DscError :: NotImplemented ( "get" . to_string ( ) ) ) ;
139
139
} ;
140
- let args = process_args ( & get. args , desired) ;
140
+ let args = process_args ( & get. args , desired, & ExecutionKind :: Actual ) ;
141
141
let command_input = get_command_input ( & get. input , desired) ?;
142
142
143
143
info ! ( "Getting current state for set by invoking get {} using {}" , & resource. resource_type, & get. executable) ;
@@ -157,16 +157,7 @@ pub fn invoke_set(resource: &ResourceManifest, cwd: &str, desired: &str, skip_te
157
157
158
158
let mut env: Option < HashMap < String , String > > = None ;
159
159
let mut input_desired: Option < & str > = None ;
160
- let mut args = process_args ( & set. args , desired) ;
161
- if ExecutionKind :: WhatIf == * execution_type {
162
- if let Some ( mut arguments) = args {
163
- arguments. push ( "--what-if" . to_string ( ) ) ;
164
- args = Some ( arguments) ;
165
- }
166
- else {
167
- args = Some ( vec ! [ "--what-if" . to_string( ) ] ) ;
168
- }
169
- }
160
+ let args = process_args ( & set. args , desired, execution_type) ;
170
161
match & set. input {
171
162
Some ( InputKind :: Env ) => {
172
163
env = Some ( json_to_hashmap ( desired) ?) ;
@@ -269,7 +260,7 @@ pub fn invoke_test(resource: &ResourceManifest, cwd: &str, expected: &str) -> Re
269
260
270
261
verify_json ( resource, cwd, expected) ?;
271
262
272
- let args = process_args ( & test. args , expected) ;
263
+ let args = process_args ( & test. args , expected, & ExecutionKind :: Actual ) ;
273
264
let command_input = get_command_input ( & test. input , expected) ?;
274
265
275
266
info ! ( "Invoking test '{}' using '{}'" , & resource. resource_type, & test. executable) ;
@@ -383,7 +374,7 @@ pub fn invoke_delete(resource: &ResourceManifest, cwd: &str, filter: &str) -> Re
383
374
384
375
verify_json ( resource, cwd, filter) ?;
385
376
386
- let args = process_args ( & delete. args , filter) ;
377
+ let args = process_args ( & delete. args , filter, & ExecutionKind :: Actual ) ;
387
378
let command_input = get_command_input ( & delete. input , filter) ?;
388
379
389
380
info ! ( "Invoking delete '{}' using '{}'" , & resource. resource_type, & delete. executable) ;
@@ -414,7 +405,7 @@ pub fn invoke_validate(resource: &ResourceManifest, cwd: &str, config: &str) ->
414
405
return Err ( DscError :: NotImplemented ( "validate" . to_string ( ) ) ) ;
415
406
} ;
416
407
417
- let args = process_args ( & validate. args , config) ;
408
+ let args = process_args ( & validate. args , config, & ExecutionKind :: Actual ) ;
418
409
let command_input = get_command_input ( & validate. input , config) ?;
419
410
420
411
info ! ( "Invoking validate '{}' using '{}'" , & resource. resource_type, & validate. executable) ;
@@ -489,9 +480,9 @@ pub fn invoke_export(resource: &ResourceManifest, cwd: &str, input: Option<&str>
489
480
command_input = get_command_input ( & export. input , input) ?;
490
481
}
491
482
492
- args = process_args ( & export. args , input) ;
483
+ args = process_args ( & export. args , input, & ExecutionKind :: Actual ) ;
493
484
} else {
494
- args = process_args ( & export. args , "" ) ;
485
+ args = process_args ( & export. args , "" , & ExecutionKind :: Actual ) ;
495
486
}
496
487
497
488
let ( _exit_code, stdout, stderr) = invoke_command ( & export. executable , args, command_input. stdin . as_deref ( ) , Some ( cwd) , command_input. env ) ?;
@@ -536,7 +527,7 @@ pub fn invoke_resolve(resource: &ResourceManifest, cwd: &str, input: &str) -> Re
536
527
return Err ( DscError :: Operation ( format ! ( "Resolve is not supported by resource {}" , & resource. resource_type) ) ) ;
537
528
} ;
538
529
539
- let args = process_args ( & resolve. args , input) ;
530
+ let args = process_args ( & resolve. args , input, & ExecutionKind :: Actual ) ;
540
531
let command_input = get_command_input ( & resolve. input , input) ?;
541
532
542
533
info ! ( "Invoking resolve '{}' using '{}'" , & resource. resource_type, & resolve. executable) ;
@@ -628,7 +619,7 @@ pub fn invoke_command(executable: &str, args: Option<Vec<String>>, input: Option
628
619
Ok ( ( exit_code, stdout, cleaned_stderr) )
629
620
}
630
621
631
- fn process_args ( args : & Option < Vec < ArgKind > > , value : & str ) -> Option < Vec < String > > {
622
+ fn process_args ( args : & Option < Vec < ArgKind > > , value : & str , execution_type : & ExecutionKind ) -> Option < Vec < String > > {
632
623
let Some ( arg_values) = args else {
633
624
debug ! ( "No args to process" ) ;
634
625
return None ;
@@ -648,6 +639,11 @@ fn process_args(args: &Option<Vec<ArgKind>>, value: &str) -> Option<Vec<String>>
648
639
processed_args. push ( json_input_arg. clone ( ) ) ;
649
640
processed_args. push ( value. to_string ( ) ) ;
650
641
} ,
642
+ ArgKind :: WhatIf { what_if_input_arg} => {
643
+ if execution_type == & ExecutionKind :: WhatIfResource {
644
+ processed_args. push ( what_if_input_arg. clone ( ) ) ;
645
+ }
646
+ }
651
647
}
652
648
}
653
649
0 commit comments