week command

This commit is contained in:
Erik Winter 2021-08-20 11:27:12 +02:00
parent 5b2e207e05
commit 0150704259
5 changed files with 48 additions and 4 deletions

View File

@ -37,6 +37,8 @@ func Parse(args []string, conf *configuration.Configuration) (Command, error) {
return NewToday(conf)
case "tomorrow":
return NewTomorrow(conf)
case "week":
return NewWeek(conf)
case "project":
return NewProject(conf, cmdArgs)
case "projects":

View File

@ -35,9 +35,5 @@ func (t *Tomorrow) Do() string {
return format.FormatError(err)
}
if len(res.Tasks) == 0 {
return "nothing to do tomorrow\n"
}
return format.FormatTaskTable(res.Tasks)
}

37
cmd/cli/command/week.go Normal file
View File

@ -0,0 +1,37 @@
package command
import (
"git.ewintr.nl/gte/cmd/cli/format"
"git.ewintr.nl/gte/internal/configuration"
"git.ewintr.nl/gte/internal/process"
"git.ewintr.nl/gte/internal/storage"
"git.ewintr.nl/gte/internal/task"
)
type Week struct {
lister *process.List
}
func NewWeek(conf *configuration.Configuration) (*Week, error) {
local, err := storage.NewSqlite(conf.Sqlite())
if err != nil {
return &Week{}, err
}
reqs := process.ListReqs{
Due: task.Today.Add(7),
IncludeBefore: true,
}
return &Week{
lister: process.NewList(local, reqs),
}, nil
}
func (w *Week) Do() string {
res, err := w.lister.Process()
if err != nil {
return format.FormatError(err)
}
return format.FormatTaskTable(res.Tasks)
}

View File

@ -2,6 +2,7 @@ package format
import (
"fmt"
"sort"
"strings"
"git.ewintr.nl/gte/internal/task"
@ -16,6 +17,8 @@ func FormatTaskTable(tasks []*task.LocalTask) string {
return "no tasks to display\n"
}
sort.Sort(task.ByDue(tasks))
var output string
for _, t := range tasks {
output += fmt.Sprintf("%d\t%s\t%s (%s, %s)\n", t.LocalId, t.Due.String(), t.Action, t.Project, strings.ToLower(t.Folder))

View File

@ -4,3 +4,9 @@ type LocalTask struct {
Task
LocalId int
}
type ByDue []*LocalTask
func (lt ByDue) Len() int { return len(lt) }
func (lt ByDue) Swap(i, j int) { lt[i], lt[j] = lt[j], lt[i] }
func (lt ByDue) Less(i, j int) bool { return lt[j].Due.After(lt[i].Due) }