summaryrefslogtreecommitdiff
path: root/internal/task/taskwarrior.go
blob: 10b31b60121c56c339c715f1ae7e5e4da9998a36 (plain)
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
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
package task

import (
	"context"
	"os/exec"
	"time"
)

// Taskwarrior describes the Taskwarrior operations required by the UI.
type Taskwarrior interface {
	Export(ctx context.Context, filters ...string) ([]Task, error)
	SortTasks(tasks []Task)
	TotalTasks(tasks []Task) int
	InProgressTasks(tasks []Task) int
	DueTasks(tasks []Task, now time.Time) int
	EditCmd(id int) *exec.Cmd
	RunShellLine(ctx context.Context, line string) (RunResult, error)
	LoadCompletionSources(ctx context.Context) CompletionSources
	AddLineContext(ctx context.Context, line string) error
	AnnotateContext(ctx context.Context, id int, text string) error
	ReplaceAnnotations(ctx context.Context, id int, text string) error
	SetDescriptionContext(ctx context.Context, id int, desc string) error
	AddTagsContext(ctx context.Context, id int, tags []string) error
	RemoveTagsContext(ctx context.Context, id int, tags []string) error
	SetDueDateContext(ctx context.Context, id int, due string) error
	SetRecurrenceContext(ctx context.Context, id int, rec string) error
	SetProjectContext(ctx context.Context, id int, project string) error
	SetPriorityContext(ctx context.Context, id int, priority string) error
	StartContext(ctx context.Context, id int) error
	StopContext(ctx context.Context, id int) error
	DoneContext(ctx context.Context, id int) error
	SetStatusUUIDContext(ctx context.Context, uuid, status string) error
	RecurringSeries(ctx context.Context, rootUUID string) ([]Task, error)
}

// Client is the production Taskwarrior implementation backed by the task CLI.
type Client struct{}

var _ Taskwarrior = Client{}

// NewTaskwarrior returns a production Taskwarrior Client.
func NewTaskwarrior() Client {
	return Client{}
}

// Export retrieves tasks using Taskwarrior export.
func (Client) Export(ctx context.Context, filters ...string) ([]Task, error) {
	return Export(ctx, filters...)
}

// SortTasks orders tasks using TaskSamurai's default task ordering.
func (Client) SortTasks(tasks []Task) {
	SortTasks(tasks)
}

// TotalTasks returns the number of tasks provided.
func (Client) TotalTasks(tasks []Task) int {
	return TotalTasks(tasks)
}

// InProgressTasks returns the number of started, incomplete tasks.
func (Client) InProgressTasks(tasks []Task) int {
	return InProgressTasks(tasks)
}

// DueTasks returns the number of due tasks.
func (Client) DueTasks(tasks []Task, now time.Time) int {
	return DueTasks(tasks, now)
}

// EditCmd returns an editor command for a task.
func (Client) EditCmd(id int) *exec.Cmd {
	return EditCmd(id)
}

// RunShellLine runs a user-entered Taskwarrior shell command.
func (Client) RunShellLine(ctx context.Context, line string) (RunResult, error) {
	return RunShellLine(ctx, line)
}

// LoadCompletionSources returns Taskwarrior-provided completion candidates.
func (Client) LoadCompletionSources(ctx context.Context) CompletionSources {
	return LoadCompletionSources(ctx)
}

// AddLineContext adds a task from a shell-style input line.
func (Client) AddLineContext(ctx context.Context, line string) error {
	return AddLineContext(ctx, line)
}

// AnnotateContext adds an annotation to a task.
func (Client) AnnotateContext(ctx context.Context, id int, text string) error {
	return AnnotateContext(ctx, id, text)
}

// ReplaceAnnotations replaces all annotations on a task.
func (Client) ReplaceAnnotations(ctx context.Context, id int, text string) error {
	return ReplaceAnnotations(ctx, id, text)
}

// SetDescriptionContext changes a task description.
func (Client) SetDescriptionContext(ctx context.Context, id int, desc string) error {
	return SetDescriptionContext(ctx, id, desc)
}

// AddTagsContext adds tags to a task.
func (Client) AddTagsContext(ctx context.Context, id int, tags []string) error {
	return AddTagsContext(ctx, id, tags)
}

// RemoveTagsContext removes tags from a task.
func (Client) RemoveTagsContext(ctx context.Context, id int, tags []string) error {
	return RemoveTagsContext(ctx, id, tags)
}

// SetDueDateContext changes a task due date.
func (Client) SetDueDateContext(ctx context.Context, id int, due string) error {
	return SetDueDateContext(ctx, id, due)
}

// SetRecurrenceContext changes a task recurrence value.
func (Client) SetRecurrenceContext(ctx context.Context, id int, rec string) error {
	return SetRecurrenceContext(ctx, id, rec)
}

// SetProjectContext changes a task project.
func (Client) SetProjectContext(ctx context.Context, id int, project string) error {
	return SetProjectContext(ctx, id, project)
}

// SetPriorityContext changes a task priority.
func (Client) SetPriorityContext(ctx context.Context, id int, priority string) error {
	return SetPriorityContext(ctx, id, priority)
}

// StartContext starts a task.
func (Client) StartContext(ctx context.Context, id int) error {
	return StartContext(ctx, id)
}

// StopContext stops a task.
func (Client) StopContext(ctx context.Context, id int) error {
	return StopContext(ctx, id)
}

// DoneContext completes a task.
func (Client) DoneContext(ctx context.Context, id int) error {
	return DoneContext(ctx, id)
}

// SetStatusUUIDContext changes a task status by UUID.
func (Client) SetStatusUUIDContext(ctx context.Context, uuid, status string) error {
	return SetStatusUUIDContext(ctx, uuid, status)
}

// RecurringSeries returns a recurring task series.
func (Client) RecurringSeries(ctx context.Context, rootUUID string) ([]Task, error) {
	return RecurringSeries(ctx, rootUUID)
}