renamed new to add

This commit is contained in:
Erik Winter 2021-08-16 06:54:45 +02:00
parent 053647de76
commit fbc2a3d400
2 changed files with 11 additions and 13 deletions

View File

@ -1,6 +1,8 @@
package command package command
import ( import (
"strings"
"git.ewintr.nl/gte/cmd/cli/format" "git.ewintr.nl/gte/cmd/cli/format"
"git.ewintr.nl/gte/internal/configuration" "git.ewintr.nl/gte/internal/configuration"
"git.ewintr.nl/gte/internal/storage" "git.ewintr.nl/gte/internal/storage"
@ -8,28 +10,24 @@ import (
"git.ewintr.nl/gte/pkg/msend" "git.ewintr.nl/gte/pkg/msend"
) )
// New sends an action to the NEW folder so it can be updated to a real task later // Add sends an action to the NEW folder so it can be updated to a real task later
type New struct { type Add struct {
disp *storage.Dispatcher disp *storage.Dispatcher
action string action string
} }
func (n *New) Cmd() string { return "new" } func (n *Add) Cmd() string { return "new" }
func NewNew(conf *configuration.Configuration, cmdArgs []string) (*New, error) {
if len(cmdArgs) != 1 {
return &New{}, ErrInvalidAmountOfArgs
}
func NewAdd(conf *configuration.Configuration, cmdArgs []string) (*Add, error) {
disp := storage.NewDispatcher(msend.NewSSLSMTP(conf.SMTP())) disp := storage.NewDispatcher(msend.NewSSLSMTP(conf.SMTP()))
return &New{ return &Add{
disp: disp, disp: disp,
action: cmdArgs[0], action: strings.Join(cmdArgs, " "),
}, nil }, nil
} }
func (n *New) Do() string { func (n *Add) Do() string {
if err := n.disp.Dispatch(&task.Task{Action: n.action}); err != nil { if err := n.disp.Dispatch(&task.Task{Action: n.action}); err != nil {
return format.FormatError(err) return format.FormatError(err)
} }

View File

@ -38,8 +38,8 @@ func Parse(args []string, conf *configuration.Configuration) (Command, error) {
return NewToday(conf) return NewToday(conf)
case "tomorrow": case "tomorrow":
return NewTomorrow(conf) return NewTomorrow(conf)
case "new": case "add":
return NewNew(conf, cmdArgs) return NewAdd(conf, cmdArgs)
default: default:
return NewEmpty() return NewEmpty()
} }