gte/cmd/generate-recurring/main.go

43 lines
1.1 KiB
Go
Raw Normal View History

2021-01-31 10:01:03 +01:00
package main
import (
2021-05-15 11:19:28 +02:00
"flag"
2021-01-31 10:01:03 +01:00
"os"
2021-05-13 08:15:14 +02:00
"git.ewintr.nl/go-kit/log"
2021-05-15 11:19:28 +02:00
"git.ewintr.nl/gte/internal/configuration"
2021-05-13 08:15:14 +02:00
"git.ewintr.nl/gte/internal/process"
2021-05-13 09:47:06 +02:00
"git.ewintr.nl/gte/internal/task"
2021-05-13 08:15:14 +02:00
"git.ewintr.nl/gte/pkg/msend"
2021-05-13 09:47:06 +02:00
"git.ewintr.nl/gte/pkg/mstore"
2021-01-31 10:01:03 +01:00
)
func main() {
2021-05-13 08:15:14 +02:00
logger := log.New(os.Stdout).WithField("cmd", "generate-recurring")
2021-05-15 11:19:28 +02:00
configPath := flag.String("c", "~/.config/gte/gte.conf", "path to configuration file")
daysAhead := flag.Int("d", 6, "generate for this amount of days from now")
flag.Parse()
configFile, err := os.Open(*configPath)
2021-02-05 10:04:19 +01:00
if err != nil {
2021-05-15 11:19:28 +02:00
logger.WithErr(err).Error("could not open config file")
os.Exit(1)
2021-02-05 10:04:19 +01:00
}
2021-05-15 11:19:28 +02:00
config := configuration.New(configFile)
2021-01-31 10:01:03 +01:00
2021-05-15 11:19:28 +02:00
msgStore := mstore.NewIMAP(config.IMAP())
mailSend := msend.NewSSLSMTP(config.SMTP())
2021-05-13 08:15:14 +02:00
taskRepo := task.NewRepository(msgStore)
taskDisp := task.NewDispatcher(mailSend)
2021-05-15 11:19:28 +02:00
recur := process.NewRecur(taskRepo, taskDisp, *daysAhead)
2021-01-31 10:01:03 +01:00
2021-05-13 08:15:14 +02:00
result, err := recur.Process()
2021-01-31 10:01:03 +01:00
if err != nil {
2021-05-13 08:15:14 +02:00
logger.WithErr(err).Error("unable to process recurring")
os.Exit(1)
2021-01-31 10:01:03 +01:00
}
2021-05-15 11:46:03 +02:00
logger.WithField("result", result).Info("finished generating recurring tasks")
2021-01-31 10:01:03 +01:00
}