2021-07-09 13:25:50 +02:00
|
|
|
package command
|
|
|
|
|
|
|
|
import (
|
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"
|
|
|
|
)
|
|
|
|
|
|
|
|
// New sends an action to the NEW folder so it can be updated to a real task later
|
|
|
|
type New struct {
|
|
|
|
disp *storage.Dispatcher
|
|
|
|
action string
|
|
|
|
}
|
|
|
|
|
2021-07-26 06:59:31 +02:00
|
|
|
func (n *New) Cmd() string { return "new" }
|
|
|
|
|
2021-07-09 13:25:50 +02:00
|
|
|
func NewNew(conf *configuration.Configuration, cmdArgs []string) (*New, error) {
|
|
|
|
if len(cmdArgs) != 1 {
|
|
|
|
return &New{}, ErrInvalidAmountOfArgs
|
|
|
|
}
|
|
|
|
|
|
|
|
disp := storage.NewDispatcher(msend.NewSSLSMTP(conf.SMTP()))
|
|
|
|
|
|
|
|
return &New{
|
|
|
|
disp: disp,
|
|
|
|
action: cmdArgs[0],
|
|
|
|
}, nil
|
|
|
|
}
|
|
|
|
|
|
|
|
func (n *New) Do() string {
|
|
|
|
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"
|
|
|
|
}
|