gte/cmd/cli/command/today.go

40 lines
817 B
Go
Raw Normal View History

2021-07-09 09:42:44 +02:00
package command
import (
2021-07-10 11:44:06 +02:00
"git.ewintr.nl/gte/cmd/cli/format"
2021-07-09 09:42:44 +02:00
"git.ewintr.nl/gte/internal/configuration"
"git.ewintr.nl/gte/internal/process"
"git.ewintr.nl/gte/internal/storage"
"git.ewintr.nl/gte/internal/task"
)
2021-07-09 09:51:37 +02:00
// Today lists all task that are due today or past their due date
2021-07-09 09:42:44 +02:00
type Today struct {
lister *process.List
2021-07-09 09:42:44 +02:00
}
func NewToday(conf *configuration.Configuration) (*Today, error) {
local, err := storage.NewSqlite(conf.Sqlite())
if err != nil {
return &Today{}, err
}
reqs := process.ListReqs{
Due: task.Today,
IncludeBefore: true,
}
lister := process.NewList(local, reqs)
2021-07-09 09:42:44 +02:00
return &Today{
lister: lister,
2021-07-09 09:42:44 +02:00
}, nil
}
func (t *Today) Do() string {
res, err := t.lister.Process()
2021-07-09 09:42:44 +02:00
if err != nil {
2021-07-10 11:44:06 +02:00
return format.FormatError(err)
2021-07-09 09:42:44 +02:00
}
return format.FormatTaskTable(res.Tasks)
2021-07-09 09:42:44 +02:00
}