Repository navigation
Expand file tree
/
Copy pathtypes.go
More file actions
250 lines (219 loc) · 6.29 KB
/
Copy pathtypes.go
File metadata and controls
250 lines (219 loc) · 6.29 KB
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
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
package things3
import (
"encoding/json"
"fmt"
"github.com/moond4rk/things3/internal/scheme"
)
// String constant for unknown enum values.
const unknownString = "unknown"
// Status string constants.
const (
statusStringIncomplete = "incomplete"
statusStringCompleted = "completed"
statusStringCanceled = "canceled"
)
// taskType represents the kind of task in the Things 3 database.
// Users distinguish types through Go's type system (Todo, Project, Heading),
// not through this enum. It remains internal for query filter routing.
type taskType int
const (
taskTypeTodo taskType = 0
taskTypeProject taskType = 1
taskTypeHeading taskType = 2
)
// Status represents the completion status of a task.
type Status int
const (
// StatusIncomplete indicates the task is not yet completed.
StatusIncomplete Status = 0
// StatusCanceled indicates the task was canceled.
StatusCanceled Status = 2
// StatusCompleted indicates the task was completed.
StatusCompleted Status = 3
)
// String returns the string representation of the Status.
func (s Status) String() string {
switch s {
case StatusIncomplete:
return statusStringIncomplete
case StatusCanceled:
return statusStringCanceled
case StatusCompleted:
return statusStringCompleted
default:
return unknownString
}
}
// MarshalJSON implements json.Marshaler for Status.
func (s Status) MarshalJSON() ([]byte, error) {
return json.Marshal(s.String())
}
// MarshalYAML implements yaml.Marshaler for Status.
func (s Status) MarshalYAML() (any, error) {
return s.String(), nil
}
// UnmarshalJSON implements json.Unmarshaler for Status.
func (s *Status) UnmarshalJSON(data []byte) error {
var str string
if err := json.Unmarshal(data, &str); err != nil {
return err
}
v, err := parseStatus(str)
if err != nil {
return err
}
*s = v
return nil
}
// UnmarshalYAML implements yaml.Unmarshaler for Status.
func (s *Status) UnmarshalYAML(unmarshal func(any) error) error {
var str string
if err := unmarshal(&str); err != nil {
return err
}
v, err := parseStatus(str)
if err != nil {
return err
}
*s = v
return nil
}
// parseStatus converts a string to Status.
func parseStatus(s string) (Status, error) {
switch s {
case statusStringIncomplete:
return StatusIncomplete, nil
case statusStringCanceled:
return StatusCanceled, nil
case statusStringCompleted:
return StatusCompleted, nil
default:
return 0, fmt.Errorf("things3: unknown status %q", s)
}
}
// IsOpen returns true if the status indicates an open (incomplete) task.
func (s Status) IsOpen() bool {
return s == StatusIncomplete
}
// IsClosed returns true if the status indicates a closed (completed or canceled) task.
func (s Status) IsClosed() bool {
return s == StatusCompleted || s == StatusCanceled
}
// StartBucket represents the scheduling bucket for a task.
type StartBucket int
const (
// StartInbox indicates the task is in the Inbox.
StartInbox StartBucket = 0
// StartAnytime indicates the task is scheduled for Anytime.
StartAnytime StartBucket = 1
// StartSomeday indicates the task is scheduled for Someday.
StartSomeday StartBucket = 2
)
// Start bucket string constants.
const (
startBucketStringInbox = "inbox"
startBucketStringAnytime = "anytime"
startBucketStringSomeday = "someday"
)
// String returns the string representation of the StartBucket.
func (s StartBucket) String() string {
switch s {
case StartInbox:
return startBucketStringInbox
case StartAnytime:
return startBucketStringAnytime
case StartSomeday:
return startBucketStringSomeday
default:
return unknownString
}
}
// MarshalJSON implements json.Marshaler for StartBucket.
func (s StartBucket) MarshalJSON() ([]byte, error) {
return json.Marshal(s.String())
}
// MarshalYAML implements yaml.Marshaler for StartBucket.
func (s StartBucket) MarshalYAML() (any, error) {
return s.String(), nil
}
// UnmarshalJSON implements json.Unmarshaler for StartBucket.
func (s *StartBucket) UnmarshalJSON(data []byte) error {
var str string
if err := json.Unmarshal(data, &str); err != nil {
return err
}
v, err := parseStartBucket(str)
if err != nil {
return err
}
*s = v
return nil
}
// UnmarshalYAML implements yaml.Unmarshaler for StartBucket.
func (s *StartBucket) UnmarshalYAML(unmarshal func(any) error) error {
var str string
if err := unmarshal(&str); err != nil {
return err
}
v, err := parseStartBucket(str)
if err != nil {
return err
}
*s = v
return nil
}
// parseStartBucket converts a string to StartBucket.
func parseStartBucket(s string) (StartBucket, error) {
switch s {
case startBucketStringInbox:
return StartInbox, nil
case startBucketStringAnytime:
return StartAnytime, nil
case startBucketStringSomeday:
return StartSomeday, nil
default:
return 0, fmt.Errorf("things3: unknown start bucket %q", s)
}
}
// Command represents Things URL scheme commands (aliased from internal/scheme).
type Command = scheme.Command
// Command constants for Things URL scheme.
const (
CommandShow = scheme.CommandShow
CommandAdd = scheme.CommandAdd
CommandAddProject = scheme.CommandAddProject
CommandUpdate = scheme.CommandUpdate
CommandUpdateProject = scheme.CommandUpdateProject
CommandSearch = scheme.CommandSearch
CommandVersion = scheme.CommandVersion
CommandJSON = scheme.CommandJSON
)
// ListID represents built-in Things list identifiers (aliased from internal/scheme).
type ListID = scheme.ListID
// ListID constants for built-in Things lists.
const (
ListInbox = scheme.ListInbox
ListToday = scheme.ListToday
ListAnytime = scheme.ListAnytime
ListUpcoming = scheme.ListUpcoming
ListSomeday = scheme.ListSomeday
ListLogbook = scheme.ListLogbook
ListTomorrow = scheme.ListTomorrow
ListDeadlines = scheme.ListDeadlines
ListRepeating = scheme.ListRepeating
ListAllProjects = scheme.ListAllProjects
ListLoggedProjects = scheme.ListLoggedProjects
)
// JSON batch operation types (aliased from internal/scheme).
type (
JSONOperation = scheme.JSONOperation
JSONItemType = scheme.JSONItemType
JSONItem = scheme.JSONItem
)
// JSON operation constants.
const (
JSONOperationCreate = scheme.JSONOperationCreate
JSONOperationUpdate = scheme.JSONOperationUpdate
JSONItemTypeTodo = scheme.JSONItemTypeTodo
JSONItemTypeProject = scheme.JSONItemTypeProject
)