gte/cmd/cli/command/add.go

35 lines
758 B
Go
Raw Normal View History

2021-07-09 13:25:50 +02:00
package command
import (
2021-08-16 06:54:45 +02:00
"strings"
2021-07-10 11:44:06 +02:00
"git.ewintr.nl/gte/cmd/cli/format"
2021-07-09 13:25:50 +02:00
"git.ewintr.nl/gte/internal/configuration"
"git.ewintr.nl/gte/internal/storage"
"git.ewintr.nl/gte/internal/task"
"git.ewintr.nl/gte/pkg/msend"
)
2021-08-16 06:54:45 +02:00
// Add sends an action to the NEW folder so it can be updated to a real task later
type Add struct {
2021-07-09 13:25:50 +02:00
disp *storage.Dispatcher
action string
}
2021-08-16 06:54:45 +02:00
func NewAdd(conf *configuration.Configuration, cmdArgs []string) (*Add, error) {
2021-07-09 13:25:50 +02:00
disp := storage.NewDispatcher(msend.NewSSLSMTP(conf.SMTP()))
2021-08-16 06:54:45 +02:00
return &Add{
2021-07-09 13:25:50 +02:00
disp: disp,
2021-08-16 06:54:45 +02:00
action: strings.Join(cmdArgs, " "),
2021-07-09 13:25:50 +02:00
}, nil
}
2021-08-16 06:54:45 +02:00
func (n *Add) Do() string {
2021-07-09 13:25:50 +02:00
if err := n.disp.Dispatch(&task.Task{Action: n.action}); err != nil {
2021-07-10 11:44:06 +02:00
return format.FormatError(err)
2021-07-09 13:25:50 +02:00
}
return "message sent\n"
}