@@ -358,13 +358,13 @@ func GetConfiguration() *Configuration {
358358// ReadConfigFile returns InputSourceContext initialized from the configuration file.
359359// On repeat calls returns with the same file, returns without reading the file again; however,
360360// if value of "config" flag changes, will read the new config file
361- func ReadConfigFile (c * cli.Context , log * zerolog.Logger ) (* configFileSettings , error ) {
361+ func ReadConfigFile (c * cli.Context , log * zerolog.Logger ) (settings * configFileSettings , warnings string , err error ) {
362362 configFile := c .String ("config" )
363363 if configuration .Source () == configFile || configFile == "" {
364364 if configuration .Source () == "" {
365- return nil , ErrNoConfigFile
365+ return nil , "" , ErrNoConfigFile
366366 }
367- return & configuration , nil
367+ return & configuration , "" , nil
368368 }
369369
370370 log .Debug ().Msgf ("Loading configuration from %s" , configFile )
@@ -373,16 +373,27 @@ func ReadConfigFile(c *cli.Context, log *zerolog.Logger) (*configFileSettings, e
373373 if os .IsNotExist (err ) {
374374 err = ErrNoConfigFile
375375 }
376- return nil , err
376+ return nil , "" , err
377377 }
378378 defer file .Close ()
379379 if err := yaml .NewDecoder (file ).Decode (& configuration ); err != nil {
380380 if err == io .EOF {
381381 log .Error ().Msgf ("Configuration file %s was empty" , configFile )
382- return & configuration , nil
382+ return & configuration , "" , nil
383383 }
384- return nil , errors .Wrap (err , "error parsing YAML in config file at " + configFile )
384+ return nil , "" , errors .Wrap (err , "error parsing YAML in config file at " + configFile )
385385 }
386386 configuration .sourceFile = configFile
387- return & configuration , nil
387+
388+ // Parse it again, with strict mode, to find warnings.
389+ if file , err := os .Open (configFile ); err == nil {
390+ decoder := yaml .NewDecoder (file )
391+ decoder .SetStrict (true )
392+ var unusedConfig configFileSettings
393+ if err := decoder .Decode (& unusedConfig ); err != nil {
394+ warnings = err .Error ()
395+ }
396+ }
397+
398+ return & configuration , warnings , nil
388399}
0 commit comments