@@ -31,6 +31,7 @@ pub struct CommandDiscovery {
31
31
resources : BTreeMap < String , Vec < DscResource > > ,
32
32
adapters : BTreeMap < String , Vec < DscResource > > ,
33
33
adapted_resources : BTreeMap < String , Vec < DscResource > > ,
34
+ progress_format : ProgressFormat ,
34
35
}
35
36
36
37
#[ derive( Deserialize ) ]
@@ -56,11 +57,12 @@ impl Default for ResourcePathSetting {
56
57
}
57
58
58
59
impl CommandDiscovery {
59
- pub fn new ( ) -> CommandDiscovery {
60
+ pub fn new ( progress_format : ProgressFormat ) -> CommandDiscovery {
60
61
CommandDiscovery {
61
62
resources : BTreeMap :: new ( ) ,
62
63
adapters : BTreeMap :: new ( ) ,
63
64
adapted_resources : BTreeMap :: new ( ) ,
65
+ progress_format,
64
66
}
65
67
}
66
68
@@ -161,13 +163,13 @@ impl CommandDiscovery {
161
163
162
164
impl Default for CommandDiscovery {
163
165
fn default ( ) -> Self {
164
- Self :: new ( )
166
+ Self :: new ( ProgressFormat :: Default )
165
167
}
166
168
}
167
169
168
170
impl ResourceDiscovery for CommandDiscovery {
169
171
170
- fn discover_resources ( & mut self , filter : & str , progress_format : ProgressFormat ) -> Result < ( ) , DscError > {
172
+ fn discover_resources ( & mut self , filter : & str ) -> Result < ( ) , DscError > {
171
173
info ! ( "{}" , t!( "discovery.commandDiscovery.discoverResources" , filter = filter) ) ;
172
174
173
175
let regex_str = convert_wildcard_to_regex ( filter) ;
@@ -178,7 +180,7 @@ impl ResourceDiscovery for CommandDiscovery {
178
180
return Err ( DscError :: Operation ( t ! ( "discovery.commandDiscovery.invalidAdapterFilter" ) . to_string ( ) ) ) ;
179
181
} ;
180
182
181
- let mut progress = ProgressBar :: new ( 1 , progress_format) ?;
183
+ let mut progress = ProgressBar :: new ( 1 , self . progress_format ) ?;
182
184
progress. write_activity ( t ! ( "discovery.commandDiscovery.progressSearching" ) . to_string ( ) . as_str ( ) ) ;
183
185
184
186
let mut resources = BTreeMap :: < String , Vec < DscResource > > :: new ( ) ;
@@ -242,9 +244,9 @@ impl ResourceDiscovery for CommandDiscovery {
242
244
Ok ( ( ) )
243
245
}
244
246
245
- fn discover_adapted_resources ( & mut self , name_filter : & str , adapter_filter : & str , progress_format : ProgressFormat ) -> Result < ( ) , DscError > {
247
+ fn discover_adapted_resources ( & mut self , name_filter : & str , adapter_filter : & str ) -> Result < ( ) , DscError > {
246
248
if self . resources . is_empty ( ) && self . adapters . is_empty ( ) {
247
- self . discover_resources ( "*" , progress_format ) ?;
249
+ self . discover_resources ( "*" ) ?;
248
250
}
249
251
250
252
if self . adapters . is_empty ( ) {
@@ -267,7 +269,7 @@ impl ResourceDiscovery for CommandDiscovery {
267
269
return Err ( DscError :: Operation ( "Could not build Regex filter for resource name" . to_string ( ) ) ) ;
268
270
} ;
269
271
270
- let mut progress = ProgressBar :: new ( self . adapters . len ( ) as u64 , progress_format) ?;
272
+ let mut progress = ProgressBar :: new ( self . adapters . len ( ) as u64 , self . progress_format ) ?;
271
273
progress. write_activity ( "Searching for adapted resources" ) ;
272
274
273
275
let mut adapted_resources = BTreeMap :: < String , Vec < DscResource > > :: new ( ) ;
@@ -283,7 +285,7 @@ impl ResourceDiscovery for CommandDiscovery {
283
285
284
286
found_adapter = true ;
285
287
info ! ( "Enumerating resources for adapter '{}'" , adapter_name) ;
286
- let mut adapter_progress = ProgressBar :: new ( 1 , progress_format) ?;
288
+ let mut adapter_progress = ProgressBar :: new ( 1 , self . progress_format ) ?;
287
289
adapter_progress. write_activity ( format ! ( "Enumerating resources for adapter '{adapter_name}'" ) . as_str ( ) ) ;
288
290
let manifest = if let Some ( manifest) = & adapter. manifest {
289
291
if let Ok ( manifest) = import_manifest ( manifest. clone ( ) ) {
@@ -350,18 +352,18 @@ impl ResourceDiscovery for CommandDiscovery {
350
352
Ok ( ( ) )
351
353
}
352
354
353
- fn list_available_resources ( & mut self , type_name_filter : & str , adapter_name_filter : & str , progress_format : ProgressFormat ) -> Result < BTreeMap < String , Vec < DscResource > > , DscError > {
355
+ fn list_available_resources ( & mut self , type_name_filter : & str , adapter_name_filter : & str ) -> Result < BTreeMap < String , Vec < DscResource > > , DscError > {
354
356
355
357
trace ! ( "Listing resources with type_name_filter '{type_name_filter}' and adapter_name_filter '{adapter_name_filter}'" ) ;
356
358
let mut resources = BTreeMap :: < String , Vec < DscResource > > :: new ( ) ;
357
359
358
360
if adapter_name_filter. is_empty ( ) {
359
- self . discover_resources ( type_name_filter, progress_format ) ?;
361
+ self . discover_resources ( type_name_filter) ?;
360
362
resources. append ( & mut self . resources ) ;
361
363
resources. append ( & mut self . adapters ) ;
362
364
} else {
363
- self . discover_resources ( "*" , progress_format ) ?;
364
- self . discover_adapted_resources ( type_name_filter, adapter_name_filter, progress_format ) ?;
365
+ self . discover_resources ( "*" ) ?;
366
+ self . discover_adapted_resources ( type_name_filter, adapter_name_filter) ?;
365
367
366
368
// add/update found adapted resources to the lookup_table
367
369
add_resources_to_lookup_table ( & self . adapted_resources ) ;
@@ -374,10 +376,10 @@ impl ResourceDiscovery for CommandDiscovery {
374
376
}
375
377
376
378
// TODO: handle version requirements
377
- fn find_resources ( & mut self , required_resource_types : & [ String ] , progress_format : ProgressFormat ) -> Result < BTreeMap < String , DscResource > , DscError >
379
+ fn find_resources ( & mut self , required_resource_types : & [ String ] ) -> Result < BTreeMap < String , DscResource > , DscError >
378
380
{
379
381
debug ! ( "Searching for resources: {:?}" , required_resource_types) ;
380
- self . discover_resources ( "*" , progress_format ) ?;
382
+ self . discover_resources ( "*" ) ?;
381
383
382
384
// convert required_resource_types to lowercase to handle case-insentiive search
383
385
let mut remaining_required_resource_types = required_resource_types. iter ( ) . map ( |x| x. to_lowercase ( ) ) . collect :: < Vec < String > > ( ) ;
@@ -426,7 +428,7 @@ impl ResourceDiscovery for CommandDiscovery {
426
428
}
427
429
}
428
430
429
- self . discover_adapted_resources ( "*" , & adapter_name, progress_format ) ?;
431
+ self . discover_adapted_resources ( "*" , & adapter_name) ?;
430
432
// add/update found adapted resources to the lookup_table
431
433
add_resources_to_lookup_table ( & self . adapted_resources ) ;
432
434
0 commit comments