@@ -34,7 +34,7 @@ use std::{
3434} ;
3535use tracing:: { debug, error, trace} ;
3636
37- pub fn config_get ( configurator : & mut Configurator , format : & Option < OutputFormat > , as_group : & bool )
37+ pub fn config_get ( configurator : & mut Configurator , format : Option < & OutputFormat > , as_group : & bool )
3838{
3939 match configurator. invoke_get ( ) {
4040 Ok ( result) => {
@@ -69,7 +69,7 @@ pub fn config_get(configurator: &mut Configurator, format: &Option<OutputFormat>
6969 }
7070}
7171
72- pub fn config_set ( configurator : & mut Configurator , format : & Option < OutputFormat > , as_group : & bool )
72+ pub fn config_set ( configurator : & mut Configurator , format : Option < & OutputFormat > , as_group : & bool )
7373{
7474 match configurator. invoke_set ( false ) {
7575 Ok ( result) => {
@@ -104,7 +104,7 @@ pub fn config_set(configurator: &mut Configurator, format: &Option<OutputFormat>
104104 }
105105}
106106
107- pub fn config_test ( configurator : & mut Configurator , format : & Option < OutputFormat > , as_group : & bool , as_get : & bool , as_config : & bool )
107+ pub fn config_test ( configurator : & mut Configurator , format : Option < & OutputFormat > , as_group : & bool , as_get : & bool , as_config : & bool )
108108{
109109 match configurator. invoke_test ( ) {
110110 Ok ( result) => {
@@ -190,7 +190,7 @@ pub fn config_test(configurator: &mut Configurator, format: &Option<OutputFormat
190190 }
191191}
192192
193- pub fn config_export ( configurator : & mut Configurator , format : & Option < OutputFormat > )
193+ pub fn config_export ( configurator : & mut Configurator , format : Option < & OutputFormat > )
194194{
195195 match configurator. invoke_export ( ) {
196196 Ok ( result) => {
@@ -219,7 +219,7 @@ pub fn config_export(configurator: &mut Configurator, format: &Option<OutputForm
219219 }
220220}
221221
222- fn initialize_config_root ( path : & Option < String > ) -> Option < String > {
222+ fn initialize_config_root ( path : Option < & String > ) -> Option < String > {
223223 // code that calls this pass in either None, Some("-"), or Some(path)
224224 // in the case of `-` we treat it as None, but need to pass it back as subsequent processing needs to handle it
225225 let use_stdin = if let Some ( specified_path) = path {
@@ -250,15 +250,15 @@ fn initialize_config_root(path: &Option<String>) -> Option<String> {
250250}
251251
252252#[ allow( clippy:: too_many_lines) ]
253- pub fn config ( subcommand : & ConfigSubCommand , parameters : & Option < String > , mounted_path : & Option < String > , as_group : & bool , as_include : & bool ) {
253+ pub fn config ( subcommand : & ConfigSubCommand , parameters : & Option < String > , mounted_path : Option < & String > , as_group : & bool , as_include : & bool ) {
254254 let ( new_parameters, json_string) = match subcommand {
255255 ConfigSubCommand :: Get { input, file, .. } |
256256 ConfigSubCommand :: Set { input, file, .. } |
257257 ConfigSubCommand :: Test { input, file, .. } |
258258 ConfigSubCommand :: Validate { input, file, .. } |
259259 ConfigSubCommand :: Export { input, file, .. } => {
260- let new_path = initialize_config_root ( file) ;
261- let document = get_input ( input, & new_path) ;
260+ let new_path = initialize_config_root ( file. as_ref ( ) ) ;
261+ let document = get_input ( input. as_ref ( ) , new_path. as_ref ( ) ) ;
262262 if * as_include {
263263 let ( new_parameters, config_json) = match get_contents ( & document) {
264264 Ok ( ( parameters, config_json) ) => ( parameters, config_json) ,
@@ -273,8 +273,8 @@ pub fn config(subcommand: &ConfigSubCommand, parameters: &Option<String>, mounte
273273 }
274274 } ,
275275 ConfigSubCommand :: Resolve { input, file, .. } => {
276- let new_path = initialize_config_root ( file) ;
277- let document = get_input ( input, & new_path) ;
276+ let new_path = initialize_config_root ( file. as_ref ( ) ) ;
277+ let document = get_input ( input. as_ref ( ) , new_path. as_ref ( ) ) ;
278278 let ( new_parameters, config_json) = match get_contents ( & document) {
279279 Ok ( ( parameters, config_json) ) => ( parameters, config_json) ,
280280 Err ( err) => {
@@ -343,29 +343,29 @@ pub fn config(subcommand: &ConfigSubCommand, parameters: &Option<String>, mounte
343343 configurator. set_system_root ( path) ;
344344 }
345345
346- if let Err ( err) = configurator. set_context ( & parameters) {
346+ if let Err ( err) = configurator. set_context ( parameters. as_ref ( ) ) {
347347 error ! ( "Error: Parameter input failure: {err}" ) ;
348348 exit ( EXIT_INVALID_INPUT ) ;
349349 }
350350
351351 match subcommand {
352- ConfigSubCommand :: Get { output_format : format , .. } => {
353- config_get ( & mut configurator, format , as_group) ;
352+ ConfigSubCommand :: Get { output_format, .. } => {
353+ config_get ( & mut configurator, output_format . as_ref ( ) , as_group) ;
354354 } ,
355- ConfigSubCommand :: Set { output_format : format , .. } => {
356- config_set ( & mut configurator, format , as_group) ;
355+ ConfigSubCommand :: Set { output_format, .. } => {
356+ config_set ( & mut configurator, output_format . as_ref ( ) , as_group) ;
357357 } ,
358- ConfigSubCommand :: Test { output_format : format , as_get, as_config, .. } => {
359- config_test ( & mut configurator, format , as_group, as_get, as_config) ;
358+ ConfigSubCommand :: Test { output_format, as_get, as_config, .. } => {
359+ config_test ( & mut configurator, output_format . as_ref ( ) , as_group, as_get, as_config) ;
360360 } ,
361- ConfigSubCommand :: Validate { input, file, output_format : format } => {
361+ ConfigSubCommand :: Validate { input, file, output_format} => {
362362 let mut result = ValidateResult {
363363 valid : true ,
364364 reason : None ,
365365 } ;
366366 if * as_include {
367- let new_path = initialize_config_root ( file) ;
368- let input = get_input ( input, & new_path) ;
367+ let new_path = initialize_config_root ( file. as_ref ( ) ) ;
368+ let input = get_input ( input. as_ref ( ) , new_path. as_ref ( ) ) ;
369369 match serde_json:: from_str :: < Include > ( & input) {
370370 Ok ( _) => {
371371 // valid, so do nothing
@@ -392,12 +392,12 @@ pub fn config(subcommand: &ConfigSubCommand, parameters: &Option<String>, mounte
392392 exit ( EXIT_JSON_ERROR ) ;
393393 } ;
394394
395- write_output ( & json, format ) ;
395+ write_output ( & json, output_format . as_ref ( ) ) ;
396396 } ,
397- ConfigSubCommand :: Export { output_format : format , .. } => {
398- config_export ( & mut configurator, format ) ;
397+ ConfigSubCommand :: Export { output_format, .. } => {
398+ config_export ( & mut configurator, output_format . as_ref ( ) ) ;
399399 } ,
400- ConfigSubCommand :: Resolve { output_format : format , .. } => {
400+ ConfigSubCommand :: Resolve { output_format, .. } => {
401401 let configuration = match serde_json:: from_str ( & json_string) {
402402 Ok ( json) => json,
403403 Err ( err) => {
@@ -426,7 +426,7 @@ pub fn config(subcommand: &ConfigSubCommand, parameters: &Option<String>, mounte
426426 exit ( EXIT_JSON_ERROR ) ;
427427 }
428428 } ;
429- write_output ( & json_string, format ) ;
429+ write_output ( & json_string, output_format . as_ref ( ) ) ;
430430 } ,
431431 }
432432}
@@ -531,51 +531,51 @@ pub fn resource(subcommand: &ResourceSubCommand) {
531531 } ;
532532
533533 match subcommand {
534- ResourceSubCommand :: List { resource_name, adapter_name, description, tags, output_format : format } => {
535- list_resources ( & mut dsc, resource_name, adapter_name, description, tags, format ) ;
534+ ResourceSubCommand :: List { resource_name, adapter_name, description, tags, output_format } => {
535+ list_resources ( & mut dsc, resource_name. as_ref ( ) , adapter_name. as_ref ( ) , description. as_ref ( ) , tags. as_ref ( ) , output_format . as_ref ( ) ) ;
536536 } ,
537- ResourceSubCommand :: Schema { resource , output_format : format } => {
537+ ResourceSubCommand :: Schema { resource , output_format } => {
538538 dsc. find_resources ( & [ resource. to_string ( ) ] ) ;
539- resource_command:: schema ( & dsc, resource, format ) ;
539+ resource_command:: schema ( & dsc, resource, output_format . as_ref ( ) ) ;
540540 } ,
541- ResourceSubCommand :: Export { resource, output_format : format } => {
541+ ResourceSubCommand :: Export { resource, output_format } => {
542542 dsc. find_resources ( & [ resource. to_string ( ) ] ) ;
543- resource_command:: export ( & mut dsc, resource, format ) ;
543+ resource_command:: export ( & mut dsc, resource, output_format . as_ref ( ) ) ;
544544 } ,
545- ResourceSubCommand :: Get { resource, input, file : path, all, output_format : format } => {
545+ ResourceSubCommand :: Get { resource, input, file : path, all, output_format } => {
546546 dsc. find_resources ( & [ resource. to_string ( ) ] ) ;
547- if * all { resource_command:: get_all ( & dsc, resource, format ) ; }
547+ if * all { resource_command:: get_all ( & dsc, resource, output_format . as_ref ( ) ) ; }
548548 else {
549- let parsed_input = get_input ( input, path) ;
550- resource_command:: get ( & dsc, resource, parsed_input, format ) ;
549+ let parsed_input = get_input ( input. as_ref ( ) , path. as_ref ( ) ) ;
550+ resource_command:: get ( & dsc, resource, parsed_input, output_format . as_ref ( ) ) ;
551551 }
552552 } ,
553- ResourceSubCommand :: Set { resource, input, file : path, output_format : format } => {
553+ ResourceSubCommand :: Set { resource, input, file : path, output_format } => {
554554 dsc. find_resources ( & [ resource. to_string ( ) ] ) ;
555- let parsed_input = get_input ( input, path) ;
556- resource_command:: set ( & dsc, resource, parsed_input, format ) ;
555+ let parsed_input = get_input ( input. as_ref ( ) , path. as_ref ( ) ) ;
556+ resource_command:: set ( & dsc, resource, parsed_input, output_format . as_ref ( ) ) ;
557557 } ,
558- ResourceSubCommand :: Test { resource, input, file : path, output_format : format } => {
558+ ResourceSubCommand :: Test { resource, input, file : path, output_format } => {
559559 dsc. find_resources ( & [ resource. to_string ( ) ] ) ;
560- let parsed_input = get_input ( input, path) ;
561- resource_command:: test ( & dsc, resource, parsed_input, format ) ;
560+ let parsed_input = get_input ( input. as_ref ( ) , path. as_ref ( ) ) ;
561+ resource_command:: test ( & dsc, resource, parsed_input, output_format . as_ref ( ) ) ;
562562 } ,
563563 ResourceSubCommand :: Delete { resource, input, file : path } => {
564564 dsc. find_resources ( & [ resource. to_string ( ) ] ) ;
565- let parsed_input = get_input ( input, path) ;
565+ let parsed_input = get_input ( input. as_ref ( ) , path. as_ref ( ) ) ;
566566 resource_command:: delete ( & dsc, resource, parsed_input) ;
567567 } ,
568568 }
569569}
570570
571- fn list_resources ( dsc : & mut DscManager , resource_name : & Option < String > , adapter_name : & Option < String > , description : & Option < String > , tags : & Option < Vec < String > > , format : & Option < OutputFormat > ) {
571+ fn list_resources ( dsc : & mut DscManager , resource_name : Option < & String > , adapter_name : Option < & String > , description : Option < & String > , tags : Option < & Vec < String > > , format : Option < & OutputFormat > ) {
572572 let mut write_table = false ;
573573 let mut table = Table :: new ( & [ "Type" , "Kind" , "Version" , "Caps" , "RequireAdapter" , "Description" ] ) ;
574574 if format. is_none ( ) && io:: stdout ( ) . is_terminal ( ) {
575575 // write as table if format is not specified and interactive
576576 write_table = true ;
577577 }
578- for resource in dsc. list_available_resources ( & resource_name. clone ( ) . unwrap_or ( "*" . to_string ( ) ) , & adapter_name. clone ( ) . unwrap_or_default ( ) ) {
578+ for resource in dsc. list_available_resources ( resource_name. unwrap_or ( & String :: from ( "*" ) ) , adapter_name. unwrap_or ( & String :: new ( ) ) ) {
579579 let mut capabilities = "--------" . to_string ( ) ;
580580 let capability_types = [
581581 ( Capability :: Get , "g" ) ,
@@ -606,7 +606,7 @@ fn list_resources(dsc: &mut DscManager, resource_name: &Option<String>, adapter_
606606
607607 // if description is specified, skip if resource description does not contain it
608608 if description. is_some ( ) &&
609- ( manifest. description . is_none ( ) | !manifest. description . unwrap_or_default ( ) . to_lowercase ( ) . contains ( & description. as_ref ( ) . unwrap_or ( & String :: new ( ) ) . to_lowercase ( ) ) ) {
609+ ( manifest. description . is_none ( ) | !manifest. description . unwrap_or_default ( ) . to_lowercase ( ) . contains ( & description. unwrap_or ( & String :: new ( ) ) . to_lowercase ( ) ) ) {
610610 continue ;
611611 }
612612
0 commit comments