gte/cmd/cli/command/tomorrow.go

44 lines
880 B
Go
Raw Normal View History

2021-07-09 09:51:37 +02:00
package command
import (
2021-07-10 11:44:06 +02:00
"git.ewintr.nl/gte/cmd/cli/format"
2021-07-09 09:51:37 +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"
)
// Tomorrow lists all tasks that are due tomorrow
type Tomorrow struct {
tomorrower *process.List
}
func NewTomorrow(conf *configuration.Configuration) (*Tomorrow, error) {
local, err := storage.NewSqlite(conf.Sqlite())
if err != nil {
return &Tomorrow{}, err
}
reqs := process.ListReqs{
Due: task.Today.Add(1),
}
tomorrower := process.NewList(local, reqs)
return &Tomorrow{
tomorrower: tomorrower,
}, nil
}
func (t *Tomorrow) Do() string {
res, err := t.tomorrower.Process()
if err != nil {
2021-07-10 11:44:06 +02:00
return format.FormatError(err)
2021-07-09 09:51:37 +02:00
}
if len(res.Tasks) == 0 {
return "nothing to do tomorrow\n"
}
2021-07-10 11:44:06 +02:00
return format.FormatTaskTable(res.Tasks)
2021-07-09 09:51:37 +02:00
}