quick new command
This commit is contained in:
parent
be904187e1
commit
33c53e5286
|
@ -1,11 +1,16 @@
|
|||
package command
|
||||
|
||||
import (
|
||||
"errors"
|
||||
"fmt"
|
||||
|
||||
"git.ewintr.nl/gte/internal/configuration"
|
||||
)
|
||||
|
||||
var (
|
||||
ErrInvalidAmountOfArgs = errors.New("invalid amount of args")
|
||||
)
|
||||
|
||||
type Command interface {
|
||||
Do() string
|
||||
}
|
||||
|
@ -15,7 +20,7 @@ func Parse(args []string, conf *configuration.Configuration) (Command, error) {
|
|||
return NewEmpty()
|
||||
}
|
||||
|
||||
cmd, _ := args[0], args[1:]
|
||||
cmd, cmdArgs := args[0], args[1:]
|
||||
switch cmd {
|
||||
case "sync":
|
||||
return NewSync(conf)
|
||||
|
@ -23,6 +28,8 @@ func Parse(args []string, conf *configuration.Configuration) (Command, error) {
|
|||
return NewToday(conf)
|
||||
case "tomorrow":
|
||||
return NewTomorrow(conf)
|
||||
case "new":
|
||||
return NewNew(conf, cmdArgs)
|
||||
default:
|
||||
return NewEmpty()
|
||||
}
|
||||
|
|
|
@ -0,0 +1,35 @@
|
|||
package command
|
||||
|
||||
import (
|
||||
"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
|
||||
}
|
||||
|
||||
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 {
|
||||
return FormatError(err)
|
||||
}
|
||||
|
||||
return "message sent\n"
|
||||
}
|
Loading…
Reference in New Issue