-
Notifications
You must be signed in to change notification settings - Fork 1
/
main.go
288 lines (269 loc) · 6.09 KB
/
main.go
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
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
package main
import (
"os"
"sort"
"github.com/tuxagon/yata-cli/cmd"
"github.com/tuxagon/yata-cli/yata"
"github.com/urfave/cli"
)
const (
// Version specifies the current release
Version = "1.1.0"
descAdd = "Create a new task"
descArchive = "Create an archive backup of the current tasks"
descComplete = "Marks a task as done"
descConfig = "Manage configuration options"
descDelete = "Deletes a task"
descFetch = "Fetches the data from the specified service"
descList = "Lists the tasks"
descMerge = "Merges the fetched tasks with the current tasks"
descPrune = "Removes all completed tasks"
descPush = "Uploads tasks data to the specified service"
descReset = "Erases all existing tasks and starts fresh"
descShow = "Displays a task based on its ID"
)
func main() {
app := cli.NewApp()
app.Name = "yata"
app.Usage = "A command line task manager"
app.Version = Version
app.Before = func(ctx *cli.Context) error {
yata.GetDirectory().Initialize()
if ctx.GlobalBool("verbose") {
yata.LogLevel = yata.LogVerbose
}
return nil
}
app.Authors = []cli.Author{
cli.Author{
Name: "Kenneth Bogner",
},
}
app.Flags = []cli.Flag{
cli.BoolFlag{
Name: "verbose",
Usage: "turn on verbose logging",
},
}
app.Commands = []cli.Command{
add(),
archive(),
complete(),
config(),
delete(),
fetch(),
list(),
merge(),
prune(),
push(),
reset(),
show(),
}
sort.Sort(cli.FlagsByName(app.Flags))
sort.Sort(cli.CommandsByName(app.Commands))
app.Run(os.Args)
}
func add() cli.Command {
cmd := cli.Command{
Name: "add",
Action: cmd.Add,
Aliases: []string{"new", "create"},
Usage: descAdd,
Description: descAdd,
Flags: []cli.Flag{
cli.StringFlag{
Name: "description,desc,d",
Usage: "specify the task description; tags can be included in description using the '#' prefix in the description text",
},
cli.StringFlag{
Name: "tags,t",
Usage: "specify tags outside of the description; list is comma-delimited",
},
cli.IntFlag{
Name: "priority,p",
Usage: "specify a priority for the task (1: Low, 2: Normal, 3: High)",
},
},
}
sort.Sort(cli.FlagsByName(cmd.Flags))
return cmd
}
func archive() cli.Command {
cmd := cli.Command{
Name: "archive",
Action: cmd.Archive,
Usage: descArchive,
Description: descArchive,
}
return cmd
}
func complete() cli.Command {
cmd := cli.Command{
Name: "complete",
Action: cmd.Complete,
Aliases: []string{"finish"},
Description: descComplete,
Usage: descComplete,
Flags: []cli.Flag{
cli.IntFlag{
Name: "id",
Usage: "specify the ID of the task to complete",
},
},
}
sort.Sort(cli.FlagsByName(cmd.Flags))
return cmd
}
func config() cli.Command {
return cli.Command{
Name: "config",
Action: cmd.Config,
Description: descConfig,
Usage: descConfig,
Flags: []cli.Flag{
cli.BoolFlag{
Name: "show-keys,k",
Usage: "show the possible keys you can set/read",
},
},
}
}
func delete() cli.Command {
return cli.Command{
Name: "delete",
Action: cmd.Delete,
Description: descDelete,
Usage: descDelete,
Flags: []cli.Flag{
cli.IntFlag{
Name: "id",
Usage: "specify the ID of the task to delete",
},
},
}
}
func fetch() cli.Command {
return cli.Command{
Name: "fetch",
Action: cmd.Fetch,
Description: descFetch,
Usage: descFetch,
Flags: []cli.Flag{
cli.BoolFlag{
Name: "google-drive,googledrive,drive,g",
Usage: "uploads tasks file to Google Drive if you have an API key set in the config",
},
},
}
}
func list() cli.Command {
cmd := cli.Command{
Name: "list",
Action: cmd.List,
Usage: descList,
Description: descList,
Flags: []cli.Flag{
cli.StringFlag{
Name: "sort",
Usage: "sort the results by the specified field",
},
cli.StringFlag{
Name: "tag,t",
Usage: "filter tasks by specified tag",
},
cli.StringFlag{
Name: "description,desc,d",
Usage: "filter tasks by description using a contains search",
},
cli.StringFlag{
Name: "format,f",
Usage: "specifies how the tasks should be displayed (json, default: simple)",
},
cli.BoolFlag{
Name: "all,a",
Usage: "display all tasks, including completed",
},
cli.BoolFlag{
Name: "show-tags",
Usage: "display tag information",
},
},
}
sort.Sort(cli.FlagsByName(cmd.Flags))
return cmd
}
func merge() cli.Command {
cmd := cli.Command{
Name: "merge",
Usage: descMerge,
Description: descMerge,
Action: cmd.Merge,
}
return cmd
}
func prune() cli.Command {
cmd := cli.Command{
Name: "prune",
Usage: descPrune,
Description: descPrune,
Action: cmd.Prune,
}
return cmd
}
func push() cli.Command {
cmd := cli.Command{
Name: "push",
Usage: descPush,
Description: descPush,
Action: cmd.Push,
Flags: []cli.Flag{
cli.BoolFlag{
Name: "google-drive,googledrive,drive,g",
Usage: "uploads tasks file to Google Drive if you have an API key set in the config",
},
},
}
return cmd
}
func reset() cli.Command {
cmd := cli.Command{
Name: "reset",
Action: cmd.Reset,
Usage: descReset,
Description: descReset,
Aliases: []string{"nuke"},
Flags: []cli.Flag{
cli.BoolFlag{
Name: "no-backup",
Usage: "prevent yata from making a backup before resetting",
},
cli.BoolFlag{
Name: "keep-id",
Usage: "keep the current incrementing ID rather than starting from 1 again",
},
},
}
sort.Sort(cli.FlagsByName(cmd.Flags))
return cmd
}
func show() cli.Command {
cmd := cli.Command{
Name: "show",
Action: cmd.Show,
Aliases: []string{"get"},
Usage: descShow,
Description: descShow,
Flags: []cli.Flag{
cli.IntFlag{
Name: "id",
Usage: "specify the ID of the task to complete",
},
cli.StringFlag{
Name: "format,f",
Usage: "specifies how the task should be displayed (json, default: simple)",
},
},
}
sort.Sort(cli.FlagsByName(cmd.Flags))
return cmd
}