This repository has been archived on 2025-10-30. You can view files and clone it. You cannot open issues or pull requests or push a commit.
Files
gitwarrior/internal/taskwarrior/task.go
Yves Biener 6f27c0a4d9 add(taskwarrior): get exported taskwarrior tasks
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.
2023-10-20 12:50:18 +02:00

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
}