2
2
// Licensed under the MIT License.
3
3
4
4
use crate :: args:: OutputFormat ;
5
- use crate :: util:: { EXIT_DSC_ERROR , EXIT_INVALID_ARGS , EXIT_JSON_ERROR , EXIT_DSC_RESOURCE_NOT_FOUND , add_type_name_to_json , write_object} ;
5
+ use crate :: util:: { EXIT_DSC_ERROR , EXIT_INVALID_ARGS , EXIT_JSON_ERROR , EXIT_DSC_RESOURCE_NOT_FOUND , write_object} ;
6
6
use dsc_lib:: configure:: config_doc:: { Configuration , ExecutionKind } ;
7
7
use dsc_lib:: configure:: add_resource_export_results_to_configuration;
8
8
use dsc_lib:: dscresources:: { resource_manifest:: Kind , invoke_result:: { GetResult , ResourceGetResponse } } ;
@@ -16,8 +16,8 @@ use dsc_lib::{
16
16
} ;
17
17
use std:: process:: exit;
18
18
19
- pub fn get ( dsc : & DscManager , resource_type : & str , mut input : String , format : Option < & OutputFormat > ) {
20
- let Some ( mut resource) = get_resource ( dsc, resource_type) else {
19
+ pub fn get ( dsc : & DscManager , resource_type : & str , input : & str , format : Option < & OutputFormat > ) {
20
+ let Some ( resource) = get_resource ( dsc, resource_type) else {
21
21
error ! ( "{}" , DscError :: ResourceNotFound ( resource_type. to_string( ) ) . to_string( ) ) ;
22
22
exit ( EXIT_DSC_RESOURCE_NOT_FOUND ) ;
23
23
} ;
@@ -28,17 +28,7 @@ pub fn get(dsc: &DscManager, resource_type: &str, mut input: String, format: Opt
28
28
exit ( EXIT_DSC_ERROR ) ;
29
29
}
30
30
31
- if let Some ( requires) = & resource. require_adapter {
32
- input = add_type_name_to_json ( input, resource. type_name . clone ( ) ) ;
33
- if let Some ( pr) = get_resource ( dsc, requires) {
34
- resource = pr;
35
- } else {
36
- error ! ( "{}: {requires}" , t!( "resource_command.adapterNotFound" ) ) ;
37
- return ;
38
- } ;
39
- }
40
-
41
- match resource. get ( input. as_str ( ) ) {
31
+ match resource. get ( input) {
42
32
Ok ( result) => {
43
33
// convert to json
44
34
let json = match serde_json:: to_string ( & result) {
@@ -58,8 +48,8 @@ pub fn get(dsc: &DscManager, resource_type: &str, mut input: String, format: Opt
58
48
}
59
49
60
50
pub fn get_all ( dsc : & DscManager , resource_type : & str , format : Option < & OutputFormat > ) {
61
- let mut input = String :: new ( ) ;
62
- let Some ( mut resource) = get_resource ( dsc, resource_type) else {
51
+ let input = String :: new ( ) ;
52
+ let Some ( resource) = get_resource ( dsc, resource_type) else {
63
53
error ! ( "{}" , DscError :: ResourceNotFound ( resource_type. to_string( ) ) . to_string( ) ) ;
64
54
exit ( EXIT_DSC_RESOURCE_NOT_FOUND ) ;
65
55
} ;
@@ -70,16 +60,6 @@ pub fn get_all(dsc: &DscManager, resource_type: &str, format: Option<&OutputForm
70
60
exit ( EXIT_DSC_ERROR ) ;
71
61
}
72
62
73
- if let Some ( requires) = & resource. require_adapter {
74
- input = add_type_name_to_json ( input, resource. type_name . clone ( ) ) ;
75
- if let Some ( pr) = get_resource ( dsc, requires) {
76
- resource = pr;
77
- } else {
78
- error ! ( "{}: {requires}" , t!( "resource_command.adapterNotFound" ) ) ;
79
- return ;
80
- } ;
81
- }
82
-
83
63
let export_result = match resource. export ( & input) {
84
64
Ok ( export) => { export }
85
65
Err ( err) => {
@@ -107,13 +87,13 @@ pub fn get_all(dsc: &DscManager, resource_type: &str, format: Option<&OutputForm
107
87
}
108
88
}
109
89
110
- pub fn set ( dsc : & DscManager , resource_type : & str , mut input : String , format : Option < & OutputFormat > ) {
90
+ pub fn set ( dsc : & DscManager , resource_type : & str , input : & str , format : Option < & OutputFormat > ) {
111
91
if input. is_empty ( ) {
112
92
error ! ( "{}" , t!( "resource_command.setInputEmpty" ) ) ;
113
93
exit ( EXIT_INVALID_ARGS ) ;
114
94
}
115
95
116
- let Some ( mut resource) = get_resource ( dsc, resource_type) else {
96
+ let Some ( resource) = get_resource ( dsc, resource_type) else {
117
97
error ! ( "{}" , DscError :: ResourceNotFound ( resource_type. to_string( ) ) . to_string( ) ) ;
118
98
exit ( EXIT_DSC_RESOURCE_NOT_FOUND ) ;
119
99
} ;
@@ -124,17 +104,7 @@ pub fn set(dsc: &DscManager, resource_type: &str, mut input: String, format: Opt
124
104
exit ( EXIT_DSC_ERROR ) ;
125
105
}
126
106
127
- if let Some ( requires) = & resource. require_adapter {
128
- input = add_type_name_to_json ( input, resource. type_name . clone ( ) ) ;
129
- if let Some ( pr) = get_resource ( dsc, requires) {
130
- resource = pr;
131
- } else {
132
- error ! ( "{}: {requires}" , t!( "resource_command.adapterNotFound" ) ) ;
133
- return ;
134
- } ;
135
- }
136
-
137
- match resource. set ( input. as_str ( ) , true , & ExecutionKind :: Actual ) {
107
+ match resource. set ( input, true , & ExecutionKind :: Actual ) {
138
108
Ok ( result) => {
139
109
// convert to json
140
110
let json = match serde_json:: to_string ( & result) {
@@ -153,13 +123,13 @@ pub fn set(dsc: &DscManager, resource_type: &str, mut input: String, format: Opt
153
123
}
154
124
}
155
125
156
- pub fn test ( dsc : & DscManager , resource_type : & str , mut input : String , format : Option < & OutputFormat > ) {
126
+ pub fn test ( dsc : & DscManager , resource_type : & str , input : & str , format : Option < & OutputFormat > ) {
157
127
if input. is_empty ( ) {
158
128
error ! ( "{}" , t!( "resource_command.testInputEmpty" ) ) ;
159
129
exit ( EXIT_INVALID_ARGS ) ;
160
130
}
161
131
162
- let Some ( mut resource) = get_resource ( dsc, resource_type) else {
132
+ let Some ( resource) = get_resource ( dsc, resource_type) else {
163
133
error ! ( "{}" , DscError :: ResourceNotFound ( resource_type. to_string( ) ) . to_string( ) ) ;
164
134
exit ( EXIT_DSC_RESOURCE_NOT_FOUND ) ;
165
135
} ;
@@ -170,17 +140,7 @@ pub fn test(dsc: &DscManager, resource_type: &str, mut input: String, format: Op
170
140
exit ( EXIT_DSC_ERROR ) ;
171
141
}
172
142
173
- if let Some ( requires) = & resource. require_adapter {
174
- input = add_type_name_to_json ( input, resource. type_name . clone ( ) ) ;
175
- if let Some ( pr) = get_resource ( dsc, requires) {
176
- resource = pr;
177
- } else {
178
- error ! ( "{}: {requires}" , t!( "resource_command.adapterNotFound" ) ) ;
179
- return ;
180
- } ;
181
- }
182
-
183
- match resource. test ( input. as_str ( ) ) {
143
+ match resource. test ( input) {
184
144
Ok ( result) => {
185
145
// convert to json
186
146
let json = match serde_json:: to_string ( & result) {
@@ -199,8 +159,8 @@ pub fn test(dsc: &DscManager, resource_type: &str, mut input: String, format: Op
199
159
}
200
160
}
201
161
202
- pub fn delete ( dsc : & DscManager , resource_type : & str , mut input : String ) {
203
- let Some ( mut resource) = get_resource ( dsc, resource_type) else {
162
+ pub fn delete ( dsc : & DscManager , resource_type : & str , input : & str ) {
163
+ let Some ( resource) = get_resource ( dsc, resource_type) else {
204
164
error ! ( "{}" , DscError :: ResourceNotFound ( resource_type. to_string( ) ) . to_string( ) ) ;
205
165
exit ( EXIT_DSC_RESOURCE_NOT_FOUND ) ;
206
166
} ;
@@ -211,17 +171,7 @@ pub fn delete(dsc: &DscManager, resource_type: &str, mut input: String) {
211
171
exit ( EXIT_DSC_ERROR ) ;
212
172
}
213
173
214
- if let Some ( requires) = & resource. require_adapter {
215
- input = add_type_name_to_json ( input, resource. type_name . clone ( ) ) ;
216
- if let Some ( pr) = get_resource ( dsc, requires) {
217
- resource = pr;
218
- } else {
219
- error ! ( "{}: {requires}" , t!( "resource_command.adapterNotFound" ) ) ;
220
- return ;
221
- } ;
222
- }
223
-
224
- match resource. delete ( input. as_str ( ) ) {
174
+ match resource. delete ( input) {
225
175
Ok ( ( ) ) => { }
226
176
Err ( err) => {
227
177
error ! ( "Error: {err}" ) ;
@@ -259,7 +209,7 @@ pub fn schema(dsc: &DscManager, resource_type: &str, format: Option<&OutputForma
259
209
}
260
210
}
261
211
262
- pub fn export ( dsc : & mut DscManager , resource_type : & str , mut input : String , format : Option < & OutputFormat > ) {
212
+ pub fn export ( dsc : & mut DscManager , resource_type : & str , input : & str , format : Option < & OutputFormat > ) {
263
213
let Some ( dsc_resource) = get_resource ( dsc, resource_type) else {
264
214
error ! ( "{}" , DscError :: ResourceNotFound ( resource_type. to_string( ) ) . to_string( ) ) ;
265
215
exit ( EXIT_DSC_RESOURCE_NOT_FOUND ) ;
@@ -270,20 +220,8 @@ pub fn export(dsc: &mut DscManager, resource_type: &str, mut input: String, form
270
220
exit ( EXIT_DSC_ERROR ) ;
271
221
}
272
222
273
- let mut adapter_resource: Option < & DscResource > = None ;
274
- if let Some ( requires) = & dsc_resource. require_adapter {
275
- input = add_type_name_to_json ( input, dsc_resource. type_name . clone ( ) ) ;
276
- if let Some ( pr) = get_resource ( dsc, requires) {
277
- adapter_resource = Some ( pr) ;
278
- } else {
279
- error ! ( "{}: {requires}" , t!( "resource_command.adapterNotFound" ) ) ;
280
- return ;
281
- } ;
282
- }
283
-
284
223
let mut conf = Configuration :: new ( ) ;
285
-
286
- if let Err ( err) = add_resource_export_results_to_configuration ( dsc_resource, adapter_resource, & mut conf, & input) {
224
+ if let Err ( err) = add_resource_export_results_to_configuration ( dsc_resource, & mut conf, input) {
287
225
error ! ( "{err}" ) ;
288
226
exit ( EXIT_DSC_ERROR ) ;
289
227
}
0 commit comments