aboutsummaryrefslogtreecommitdiff
path: root/main.go
diff options
context:
space:
mode:
authorRené 'Necoro' Neumann <necoro@necoro.eu>2020-05-11 13:22:02 +0200
committerRené 'Necoro' Neumann <necoro@necoro.eu>2020-05-11 13:22:02 +0200
commit8558205de4c9bd46aa7b4a61db7bdd1fa2f91240 (patch)
treeb8904e770672980e4821d68bf6edde8e07e138a4 /main.go
parent748481d6edc76dae84ffa00d05241e81f2a7fb6c (diff)
downloadfeed2imap-go-8558205de4c9bd46aa7b4a61db7bdd1fa2f91240.tar.gz
feed2imap-go-8558205de4c9bd46aa7b4a61db7bdd1fa2f91240.tar.bz2
feed2imap-go-8558205de4c9bd46aa7b4a61db7bdd1fa2f91240.zip
Reorganize flag handling
Diffstat (limited to '')
-rw-r--r--main.go47
1 files changed, 30 insertions, 17 deletions
diff --git a/main.go b/main.go
index 242dade..e6faa68 100644
--- a/main.go
+++ b/main.go
@@ -13,13 +13,26 @@ import (
"github.com/Necoro/feed2imap-go/pkg/version"
)
-var printVersion = flag.Bool("version", false, "print version and exit")
-var cfgFile = flag.String("f", "config.yml", "configuration file")
-var cacheFile = flag.String("c", "feed.cache", "cache file")
-var verbose = flag.Bool("v", false, "enable verbose output")
-var debug = flag.Bool("d", false, "enable debug output")
-var dryRun = flag.Bool("dry-run", false, "do everything short of uploading and writing the cache")
-var buildCache = flag.Bool("build-cache", false, "only (re)build the cache; useful after migration or when the cache is lost or corrupted")
+// flags
+var (
+ cfgFile string = "config.yml"
+ cacheFile string = "feed.cache"
+ printVersion bool = false
+ dryRun bool = false
+ buildCache bool = false
+ verbose bool = false
+ debug bool = false
+)
+
+func init() {
+ flag.StringVar(&cfgFile, "f", cfgFile, "configuration file")
+ flag.StringVar(&cacheFile, "c", cacheFile, "cache file")
+ flag.BoolVar(&printVersion, "version", printVersion, "print version and exit")
+ flag.BoolVar(&dryRun, "dry-run", dryRun, "do everything short of uploading and writing the cache")
+ flag.BoolVar(&buildCache, "build-cache", buildCache, "only (re)build the cache; useful after migration or when the cache is lost or corrupted")
+ flag.BoolVar(&verbose, "v", verbose, "enable verbose output")
+ flag.BoolVar(&debug, "d", debug, "enable debug output")
+}
func processFeed(feed *feed.Feed, client *imap.Client, dryRun bool) {
msgs, err := feed.Messages()
@@ -51,20 +64,20 @@ func processFeed(feed *feed.Feed, client *imap.Client, dryRun bool) {
func run() error {
flag.Parse()
- if *printVersion {
+ if printVersion {
println("Feed2Imap-Go, " + version.FullVersion())
return nil
}
- if *debug {
+ if debug {
log.SetDebug()
- } else if *verbose {
+ } else if verbose {
log.SetVerbose()
}
log.Printf("Starting up (%s)...", version.FullVersion())
- cfg, err := config.Load(*cfgFile)
+ cfg, err := config.Load(cfgFile)
if err != nil {
return err
}
@@ -75,7 +88,7 @@ func run() error {
state := feed.NewState(cfg)
- err = state.LoadCache(*cacheFile, *buildCache)
+ err = state.LoadCache(cacheFile, buildCache)
if err != nil {
return err
}
@@ -100,7 +113,7 @@ func run() error {
}
var c *imap.Client
- if !*dryRun && !*buildCache {
+ if !dryRun && !buildCache {
if c, err = imap.Connect(imapUrl); err != nil {
return err
}
@@ -108,16 +121,16 @@ func run() error {
defer c.Disconnect()
}
- if *buildCache {
+ if buildCache {
state.Foreach((*feed.Feed).MarkSuccess)
} else {
state.ForeachGo(func(f *feed.Feed) {
- processFeed(f, c, *dryRun)
+ processFeed(f, c, dryRun)
})
}
- if !*dryRun {
- if err = state.StoreCache(*cacheFile); err != nil {
+ if !dryRun {
+ if err = state.StoreCache(cacheFile); err != nil {
return err
}
}