1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
|
package askcli
import (
"encoding/json"
"fmt"
"io"
)
// TaskExport mirrors the JSON structure returned by Taskwarrior export commands.
type TaskExport struct {
UUID string `json:"uuid"`
Project string `json:"project,omitempty"`
Description string `json:"description"`
Status string `json:"status"`
Priority string `json:"priority"`
Tags []string `json:"tags"`
Start string `json:"start,omitempty"`
Urgency float64 `json:"urgency"`
Depends []string `json:"depends"`
Annotations []struct {
Description string `json:"description"`
Entry string `json:"entry"`
} `json:"annotations"`
}
// ParseTaskExport decodes Taskwarrior JSON from the supplied reader.
func ParseTaskExport(r io.Reader) ([]TaskExport, error) {
data, err := io.ReadAll(r)
if err != nil {
return nil, fmt.Errorf("failed to read task export data: %w", err)
}
var tasks []TaskExport
if err := json.Unmarshal(data, &tasks); err != nil {
return nil, fmt.Errorf("failed to parse task export JSON: %w", err)
}
return tasks, nil
}
type taskExportWithID struct {
ID string `json:"id,omitempty"`
TaskExport
}
func withTaskIDs(tasks []TaskExport, aliases map[string]string) []taskExportWithID {
withIDs := make([]taskExportWithID, len(tasks))
for i := range withIDs {
withIDs[i] = taskExportWithID{
ID: displayTaskAlias(tasks[i].UUID, aliases),
TaskExport: tasks[i],
}
}
return withIDs
}
|