diff --git a/cmd/cli/command/command.go b/cmd/cli/command/command.go index 03d9429..fd75e70 100644 --- a/cmd/cli/command/command.go +++ b/cmd/cli/command/command.go @@ -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": diff --git a/cmd/cli/command/tomorrow.go b/cmd/cli/command/tomorrow.go index b5673c1..9aad2d0 100644 --- a/cmd/cli/command/tomorrow.go +++ b/cmd/cli/command/tomorrow.go @@ -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) } diff --git a/cmd/cli/command/week.go b/cmd/cli/command/week.go new file mode 100644 index 0000000..8a1130a --- /dev/null +++ b/cmd/cli/command/week.go @@ -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) +} diff --git a/cmd/cli/format/format.go b/cmd/cli/format/format.go index 68ec3a4..646586d 100644 --- a/cmd/cli/format/format.go +++ b/cmd/cli/format/format.go @@ -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)) diff --git a/internal/task/localtask.go b/internal/task/localtask.go index 5c6a10e..a7eaac8 100644 --- a/internal/task/localtask.go +++ b/internal/task/localtask.go @@ -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) }