@@ -68,12 +68,16 @@ impl ConfigPrefix {
6868}
6969
7070impl Config {
71- pub fn parse ( prefix : ConfigPrefix , filename : & PathBuf ) -> Result < Self , String > {
71+ pub fn parse ( prefix : ConfigPrefix , filename : & Option < PathBuf > ) -> Result < Self , String > {
7272 let config_defaults = include_str ! ( "../default_values.toml" ) ;
7373
74- let config: ConfigWrapper = Figment :: new ( )
75- . merge ( Toml :: string ( config_defaults) )
76- . merge ( Toml :: file ( filename) )
74+ let mut figment_config = Figment :: new ( ) . merge ( Toml :: string ( config_defaults) ) ;
75+
76+ if let Some ( path) = filename {
77+ figment_config = figment_config. merge ( Toml :: file ( path) ) ;
78+ }
79+
80+ let config: ConfigWrapper = figment_config
7781 . merge ( Env :: prefixed ( prefix. get_prefix ( ) ) . split ( "__" ) )
7882 . extract ( )
7983 . map_err ( |e| e. to_string ( ) ) ?;
@@ -349,7 +353,7 @@ mod tests {
349353 fn test_minimal_config ( ) {
350354 Config :: parse (
351355 ConfigPrefix :: Service ,
352- & PathBuf :: from ( "minimal-config-example.toml" ) ,
356+ & Some ( PathBuf :: from ( "minimal-config-example.toml" ) ) ,
353357 )
354358 . unwrap ( ) ;
355359 }
@@ -359,7 +363,7 @@ mod tests {
359363 // Generate full config by deserializing the minimal config and let the code fill in the defaults.
360364 let max_config = Config :: parse (
361365 ConfigPrefix :: Service ,
362- & PathBuf :: from ( "minimal-config-example.toml" ) ,
366+ & Some ( PathBuf :: from ( "minimal-config-example.toml" ) ) ,
363367 )
364368 . unwrap ( ) ;
365369 let max_config_file: Config = toml:: from_str (
@@ -381,7 +385,7 @@ mod tests {
381385
382386 Config :: parse (
383387 ConfigPrefix :: Service ,
384- & PathBuf :: from ( "minimal-config-example.toml" ) ,
388+ & Some ( PathBuf :: from ( "minimal-config-example.toml" ) ) ,
385389 )
386390 . unwrap ( ) ;
387391
@@ -421,7 +425,7 @@ mod tests {
421425 // This should fail because the subgraphs.network.query_url field is missing
422426 Config :: parse (
423427 ConfigPrefix :: Service ,
424- & PathBuf :: from ( temp_minimal_config_path. path ( ) ) ,
428+ & Some ( PathBuf :: from ( temp_minimal_config_path. path ( ) ) ) ,
425429 )
426430 . unwrap_err ( ) ;
427431
@@ -430,7 +434,7 @@ mod tests {
430434
431435 let config = Config :: parse (
432436 ConfigPrefix :: Service ,
433- & PathBuf :: from ( temp_minimal_config_path. path ( ) ) ,
437+ & Some ( PathBuf :: from ( temp_minimal_config_path. path ( ) ) ) ,
434438 )
435439 . unwrap ( ) ;
436440
@@ -448,7 +452,7 @@ mod tests {
448452
449453 let config = Config :: parse (
450454 ConfigPrefix :: Service ,
451- & PathBuf :: from ( "minimal-config-example.toml" ) ,
455+ & Some ( PathBuf :: from ( "minimal-config-example.toml" ) ) ,
452456 )
453457 . unwrap ( ) ;
454458
@@ -533,7 +537,7 @@ mod tests {
533537 // Parse the config with new datbase vars
534538 let config = Config :: parse (
535539 ConfigPrefix :: Service ,
536- & PathBuf :: from ( temp_minimal_config_path. path ( ) ) ,
540+ & Some ( PathBuf :: from ( temp_minimal_config_path. path ( ) ) ) ,
537541 )
538542 . unwrap ( ) ;
539543
0 commit comments