diff options
author | René 'Necoro' Neumann <necoro@necoro.eu> | 2020-05-01 17:48:57 +0200 |
---|---|---|
committer | René 'Necoro' Neumann <necoro@necoro.eu> | 2020-05-01 17:48:57 +0200 |
commit | 8afa4a29d793e84007666083158e198cf2b8557d (patch) | |
tree | 3ed60577657f2723e1cae80c3965b1414124f433 /pkg/config | |
parent | 23c2296ae94bedd616bffdf6f87f689bdc90b108 (diff) | |
download | feed2imap-go-8afa4a29d793e84007666083158e198cf2b8557d.tar.gz feed2imap-go-8afa4a29d793e84007666083158e198cf2b8557d.tar.bz2 feed2imap-go-8afa4a29d793e84007666083158e198cf2b8557d.zip |
Print warning, when unknown global option. Also support specifying the new 'options:' keys on global level, but print warning.
Diffstat (limited to '')
-rw-r--r-- | pkg/config/yaml.go | 23 |
1 files changed, 23 insertions, 0 deletions
diff --git a/pkg/config/yaml.go b/pkg/config/yaml.go index f6b9edd..e8dc401 100644 --- a/pkg/config/yaml.go +++ b/pkg/config/yaml.go @@ -76,6 +76,27 @@ func unmarshal(in io.Reader, cfg *Config) (config, error) { return parsedCfg, nil } +func (cfg *Config) fixGlobalOptions(unparsed Map) { + origMap := Map{} + + // copy map + for k, v := range unparsed { + origMap[k] = v + } + + newOpts, _ := buildOptions(&cfg.FeedOptions, unparsed) + + for k := range origMap { + if _, ok := unparsed[k]; !ok { + log.Warnf("Global option '%s' should be inside the 'options' map. It currently overwrites the same key there.", k) + } else { + log.Warnf("Unknown global option '%s'. Ignored!", k) + } + } + + cfg.FeedOptions = newOpts +} + func (cfg *Config) parse(in io.Reader) error { var ( err error @@ -93,6 +114,8 @@ func (cfg *Config) parse(in io.Reader) error { return fmt.Errorf("while unmarshalling: %w", err) } + cfg.fixGlobalOptions(parsedCfg.GlobalConfig) + if err := buildFeeds(parsedCfg.Feeds, []string{}, cfg.Feeds, &cfg.FeedOptions); err != nil { return fmt.Errorf("while parsing: %w", err) } |