From be904187e18ae37191c74a6cbfa01a67e9ce905e Mon Sep 17 00:00:00 2001 From: Erik Winter Date: Fri, 9 Jul 2021 09:51:37 +0200 Subject: [PATCH] tomorrow command --- cmd/cli/command/command.go | 2 ++ cmd/cli/command/today.go | 1 + cmd/cli/command/tomorrow.go | 49 +++++++++++++++++++++++++++++++++++++ 3 files changed, 52 insertions(+) create mode 100644 cmd/cli/command/tomorrow.go diff --git a/cmd/cli/command/command.go b/cmd/cli/command/command.go index 28782ce..036c387 100644 --- a/cmd/cli/command/command.go +++ b/cmd/cli/command/command.go @@ -21,6 +21,8 @@ func Parse(args []string, conf *configuration.Configuration) (Command, error) { return NewSync(conf) case "today": return NewToday(conf) + case "tomorrow": + return NewTomorrow(conf) default: return NewEmpty() } diff --git a/cmd/cli/command/today.go b/cmd/cli/command/today.go index 33fc319..3f5aba2 100644 --- a/cmd/cli/command/today.go +++ b/cmd/cli/command/today.go @@ -9,6 +9,7 @@ import ( "git.ewintr.nl/gte/internal/task" ) +// Today lists all task that are due today or past their due date type Today struct { todayer *process.List } diff --git a/cmd/cli/command/tomorrow.go b/cmd/cli/command/tomorrow.go new file mode 100644 index 0000000..49d4251 --- /dev/null +++ b/cmd/cli/command/tomorrow.go @@ -0,0 +1,49 @@ +package command + +import ( + "fmt" + + "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 { + return FormatError(err) + } + + if len(res.Tasks) == 0 { + return "nothing to do tomorrow\n" + } + + var msg string + for _, t := range res.Tasks { + msg += fmt.Sprintf("%s - %s", t.Project, t.Action) + } + + return msg +}