aboutsummaryrefslogtreecommitdiff
path: root/pkg/config/yaml.go
diff options
context:
space:
mode:
authorRené 'Necoro' Neumann <necoro@necoro.eu>2020-08-22 15:57:19 +0200
committerRené 'Necoro' Neumann <necoro@necoro.eu>2020-08-22 15:57:19 +0200
commitaf957a67eb34430d5788bf1d2cb8e1aa1e46f3ff (patch)
tree6758764e1008e2a3fc01c166f4618b137ac975d2 /pkg/config/yaml.go
parent1e57a00c41035b7c3a1c4c5f230281b7461d90a5 (diff)
downloadfeed2imap-go-af957a67eb34430d5788bf1d2cb8e1aa1e46f3ff.tar.gz
feed2imap-go-af957a67eb34430d5788bf1d2cb8e1aa1e46f3ff.tar.bz2
feed2imap-go-af957a67eb34430d5788bf1d2cb8e1aa1e46f3ff.zip
#26: Introduce new option `auto-target`
Diffstat (limited to '')
-rw-r--r--pkg/config/yaml.go15
1 files changed, 9 insertions, 6 deletions
diff --git a/pkg/config/yaml.go b/pkg/config/yaml.go
index 85b6bd0..9dd74a9 100644
--- a/pkg/config/yaml.go
+++ b/pkg/config/yaml.go
@@ -50,7 +50,7 @@ func (grpFeed *configGroupFeed) isFeed() bool {
return grpFeed.Feed.Name != "" || grpFeed.Feed.Url != "" || len(grpFeed.Feed.Exec) > 0
}
-func (grpFeed *configGroupFeed) target() string {
+func (grpFeed *configGroupFeed) target(autoTarget bool) string {
tag := grpFeed.Target.ShortTag()
switch tag {
case strTag:
@@ -58,7 +58,10 @@ func (grpFeed *configGroupFeed) target() string {
case nullTag:
return ""
case emptyTag:
- // tag not set: continue on
+ if !autoTarget {
+ return ""
+ }
+ // tag not set and autoTarget is on: continue on
default:
panic("unexpected tag " + tag + " for target node")
}
@@ -122,7 +125,7 @@ func (cfg *Config) parse(in io.Reader) error {
cfg.fixGlobalOptions(parsedCfg.GlobalConfig)
- if err := buildFeeds(parsedCfg.Feeds, []string{}, cfg.Feeds, &cfg.FeedOptions); err != nil {
+ if err := buildFeeds(parsedCfg.Feeds, []string{}, cfg.Feeds, &cfg.FeedOptions, cfg.AutoTarget); err != nil {
return fmt.Errorf("while parsing: %w", err)
}
@@ -185,9 +188,9 @@ func buildOptions(globalFeedOptions *Options, options Map) (feedOptions Options,
}
// Fetch the group structure and populate the `targetStr` fields in the feeds
-func buildFeeds(cfg []configGroupFeed, target []string, feeds Feeds, globalFeedOptions *Options) error {
+func buildFeeds(cfg []configGroupFeed, target []string, feeds Feeds, globalFeedOptions *Options, autoTarget bool) error {
for _, f := range cfg {
- target := appTarget(target, f.target())
+ target := appTarget(target, f.target(autoTarget))
switch {
case f.isFeed() && f.isGroup():
return fmt.Errorf("Entry with targetStr %s is both a Feed and a group", target)
@@ -224,7 +227,7 @@ func buildFeeds(cfg []configGroupFeed, target []string, feeds Feeds, globalFeedO
log.Warnf("Unknown option '%s' for group '%s'. Ignored!", optName, f.Group.Group)
}
- if err := buildFeeds(f.Group.Feeds, target, feeds, &opt); err != nil {
+ if err := buildFeeds(f.Group.Feeds, target, feeds, &opt, autoTarget); err != nil {
return err
}
}