week command
This commit is contained in:
parent
5b2e207e05
commit
0150704259
|
@ -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":
|
||||
|
|
|
@ -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)
|
||||
}
|
||||
|
|
|
@ -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)
|
||||
}
|
|
@ -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))
|
||||
|
|
|
@ -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) }
|
||||
|
|
Loading…
Reference in New Issue