This implementation uses a filter struct to create taskwarrior filters (like you would do in the command line) to export the filtered tasks into json which are parsed as go structs.
47 lines
915 B
Go
47 lines
915 B
Go
package taskwarrior
|
|
|
|
import (
|
|
"bytes"
|
|
"encoding/json"
|
|
"os/exec"
|
|
)
|
|
|
|
/// A task with an Id of 0 is either `completed` or `deleted` which is also
|
|
/// mentioned in the Status field
|
|
|
|
type Task struct {
|
|
Id uint
|
|
Project string
|
|
Tags []string
|
|
Description string
|
|
Annotations []Annotation
|
|
Status string
|
|
Due string
|
|
Entry string
|
|
Modified string
|
|
End string
|
|
Uuid string
|
|
Urgency float32
|
|
}
|
|
|
|
type Annotation struct {
|
|
Description string
|
|
Entry string
|
|
}
|
|
|
|
func GetTasks(filter Filter) ([]Task, error) {
|
|
filter.filter = append(filter.filter, "export")
|
|
cmd := exec.Command("task", filter.filter...)
|
|
out, err := cmd.Output()
|
|
if err != nil {
|
|
return nil, err
|
|
}
|
|
var tasks []Task
|
|
decoder := json.NewDecoder(bytes.NewBuffer(out))
|
|
decoder.DisallowUnknownFields()
|
|
if err = decoder.Decode(&tasks); err != nil {
|
|
return nil, err
|
|
}
|
|
return tasks, nil
|
|
}
|