gte/cmd/cli/command/done.go

46 lines
944 B
Go
Raw Normal View History

2021-07-10 12:30:38 +02:00
package command
import (
"git.ewintr.nl/gte/cmd/cli/format"
"git.ewintr.nl/gte/internal/configuration"
"git.ewintr.nl/gte/internal/process"
"git.ewintr.nl/gte/internal/storage"
"git.ewintr.nl/gte/pkg/msend"
)
// Done updates a task to be marked done
type Done struct {
doner *process.Update
}
2021-07-26 06:59:31 +02:00
func (d *Done) Cmd() string { return "done" }
2021-07-29 07:01:24 +02:00
func NewDone(localId int, conf *configuration.Configuration) (*Done, error) {
2021-07-10 12:30:38 +02:00
local, err := storage.NewSqlite(conf.Sqlite())
if err != nil {
return &Done{}, err
}
disp := storage.NewDispatcher(msend.NewSSLSMTP(conf.SMTP()))
fields := process.UpdateFields{"done": "true"}
2021-07-29 07:01:24 +02:00
tId, err := findId(localId, local)
2021-07-14 07:17:53 +02:00
if err != nil {
return &Done{}, err
}
2021-07-10 12:30:38 +02:00
2021-07-14 07:17:53 +02:00
updater := process.NewUpdate(local, disp, tId, fields)
2021-07-10 12:30:38 +02:00
return &Done{
doner: updater,
}, nil
}
func (d *Done) Do() string {
err := d.doner.Process()
if err != nil {
return format.FormatError(err)
}
return "message sent\n"
}