22// Licensed under the MIT License.
33
44use 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} ;
66use dsc_lib:: configure:: config_doc:: { Configuration , ExecutionKind } ;
77use dsc_lib:: configure:: add_resource_export_results_to_configuration;
88use dsc_lib:: dscresources:: { resource_manifest:: Kind , invoke_result:: { GetResult , ResourceGetResponse } } ;
@@ -16,8 +16,8 @@ use dsc_lib::{
1616} ;
1717use std:: process:: exit;
1818
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 {
2121 error ! ( "{}" , DscError :: ResourceNotFound ( resource_type. to_string( ) ) . to_string( ) ) ;
2222 exit ( EXIT_DSC_RESOURCE_NOT_FOUND ) ;
2323 } ;
@@ -28,17 +28,7 @@ pub fn get(dsc: &DscManager, resource_type: &str, mut input: String, format: Opt
2828 exit ( EXIT_DSC_ERROR ) ;
2929 }
3030
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) {
4232 Ok ( result) => {
4333 // convert to json
4434 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
5848}
5949
6050pub 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 {
6353 error ! ( "{}" , DscError :: ResourceNotFound ( resource_type. to_string( ) ) . to_string( ) ) ;
6454 exit ( EXIT_DSC_RESOURCE_NOT_FOUND ) ;
6555 } ;
@@ -70,16 +60,6 @@ pub fn get_all(dsc: &DscManager, resource_type: &str, format: Option<&OutputForm
7060 exit ( EXIT_DSC_ERROR ) ;
7161 }
7262
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-
8363 let export_result = match resource. export ( & input) {
8464 Ok ( export) => { export }
8565 Err ( err) => {
@@ -107,13 +87,13 @@ pub fn get_all(dsc: &DscManager, resource_type: &str, format: Option<&OutputForm
10787 }
10888}
10989
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 > ) {
11191 if input. is_empty ( ) {
11292 error ! ( "{}" , t!( "resource_command.setInputEmpty" ) ) ;
11393 exit ( EXIT_INVALID_ARGS ) ;
11494 }
11595
116- let Some ( mut resource) = get_resource ( dsc, resource_type) else {
96+ let Some ( resource) = get_resource ( dsc, resource_type) else {
11797 error ! ( "{}" , DscError :: ResourceNotFound ( resource_type. to_string( ) ) . to_string( ) ) ;
11898 exit ( EXIT_DSC_RESOURCE_NOT_FOUND ) ;
11999 } ;
@@ -124,17 +104,7 @@ pub fn set(dsc: &DscManager, resource_type: &str, mut input: String, format: Opt
124104 exit ( EXIT_DSC_ERROR ) ;
125105 }
126106
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 ) {
138108 Ok ( result) => {
139109 // convert to json
140110 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
153123 }
154124}
155125
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 > ) {
157127 if input. is_empty ( ) {
158128 error ! ( "{}" , t!( "resource_command.testInputEmpty" ) ) ;
159129 exit ( EXIT_INVALID_ARGS ) ;
160130 }
161131
162- let Some ( mut resource) = get_resource ( dsc, resource_type) else {
132+ let Some ( resource) = get_resource ( dsc, resource_type) else {
163133 error ! ( "{}" , DscError :: ResourceNotFound ( resource_type. to_string( ) ) . to_string( ) ) ;
164134 exit ( EXIT_DSC_RESOURCE_NOT_FOUND ) ;
165135 } ;
@@ -170,17 +140,7 @@ pub fn test(dsc: &DscManager, resource_type: &str, mut input: String, format: Op
170140 exit ( EXIT_DSC_ERROR ) ;
171141 }
172142
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) {
184144 Ok ( result) => {
185145 // convert to json
186146 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
199159 }
200160}
201161
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 {
204164 error ! ( "{}" , DscError :: ResourceNotFound ( resource_type. to_string( ) ) . to_string( ) ) ;
205165 exit ( EXIT_DSC_RESOURCE_NOT_FOUND ) ;
206166 } ;
@@ -211,17 +171,7 @@ pub fn delete(dsc: &DscManager, resource_type: &str, mut input: String) {
211171 exit ( EXIT_DSC_ERROR ) ;
212172 }
213173
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) {
225175 Ok ( ( ) ) => { }
226176 Err ( err) => {
227177 error ! ( "Error: {err}" ) ;
@@ -259,7 +209,7 @@ pub fn schema(dsc: &DscManager, resource_type: &str, format: Option<&OutputForma
259209 }
260210}
261211
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 > ) {
263213 let Some ( dsc_resource) = get_resource ( dsc, resource_type) else {
264214 error ! ( "{}" , DscError :: ResourceNotFound ( resource_type. to_string( ) ) . to_string( ) ) ;
265215 exit ( EXIT_DSC_RESOURCE_NOT_FOUND ) ;
@@ -270,20 +220,8 @@ pub fn export(dsc: &mut DscManager, resource_type: &str, mut input: String, form
270220 exit ( EXIT_DSC_ERROR ) ;
271221 }
272222
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-
284223 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) {
287225 error ! ( "{err}" ) ;
288226 exit ( EXIT_DSC_ERROR ) ;
289227 }
0 commit comments