gte/cmd/cli/command/today.go

43 lines
877 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 {
todayer *process.List
}
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,
}
todayer := process.NewList(local, reqs)
return &Today{
todayer: todayer,
}, nil
}
func (t *Today) Do() string {
res, err := t.todayer.Process()
if err != nil {
2021-07-10 11:44:06 +02:00
return format.FormatError(err)
2021-07-09 09:42:44 +02:00
}
if len(res.Tasks) == 0 {
return "nothing left\n"
}
2021-07-10 11:44:06 +02:00
return format.FormatTaskTable(res.Tasks)
2021-07-09 09:42:44 +02:00
}