todo-jsonl 0.1.20 → 0.1.28
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/bin/todo.rb +77 -62
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 2869302296a5a0ab3af889b0a76926cfba6d59552d5e4103524dae1ae3e7fd50
|
4
|
+
data.tar.gz: f2d7d03e8b62139d3197386c44391caf4a9d4fae545012389272cebdca61c3d9
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 40c72337ffd6a818adf28ef001cbd3b4f365af92d1fecd9a36ea361522a2125d83500ed76d4633df228c2c87a987083b08541452e7129af914452e7ca6652563
|
7
|
+
data.tar.gz: 6f42e59df9b34c140f3c6bba11010f0b6a3f7a3c45d1c7b23d5ded213ee2562e62a963b3e889a6886b97ff991e49e78af6efccf898fd951220c1cad8bcb2f66d
|
data/bin/todo.rb
CHANGED
@@ -115,9 +115,14 @@ class Todo
|
|
115
115
|
raise action + ' command requires exactly one parameter' if args.length != 1
|
116
116
|
show(args.first.to_i)
|
117
117
|
when 'help'
|
118
|
+
raise action + ' command has no parameters' if args.length > 0
|
118
119
|
puts usage
|
119
120
|
when 'repl'
|
121
|
+
raise action + ' command has no parameters' if args.length > 0
|
120
122
|
start_repl
|
123
|
+
when 'cleanup'
|
124
|
+
raise action + ' command requires at least one parameter' if args.nil? || args.empty?
|
125
|
+
cleanup(args)
|
121
126
|
else
|
122
127
|
list(nil, arguments)
|
123
128
|
end
|
@@ -150,6 +155,7 @@ class Todo
|
|
150
155
|
* list <regex> [regex...] list tasks (only active tasks by default)
|
151
156
|
* show <tasknumber> show all task details
|
152
157
|
* repl enter read-eval-print loop mode
|
158
|
+
* cleanup <regex> [regex...] cleanup completed tasks by regex
|
153
159
|
* help this help screen
|
154
160
|
|
155
161
|
With list command the following pre-defined regex patterns can be also used:
|
@@ -195,9 +201,7 @@ class Todo
|
|
195
201
|
end
|
196
202
|
end
|
197
203
|
end
|
198
|
-
if item_to_check && !tasks.has_key?(item_to_check)
|
199
|
-
raise "#{item_to_check}: No such todo"
|
200
|
-
end
|
204
|
+
raise "#{item_to_check}: No such todo" if item_to_check && !tasks.has_key?(item_to_check)
|
201
205
|
tasks
|
202
206
|
end
|
203
207
|
|
@@ -231,22 +235,29 @@ class Todo
|
|
231
235
|
list
|
232
236
|
end
|
233
237
|
|
234
|
-
def
|
238
|
+
def update_task(item, post_action, update_function)
|
235
239
|
tasks = load_tasks(item)
|
236
|
-
tasks[item]
|
240
|
+
update_function.call(tasks[item])
|
237
241
|
tasks[item][:modified] = @today.strftime(DATE_FORMAT)
|
238
|
-
postprocess_tags(tasks[item])
|
239
242
|
write_tasks(tasks)
|
240
|
-
|
243
|
+
case post_action
|
244
|
+
when :show then show(item, tasks)
|
245
|
+
when :list then list(tasks)
|
246
|
+
end
|
247
|
+
end
|
248
|
+
|
249
|
+
def append(item, text = '')
|
250
|
+
update_task(item, :list, lambda do |task|
|
251
|
+
task[:title] = [task[:title], text].join(' ')
|
252
|
+
postprocess_tags(task)
|
253
|
+
end)
|
241
254
|
end
|
242
255
|
|
243
256
|
def rename(item, text)
|
244
|
-
|
245
|
-
|
246
|
-
|
247
|
-
|
248
|
-
write_tasks(tasks)
|
249
|
-
list(tasks)
|
257
|
+
update_task(item, :list, lambda do |task|
|
258
|
+
task[:title] = text
|
259
|
+
postprocess_tags(task)
|
260
|
+
end)
|
250
261
|
end
|
251
262
|
|
252
263
|
def delete(item)
|
@@ -257,52 +268,38 @@ class Todo
|
|
257
268
|
end
|
258
269
|
|
259
270
|
def change_state(item, state, note = nil)
|
260
|
-
|
261
|
-
|
262
|
-
|
263
|
-
|
264
|
-
|
265
|
-
|
266
|
-
end
|
267
|
-
write_tasks(tasks)
|
268
|
-
list(tasks)
|
271
|
+
update_task(item, :list, lambda do |task|
|
272
|
+
task[:state] = state
|
273
|
+
if !note.nil? && !note.empty?
|
274
|
+
task[:note] ||= []
|
275
|
+
task[:note].push(note)
|
276
|
+
end
|
277
|
+
end)
|
269
278
|
end
|
270
279
|
|
271
280
|
def set_priority(item, note = nil)
|
272
|
-
|
273
|
-
|
274
|
-
|
275
|
-
|
276
|
-
|
277
|
-
|
278
|
-
|
279
|
-
end
|
280
|
-
write_tasks(tasks)
|
281
|
-
list(tasks)
|
281
|
+
update_task(item, :list, lambda do |task|
|
282
|
+
task[:priority] = !task[:priority]
|
283
|
+
task.delete(:priority) if !task[:priority]
|
284
|
+
if !note.nil? && !note.empty?
|
285
|
+
task[:note] ||= []
|
286
|
+
task[:note].push(note)
|
287
|
+
end
|
288
|
+
end)
|
282
289
|
end
|
283
290
|
|
284
291
|
def due_date(item, date = '')
|
285
|
-
|
286
|
-
|
287
|
-
|
288
|
-
|
289
|
-
write_tasks(tasks)
|
290
|
-
list(tasks)
|
292
|
+
update_task(item, :list, lambda do |task|
|
293
|
+
task[:due] = convert_due_date(date)
|
294
|
+
task.delete(:due) if task[:due].nil?
|
295
|
+
end)
|
291
296
|
end
|
292
297
|
|
293
298
|
def list(tasks = nil, patterns = nil)
|
294
|
-
items = {}
|
295
299
|
tasks = tasks || load_tasks
|
296
300
|
task_indent = [tasks.keys.max.to_s.size, 4].max
|
297
|
-
patterns = patterns.nil? || patterns.empty? ? [
|
298
|
-
|
299
|
-
normalized_task = "state=#{task[:state]} due=#{task[:due]} #{task[:title]}"
|
300
|
-
match = true
|
301
|
-
patterns.each do |pattern|
|
302
|
-
match = false unless /#{@queries[pattern] || pattern}/ix.match(normalized_task)
|
303
|
-
end
|
304
|
-
items[num] = task if match
|
305
|
-
end
|
301
|
+
patterns = patterns.nil? || patterns.empty? ? [':active'] : patterns
|
302
|
+
items = filter_tasks(tasks, patterns)
|
306
303
|
items = items.sort_by do |num, task|
|
307
304
|
[task[:priority] && task[:state] != 'done' ? 0 : 1, ORDER[task[:state] || 'default'], task[:due] || 'n/a', num]
|
308
305
|
end
|
@@ -332,24 +329,20 @@ class Todo
|
|
332
329
|
end
|
333
330
|
|
334
331
|
def add_note(item, text)
|
335
|
-
|
336
|
-
|
337
|
-
|
338
|
-
|
339
|
-
write_tasks(tasks)
|
340
|
-
show(item)
|
332
|
+
update_task(item, :show, lambda do |task|
|
333
|
+
task[:note] ||= []
|
334
|
+
task[:note].push(text)
|
335
|
+
end)
|
341
336
|
end
|
342
337
|
|
343
338
|
def delete_note(item)
|
344
|
-
|
345
|
-
|
346
|
-
|
347
|
-
write_tasks(tasks)
|
348
|
-
show(item)
|
339
|
+
update_task(item, :show, lambda do |task|
|
340
|
+
task.delete(:note)
|
341
|
+
end)
|
349
342
|
end
|
350
343
|
|
351
|
-
def show(item)
|
352
|
-
tasks = load_tasks(item)
|
344
|
+
def show(item, tasks = nil)
|
345
|
+
tasks = tasks || load_tasks(item)
|
353
346
|
tasks[item].each do |key, value|
|
354
347
|
val = value.kind_of?(Array) ? "\n" + value.join("\n") : value
|
355
348
|
puts "#{colorize(key.to_s.rjust(10, ' ') + ':', :cyan)} #{val}"
|
@@ -369,11 +362,33 @@ class Todo
|
|
369
362
|
end
|
370
363
|
end
|
371
364
|
|
365
|
+
def cleanup(patterns)
|
366
|
+
tasks = load_tasks
|
367
|
+
patterns = [':done'] + patterns.to_a
|
368
|
+
items = filter_tasks(tasks, patterns)
|
369
|
+
items.keys.each do |num| tasks.delete(num) end
|
370
|
+
write_tasks(tasks)
|
371
|
+
puts "Deleted #{items.size} todo(s)"
|
372
|
+
end
|
373
|
+
|
374
|
+
def filter_tasks(tasks, patterns)
|
375
|
+
items = {}
|
376
|
+
tasks.each do |num, task|
|
377
|
+
normalized_task = "state=#{task[:state]} due=#{task[:due]} #{task[:title]}"
|
378
|
+
match = true
|
379
|
+
patterns.each do |pattern|
|
380
|
+
match = false unless /#{@queries[pattern] || pattern}/ix.match(normalized_task)
|
381
|
+
end
|
382
|
+
items[num] = task if match
|
383
|
+
end
|
384
|
+
return items
|
385
|
+
end
|
386
|
+
|
372
387
|
def colorize(text, color)
|
373
388
|
"\e[#{COLOR_CODES[color]}m#{text}\e[0m"
|
374
389
|
end
|
375
390
|
|
376
|
-
def convert_due_date(date
|
391
|
+
def convert_due_date(date)
|
377
392
|
due = nil
|
378
393
|
day_index = @due_date_days.index(date.to_s.downcase) ||
|
379
394
|
DUE_DATE_DAYS_SIMPLE.index(date.to_s.downcase) ||
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: todo-jsonl
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.1.
|
4
|
+
version: 0.1.28
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Gabor Bata
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2021-03-
|
11
|
+
date: 2021-03-09 00:00:00.000000000 Z
|
12
12
|
dependencies: []
|
13
13
|
description:
|
14
14
|
email:
|