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 {
|
2021-07-14 07:17:53 +02:00
|
|
|
local storage.LocalRepository
|
2021-07-09 09:42:44 +02:00
|
|
|
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{
|
2021-07-14 07:17:53 +02:00
|
|
|
local: local,
|
2021-07-09 09:42:44 +02:00
|
|
|
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-14 07:17:53 +02:00
|
|
|
return format.FormatTaskTable(t.local, res.Tasks)
|
2021-07-09 09:42:44 +02:00
|
|
|
}
|