gte/cmd/cli/command/send.go

37 lines
699 B
Go
Raw Normal View History

2021-09-03 09:31:41 +02:00
package command
import (
"fmt"
2021-09-19 11:59:26 +02:00
"ewintr.nl/gte/cmd/cli/format"
"ewintr.nl/gte/internal/configuration"
"ewintr.nl/gte/internal/process"
"ewintr.nl/gte/internal/storage"
"ewintr.nl/gte/pkg/msend"
2021-09-03 09:31:41 +02:00
)
type Send struct {
sender *process.Send
}
func NewSend(conf *configuration.Configuration) (*Send, error) {
local, err := storage.NewSqlite(conf.Sqlite())
if err != nil {
return &Send{}, err
}
disp := storage.NewDispatcher(msend.NewSSLSMTP(conf.SMTP()))
return &Send{
sender: process.NewSend(local, disp),
}, nil
}
func (s *Send) Do() string {
count, err := s.sender.Process()
if err != nil {
return format.FormatError(err)
}
2021-09-04 19:47:36 +02:00
return fmt.Sprintf("sent %d tasks\n\n", count)
2021-09-03 09:31:41 +02:00
}