@@ -34,7 +34,7 @@ use std::{
34
34
} ;
35
35
use tracing:: { debug, error, trace} ;
36
36
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 )
38
38
{
39
39
match configurator. invoke_get ( ) {
40
40
Ok ( result) => {
@@ -69,7 +69,7 @@ pub fn config_get(configurator: &mut Configurator, format: &Option<OutputFormat>
69
69
}
70
70
}
71
71
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 )
73
73
{
74
74
match configurator. invoke_set ( false ) {
75
75
Ok ( result) => {
@@ -104,7 +104,7 @@ pub fn config_set(configurator: &mut Configurator, format: &Option<OutputFormat>
104
104
}
105
105
}
106
106
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 )
108
108
{
109
109
match configurator. invoke_test ( ) {
110
110
Ok ( result) => {
@@ -190,7 +190,7 @@ pub fn config_test(configurator: &mut Configurator, format: &Option<OutputFormat
190
190
}
191
191
}
192
192
193
- pub fn config_export ( configurator : & mut Configurator , format : & Option < OutputFormat > )
193
+ pub fn config_export ( configurator : & mut Configurator , format : Option < & OutputFormat > )
194
194
{
195
195
match configurator. invoke_export ( ) {
196
196
Ok ( result) => {
@@ -219,7 +219,7 @@ pub fn config_export(configurator: &mut Configurator, format: &Option<OutputForm
219
219
}
220
220
}
221
221
222
- fn initialize_config_root ( path : & Option < String > ) -> Option < String > {
222
+ fn initialize_config_root ( path : Option < & String > ) -> Option < String > {
223
223
// code that calls this pass in either None, Some("-"), or Some(path)
224
224
// in the case of `-` we treat it as None, but need to pass it back as subsequent processing needs to handle it
225
225
let use_stdin = if let Some ( specified_path) = path {
@@ -250,15 +250,15 @@ fn initialize_config_root(path: &Option<String>) -> Option<String> {
250
250
}
251
251
252
252
#[ 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 ) {
254
254
let ( new_parameters, json_string) = match subcommand {
255
255
ConfigSubCommand :: Get { input, file, .. } |
256
256
ConfigSubCommand :: Set { input, file, .. } |
257
257
ConfigSubCommand :: Test { input, file, .. } |
258
258
ConfigSubCommand :: Validate { input, file, .. } |
259
259
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 ( ) ) ;
262
262
if * as_include {
263
263
let ( new_parameters, config_json) = match get_contents ( & document) {
264
264
Ok ( ( parameters, config_json) ) => ( parameters, config_json) ,
@@ -273,8 +273,8 @@ pub fn config(subcommand: &ConfigSubCommand, parameters: &Option<String>, mounte
273
273
}
274
274
} ,
275
275
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 ( ) ) ;
278
278
let ( new_parameters, config_json) = match get_contents ( & document) {
279
279
Ok ( ( parameters, config_json) ) => ( parameters, config_json) ,
280
280
Err ( err) => {
@@ -343,29 +343,29 @@ pub fn config(subcommand: &ConfigSubCommand, parameters: &Option<String>, mounte
343
343
configurator. set_system_root ( path) ;
344
344
}
345
345
346
- if let Err ( err) = configurator. set_context ( & parameters) {
346
+ if let Err ( err) = configurator. set_context ( parameters. as_ref ( ) ) {
347
347
error ! ( "Error: Parameter input failure: {err}" ) ;
348
348
exit ( EXIT_INVALID_INPUT ) ;
349
349
}
350
350
351
351
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) ;
354
354
} ,
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) ;
357
357
} ,
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) ;
360
360
} ,
361
- ConfigSubCommand :: Validate { input, file, output_format : format } => {
361
+ ConfigSubCommand :: Validate { input, file, output_format} => {
362
362
let mut result = ValidateResult {
363
363
valid : true ,
364
364
reason : None ,
365
365
} ;
366
366
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 ( ) ) ;
369
369
match serde_json:: from_str :: < Include > ( & input) {
370
370
Ok ( _) => {
371
371
// valid, so do nothing
@@ -392,12 +392,12 @@ pub fn config(subcommand: &ConfigSubCommand, parameters: &Option<String>, mounte
392
392
exit ( EXIT_JSON_ERROR ) ;
393
393
} ;
394
394
395
- write_output ( & json, format ) ;
395
+ write_output ( & json, output_format . as_ref ( ) ) ;
396
396
} ,
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 ( ) ) ;
399
399
} ,
400
- ConfigSubCommand :: Resolve { output_format : format , .. } => {
400
+ ConfigSubCommand :: Resolve { output_format, .. } => {
401
401
let configuration = match serde_json:: from_str ( & json_string) {
402
402
Ok ( json) => json,
403
403
Err ( err) => {
@@ -426,7 +426,7 @@ pub fn config(subcommand: &ConfigSubCommand, parameters: &Option<String>, mounte
426
426
exit ( EXIT_JSON_ERROR ) ;
427
427
}
428
428
} ;
429
- write_output ( & json_string, format ) ;
429
+ write_output ( & json_string, output_format . as_ref ( ) ) ;
430
430
} ,
431
431
}
432
432
}
@@ -531,51 +531,51 @@ pub fn resource(subcommand: &ResourceSubCommand) {
531
531
} ;
532
532
533
533
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 ( ) ) ;
536
536
} ,
537
- ResourceSubCommand :: Schema { resource , output_format : format } => {
537
+ ResourceSubCommand :: Schema { resource , output_format } => {
538
538
dsc. find_resources ( & [ resource. to_string ( ) ] ) ;
539
- resource_command:: schema ( & dsc, resource, format ) ;
539
+ resource_command:: schema ( & dsc, resource, output_format . as_ref ( ) ) ;
540
540
} ,
541
- ResourceSubCommand :: Export { resource, output_format : format } => {
541
+ ResourceSubCommand :: Export { resource, output_format } => {
542
542
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 ( ) ) ;
544
544
} ,
545
- ResourceSubCommand :: Get { resource, input, file : path, all, output_format : format } => {
545
+ ResourceSubCommand :: Get { resource, input, file : path, all, output_format } => {
546
546
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 ( ) ) ; }
548
548
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 ( ) ) ;
551
551
}
552
552
} ,
553
- ResourceSubCommand :: Set { resource, input, file : path, output_format : format } => {
553
+ ResourceSubCommand :: Set { resource, input, file : path, output_format } => {
554
554
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 ( ) ) ;
557
557
} ,
558
- ResourceSubCommand :: Test { resource, input, file : path, output_format : format } => {
558
+ ResourceSubCommand :: Test { resource, input, file : path, output_format } => {
559
559
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 ( ) ) ;
562
562
} ,
563
563
ResourceSubCommand :: Delete { resource, input, file : path } => {
564
564
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 ( ) ) ;
566
566
resource_command:: delete ( & dsc, resource, parsed_input) ;
567
567
} ,
568
568
}
569
569
}
570
570
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 > ) {
572
572
let mut write_table = false ;
573
573
let mut table = Table :: new ( & [ "Type" , "Kind" , "Version" , "Caps" , "RequireAdapter" , "Description" ] ) ;
574
574
if format. is_none ( ) && io:: stdout ( ) . is_terminal ( ) {
575
575
// write as table if format is not specified and interactive
576
576
write_table = true ;
577
577
}
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 ( ) ) ) {
579
579
let mut capabilities = "--------" . to_string ( ) ;
580
580
let capability_types = [
581
581
( Capability :: Get , "g" ) ,
@@ -606,7 +606,7 @@ fn list_resources(dsc: &mut DscManager, resource_name: &Option<String>, adapter_
606
606
607
607
// if description is specified, skip if resource description does not contain it
608
608
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 ( ) ) ) {
610
610
continue ;
611
611
}
612
612
0 commit comments