output tasks only from the last 24 hours by default, add more task output options
This commit is contained in:
parent
1d59d0f7d0
commit
6dcdf6c826
9
main.go
9
main.go
|
@ -59,10 +59,14 @@ func list(path *string) func(*cli.Cmd) {
|
||||||
cmd.Spec = "[OPTIONS]"
|
cmd.Spec = "[OPTIONS]"
|
||||||
var (
|
var (
|
||||||
asJSON = cmd.BoolOpt("json", false, "output task history as JSON")
|
asJSON = cmd.BoolOpt("json", false, "output task history as JSON")
|
||||||
assend = cmd.BoolOpt("assend", true, "sort tasks assending in age")
|
assend = cmd.BoolOpt("assend", false, "sort tasks assending in age")
|
||||||
|
all = cmd.BoolOpt("a all", false, "output all tasks")
|
||||||
limit = cmd.IntOpt("n limit", 0, "limit the number of results by n")
|
limit = cmd.IntOpt("n limit", 0, "limit the number of results by n")
|
||||||
|
duration = cmd.StringOpt("d duration", "24h", "show tasks within this duration")
|
||||||
)
|
)
|
||||||
cmd.Action = func() {
|
cmd.Action = func() {
|
||||||
|
duration, err := time.ParseDuration(*duration)
|
||||||
|
maybe(err)
|
||||||
db, err := NewStore(*path)
|
db, err := NewStore(*path)
|
||||||
maybe(err)
|
maybe(err)
|
||||||
defer db.Close()
|
defer db.Close()
|
||||||
|
@ -71,6 +75,9 @@ func list(path *string) func(*cli.Cmd) {
|
||||||
if *assend {
|
if *assend {
|
||||||
sort.Sort(sort.Reverse(ByID(tasks)))
|
sort.Sort(sort.Reverse(ByID(tasks)))
|
||||||
}
|
}
|
||||||
|
if !*all {
|
||||||
|
tasks = After(time.Now().Add(-duration), tasks)
|
||||||
|
}
|
||||||
if *limit > 0 && (len(tasks) > *limit) {
|
if *limit > 0 && (len(tasks) > *limit) {
|
||||||
tasks = tasks[0:*limit]
|
tasks = tasks[0:*limit]
|
||||||
}
|
}
|
||||||
|
|
14
types.go
14
types.go
|
@ -151,6 +151,20 @@ func (b ByID) Len() int { return len(b) }
|
||||||
func (b ByID) Swap(i, j int) { b[i], b[j] = b[j], b[i] }
|
func (b ByID) Swap(i, j int) { b[i], b[j] = b[j], b[i] }
|
||||||
func (b ByID) Less(i, j int) bool { return b[i].ID < b[j].ID }
|
func (b ByID) Less(i, j int) bool { return b[i].ID < b[j].ID }
|
||||||
|
|
||||||
|
// After returns tasks that were started after the
|
||||||
|
// provided start time.
|
||||||
|
func After(start time.Time, tasks []*Task) []*Task {
|
||||||
|
filtered := []*Task{}
|
||||||
|
for _, task := range tasks {
|
||||||
|
if len(task.Pomodoros) > 0 {
|
||||||
|
if start.Before(task.Pomodoros[0].Start) {
|
||||||
|
filtered = append(filtered, task)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return filtered
|
||||||
|
}
|
||||||
|
|
||||||
// Pomodoro is a unit of time to spend working
|
// Pomodoro is a unit of time to spend working
|
||||||
// on a single task.
|
// on a single task.
|
||||||
type Pomodoro struct {
|
type Pomodoro struct {
|
||||||
|
|
Loading…
Reference in New Issue