gte/cmd/cli/command/tomorrow.go

45 lines
958 B
Go
Raw Normal View History

2021-07-09 09:51:37 +02:00
package command
import (
2022-06-05 14:37:50 +02:00
"sort"
2021-09-19 11:59:26 +02:00
"ewintr.nl/gte/cmd/cli/format"
"ewintr.nl/gte/internal/configuration"
"ewintr.nl/gte/internal/process"
"ewintr.nl/gte/internal/storage"
"ewintr.nl/gte/internal/task"
2021-07-09 09:51:37 +02:00
)
// Tomorrow lists all tasks that are due tomorrow
type Tomorrow struct {
lister *process.List
2021-07-09 09:51:37 +02:00
}
func NewTomorrow(conf *configuration.Configuration) (*Tomorrow, error) {
local, err := storage.NewSqlite(conf.Sqlite())
if err != nil {
return &Tomorrow{}, err
}
reqs := process.ListReqs{
2022-06-06 11:07:03 +02:00
Due: task.Today().Add(1),
ApplyUpdates: true,
2021-07-09 09:51:37 +02:00
}
lister := process.NewList(local, reqs)
2021-07-09 09:51:37 +02:00
return &Tomorrow{
lister: lister,
2021-07-09 09:51:37 +02:00
}, nil
}
func (t *Tomorrow) Do() string {
res, err := t.lister.Process()
2021-07-09 09:51:37 +02:00
if err != nil {
2021-07-10 11:44:06 +02:00
return format.FormatError(err)
2021-07-09 09:51:37 +02:00
}
2022-06-05 14:37:50 +02:00
sort.Sort(task.ByDefault(res.Tasks))
cols := []format.Column{format.COL_ID, format.COL_STATUS, format.COL_ACTION, format.COL_PROJECT}
2021-07-09 09:51:37 +02:00
2022-06-05 14:37:50 +02:00
return format.FormatTaskTable(res.Tasks, cols)
2021-07-09 09:51:37 +02:00
}