todo-jsonl 0.1.19 → 0.1.25
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 +80 -68
- 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: d47bb16f60f84f6c3e55951169bdb0871f915b7a6948844897fa8a150df05456
|
4
|
+
data.tar.gz: '09600be32199c25bc946036ee947290c7c77472d00933fee39c67d9bd2dc0649'
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 3ae62a56b667ebcb55e661d1ac64cd4c2b62db7d7d4f106c79a034ca58264d4d7c3ea20a4d262e4386806baa88d472c88dcc5a6946c4d3ca8eb01bbc3d99363e
|
7
|
+
data.tar.gz: ede2f1f9f155ce5ff5acacdd784b030c01e11f14a4ef6d85e5223663dc3a0dea5a2ab8a3eac95f498808747fa9588723d1feef36828e4657ee23cd41736aa4e0
|
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:
|
@@ -165,8 +171,8 @@ class Todo
|
|
165
171
|
end
|
166
172
|
|
167
173
|
def setup
|
168
|
-
@today =
|
169
|
-
next_7_days = (0..6).map do |day|
|
174
|
+
@today = Date.today
|
175
|
+
next_7_days = (0..6).map do |day| @today + day end
|
170
176
|
@due_date_days = next_7_days.map do |day| day.strftime('%A').downcase end
|
171
177
|
due_dates_for_queries = next_7_days.map do |day| day.strftime(DATE_FORMAT) end
|
172
178
|
|
@@ -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,78 +235,68 @@ 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
|
+
send(post_action, tasks) if post_action
|
244
|
+
end
|
245
|
+
|
246
|
+
def append(item, text = '')
|
247
|
+
update_task item, :list, lambda { |task|
|
248
|
+
task[:title] = [task[:title], text].join(' ')
|
249
|
+
postprocess_tags(task)
|
250
|
+
}
|
241
251
|
end
|
242
252
|
|
243
253
|
def rename(item, text)
|
244
|
-
|
245
|
-
|
246
|
-
|
247
|
-
|
248
|
-
write_tasks(tasks)
|
249
|
-
list(tasks)
|
254
|
+
update_task item, :list, lambda { |task|
|
255
|
+
task[:title] = text
|
256
|
+
postprocess_tags(task)
|
257
|
+
}
|
250
258
|
end
|
251
259
|
|
252
260
|
def delete(item)
|
253
261
|
tasks = load_tasks(item)
|
254
262
|
tasks.delete(item)
|
255
263
|
write_tasks(tasks)
|
256
|
-
list
|
264
|
+
list(tasks)
|
257
265
|
end
|
258
266
|
|
259
267
|
def change_state(item, state, note = nil)
|
260
|
-
|
261
|
-
|
262
|
-
|
263
|
-
|
264
|
-
|
265
|
-
|
266
|
-
|
267
|
-
write_tasks(tasks)
|
268
|
-
list(tasks)
|
268
|
+
update_task item, :list, lambda { |task|
|
269
|
+
task[:state] = state
|
270
|
+
if !note.nil? && !note.empty?
|
271
|
+
task[:note] ||= []
|
272
|
+
task[:note].push(note)
|
273
|
+
end
|
274
|
+
}
|
269
275
|
end
|
270
276
|
|
271
277
|
def set_priority(item, note = nil)
|
272
|
-
|
273
|
-
|
274
|
-
|
275
|
-
|
276
|
-
|
277
|
-
|
278
|
-
|
279
|
-
|
280
|
-
write_tasks(tasks)
|
281
|
-
list(tasks)
|
278
|
+
update_task item, :list, lambda { |task|
|
279
|
+
task[:priority] = !task[:priority]
|
280
|
+
task.delete(:priority) if !task[:priority]
|
281
|
+
if !note.nil? && !note.empty?
|
282
|
+
task[:note] ||= []
|
283
|
+
task[:note].push(note)
|
284
|
+
end
|
285
|
+
}
|
282
286
|
end
|
283
287
|
|
284
288
|
def due_date(item, date = '')
|
285
|
-
|
286
|
-
|
287
|
-
|
288
|
-
|
289
|
-
write_tasks(tasks)
|
290
|
-
list(tasks)
|
289
|
+
update_task item, :list, lambda { |task|
|
290
|
+
task[:due] = convert_due_date(date)
|
291
|
+
task.delete(:due) if task[:due].nil?
|
292
|
+
}
|
291
293
|
end
|
292
294
|
|
293
295
|
def list(tasks = nil, patterns = nil)
|
294
|
-
items = {}
|
295
296
|
tasks = tasks || load_tasks
|
296
297
|
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
|
298
|
+
patterns = patterns.nil? || patterns.empty? ? [':active'] : patterns
|
299
|
+
items = filter_tasks(tasks, patterns)
|
306
300
|
items = items.sort_by do |num, task|
|
307
301
|
[task[:priority] && task[:state] != 'done' ? 0 : 1, ORDER[task[:state] || 'default'], task[:due] || 'n/a', num]
|
308
302
|
end
|
@@ -316,7 +310,7 @@ class Todo
|
|
316
310
|
priority_flag = task[:priority] ? colorize(PRIORITY_FLAG, :red) : ' '
|
317
311
|
due_date = ''
|
318
312
|
if task[:due] && state != 'done'
|
319
|
-
date_diff = (Date.
|
313
|
+
date_diff = (Date.strptime(task[:due], DATE_FORMAT) - @today).to_i
|
320
314
|
if date_diff < 0
|
321
315
|
due_date = colorize("(#{date_diff.abs}d overdue)", :red)
|
322
316
|
elsif date_diff == 0 || date_diff == 1
|
@@ -332,24 +326,20 @@ class Todo
|
|
332
326
|
end
|
333
327
|
|
334
328
|
def add_note(item, text)
|
335
|
-
|
336
|
-
|
337
|
-
|
338
|
-
|
339
|
-
write_tasks(tasks)
|
340
|
-
show(item)
|
329
|
+
update_task item, :show, lambda { |task|
|
330
|
+
task[:note] ||= []
|
331
|
+
task[:note].push(text)
|
332
|
+
}
|
341
333
|
end
|
342
334
|
|
343
335
|
def delete_note(item)
|
344
|
-
|
345
|
-
|
346
|
-
|
347
|
-
write_tasks(tasks)
|
348
|
-
show(item)
|
336
|
+
update_task item, :show, lambda { |task|
|
337
|
+
task.delete(:note)
|
338
|
+
}
|
349
339
|
end
|
350
340
|
|
351
|
-
def show(item)
|
352
|
-
tasks = load_tasks(item)
|
341
|
+
def show(item, tasks = nil)
|
342
|
+
tasks = tasks || load_tasks(item)
|
353
343
|
tasks[item].each do |key, value|
|
354
344
|
val = value.kind_of?(Array) ? "\n" + value.join("\n") : value
|
355
345
|
puts "#{colorize(key.to_s.rjust(10, ' ') + ':', :cyan)} #{val}"
|
@@ -369,19 +359,41 @@ class Todo
|
|
369
359
|
end
|
370
360
|
end
|
371
361
|
|
362
|
+
def cleanup(patterns)
|
363
|
+
tasks = load_tasks
|
364
|
+
patterns = [':done'] + patterns.to_a
|
365
|
+
items = filter_tasks(tasks, patterns)
|
366
|
+
items.keys.each do |num| tasks.delete(num) end
|
367
|
+
write_tasks(tasks)
|
368
|
+
puts "Deleted #{items.size} todo(s)"
|
369
|
+
end
|
370
|
+
|
371
|
+
def filter_tasks(tasks, patterns)
|
372
|
+
items = {}
|
373
|
+
tasks.each do |num, task|
|
374
|
+
normalized_task = "state=#{task[:state]} due=#{task[:due]} #{task[:title]}"
|
375
|
+
match = true
|
376
|
+
patterns.each do |pattern|
|
377
|
+
match = false unless /#{@queries[pattern] || pattern}/ix.match(normalized_task)
|
378
|
+
end
|
379
|
+
items[num] = task if match
|
380
|
+
end
|
381
|
+
return items
|
382
|
+
end
|
383
|
+
|
372
384
|
def colorize(text, color)
|
373
385
|
"\e[#{COLOR_CODES[color]}m#{text}\e[0m"
|
374
386
|
end
|
375
387
|
|
376
|
-
def convert_due_date(date
|
388
|
+
def convert_due_date(date)
|
377
389
|
due = nil
|
378
390
|
day_index = @due_date_days.index(date.to_s.downcase) ||
|
379
391
|
DUE_DATE_DAYS_SIMPLE.index(date.to_s.downcase) ||
|
380
392
|
@due_date_days.map do |day| day[0..2] end.index(date.to_s.downcase)
|
381
393
|
if day_index
|
382
|
-
due = (@today
|
394
|
+
due = (@today + day_index).strftime(DATE_FORMAT)
|
383
395
|
else
|
384
|
-
due = date.nil? || date.empty? ? nil : Date.
|
396
|
+
due = date.nil? || date.empty? ? nil : Date.strptime(date, DATE_FORMAT).strftime(DATE_FORMAT)
|
385
397
|
end
|
386
398
|
return due
|
387
399
|
end
|
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.25
|
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-08 00:00:00.000000000 Z
|
12
12
|
dependencies: []
|
13
13
|
description:
|
14
14
|
email:
|