todo-jsonl 0.1.4 → 0.1.9

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.
Files changed (3) hide show
  1. checksums.yaml +4 -4
  2. data/bin/todo.rb +38 -19
  3. metadata +2 -2
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 31bdcebfb49f7f05d6a424395c278500e1fead78ee0147cf227766a0e23d8fff
4
- data.tar.gz: 4d9a84565ccc806e360e9798bedab32054adddd1785dc2be12db0135700fab8e
3
+ metadata.gz: 889bafbe16e82bf4bc1d64a7cc4991a582693677c02a1a6ace65bdd04f20f4b6
4
+ data.tar.gz: 67def741aa050ac753c55af39488712aa3aed696f17c28366020233a59673810
5
5
  SHA512:
6
- metadata.gz: 61aeb4750cc4ac098f7e02455ad290bbc4c7678fa5125f9cb1d628d7f3ac532717de2cf7f0b05c9f1b36a2c4609439b57112052f853d48e381d7f04b9650551c
7
- data.tar.gz: 76b8984917bc16e61124ac416291fa3cfb9fa6bb72f1db725f7b614b4b68030d20417fb724291559295ad7e9fdd65de605ac98a09b7d086b46a64bf55b3addae
6
+ metadata.gz: 5de24eee9c08a01b1abfe1315bbc75444d0d7fa26e0f3c6c99f25911104ec5b3d428e4ae13c23cb3f7d6b931c6b059759b870b65af33ff795786676545813e2c
7
+ data.tar.gz: 4b10d821af4c52d466f621cc77961551556f915f063032b5e7525c8f5d3fff84b838d1564eeabf899c1480e64235654d1ca669922552ddb53bc4be6941033aab
@@ -74,11 +74,8 @@ QUERIES = {
74
74
  }
75
75
 
76
76
  TODAY = DateTime.now
77
-
78
- DUE_DATE_DAYS = ['today', 'tomorrow']
79
- (2..6).each do |day|
80
- DUE_DATE_DAYS.push((TODAY.to_date + day).strftime('%A').downcase)
81
- end
77
+ DUE_DATE_DAYS = (0..6).map do |day| (TODAY.to_date + day).strftime('%A').downcase end
78
+ DUE_DATE_DAYS_SIMPLE = ['today', 'tomorrow']
82
79
 
83
80
  PRIORITY_FLAG = '*'
84
81
 
@@ -93,8 +90,9 @@ def usage
93
90
  * start <tasknumber> mark task as started
94
91
  * done <tasknumber> mark task as completed
95
92
  * block <tasknumber> mark task as blocked
93
+ * reset <tasknumber> reset task to new state
96
94
  * prio <tasknumber> toggle high priority flag
97
- * due <tasknumber> <date> set due date
95
+ * due <tasknumber> <date> set due date (in YYYY-MM-DD format)
98
96
 
99
97
  * append <tasknumber> <text> append text to task title
100
98
  * rename <tasknumber> <text> rename task
@@ -194,7 +192,12 @@ end
194
192
 
195
193
  def due_date(item, date = '')
196
194
  tasks = load_tasks(item)
197
- tasks[item][:due] = date.nil? || date.empty? ? nil : Date.parse(date).strftime(DATE_FORMAT)
195
+ day_index = DUE_DATE_DAYS.index(date.to_s.downcase) || DUE_DATE_DAYS_SIMPLE.index(date.to_s.downcase)
196
+ if day_index
197
+ tasks[item][:due] = (TODAY.to_date + day_index).strftime(DATE_FORMAT)
198
+ else
199
+ tasks[item][:due] = date.nil? || date.empty? ? nil : Date.parse(date).strftime(DATE_FORMAT)
200
+ end
198
201
  tasks[item][:modified] = Time.now.strftime(DATE_FORMAT)
199
202
  write_tasks(tasks)
200
203
  list(tasks)
@@ -203,6 +206,7 @@ end
203
206
  def list(tasks = nil, patterns = nil)
204
207
  items = {}
205
208
  tasks = tasks || load_tasks
209
+ task_indent = [tasks.keys.max.to_s.size, 4].max
206
210
  patterns = patterns.nil? || patterns.empty? ? [QUERIES[':active']] : patterns
207
211
  tasks.each do |num, task|
208
212
  normalized_task = "state=#{task[:state]} #{task[:title]}"
@@ -213,7 +217,7 @@ def list(tasks = nil, patterns = nil)
213
217
  items[num] = task if match
214
218
  end
215
219
  items = items.sort_by do |num, task|
216
- [task[:priority] ? 0 : 1, ORDER[task[:state] || 'default'], num]
220
+ [task[:priority] && task[:state] != 'done' ? 0 : 1, ORDER[task[:state] || 'default'], task[:due] || 'n/a', num]
217
221
  end
218
222
  items.each do |num, task|
219
223
  state = task[:state] || 'default'
@@ -227,13 +231,13 @@ def list(tasks = nil, patterns = nil)
227
231
  if date_diff < 0
228
232
  due_date = colorize("(#{date_diff.abs}d overdue)", :red)
229
233
  elsif date_diff == 0 || date_diff == 1
230
- due_date = colorize("(#{DUE_DATE_DAYS[date_diff]})", :yellow)
234
+ due_date = colorize("(#{DUE_DATE_DAYS_SIMPLE[date_diff]})", :yellow)
231
235
  else
232
236
  due_date = colorize("(#{DUE_DATE_DAYS[date_diff] || task[:due]})", :magenta) if date_diff > 1
233
237
  end
234
238
  due_date = ' ' + due_date
235
239
  end
236
- puts "#{num.to_s.rjust(4, ' ')}:#{priority_flag}#{display_state} #{title}#{due_date}"
240
+ puts "#{num.to_s.rjust(task_indent, ' ')}:#{priority_flag}#{display_state} #{title}#{due_date}"
237
241
  end
238
242
  puts 'No todos found' if items.empty?
239
243
  end
@@ -286,31 +290,46 @@ def read(arguments)
286
290
  args = arguments[1..-1] || []
287
291
  case action
288
292
  when 'add'
289
- add(args.join(' ')) unless args.nil? || args.empty?
293
+ raise action + ' command requires at least one parameter' if args.nil? || args.empty?
294
+ add(args.join(' '))
290
295
  when 'start'
296
+ raise action + ' command can receive only one task number' if args.length > 1
291
297
  args.length == 1 ? change_state(args.first.to_i, 'started') : list(nil, [':started'])
292
298
  when 'done'
299
+ raise action + ' command can receive only one task number' if args.length > 1
293
300
  args.length == 1 ? change_state(args.first.to_i, 'done') : list(nil, [':done'])
294
301
  when 'block'
302
+ raise action + ' command can receive only one task number' if args.length > 1
295
303
  args.length == 1 ? change_state(args.first.to_i, 'blocked') : list(nil, [':blocked'])
304
+ when 'reset'
305
+ raise action + ' command can receive only one task number' if args.length > 1
306
+ args.length == 1 ? change_state(args.first.to_i, 'new') : list(nil, [':new'])
296
307
  when 'prio'
297
- set_priority(args.first.to_i) if args.length == 1
308
+ raise action + ' command requires exactly one parameter' if args.length != 1
309
+ set_priority(args.first.to_i)
298
310
  when 'due'
299
- due_date(args.first.to_i, (args[1..-1] || []).join(' ')) unless args.length < 1
311
+ raise action + ' command requires at least one parameter' if args.length < 1
312
+ due_date(args.first.to_i, (args[1..-1] || []).join(' '))
300
313
  when 'append'
301
- append(args.first.to_i, args[1..-1].join(' ')) unless args.length < 2
314
+ raise action + ' command requires at least two parameters' if args.length < 2
315
+ append(args.first.to_i, args[1..-1].join(' '))
302
316
  when 'rename'
303
- rename(args.first.to_i, args[1..-1].join(' ')) unless args.length < 2
317
+ raise action + ' command requires at least two parameters' if args.length < 2
318
+ rename(args.first.to_i, args[1..-1].join(' '))
304
319
  when 'del'
305
- delete(args.first.to_i) if args.length == 1
320
+ raise action + ' command requires exactly one parameter' if args.length != 1
321
+ delete(args.first.to_i)
306
322
  when 'note'
307
- add_note(args.first.to_i, args[1..-1].join(' ')) unless args.length < 2
323
+ raise action + ' command requires at least two parameters' if args.length < 2
324
+ add_note(args.first.to_i, args[1..-1].join(' '))
308
325
  when 'delnote'
309
- delete_note(args.first.to_i) if args.length == 1
326
+ raise action + ' command requires exactly one parameter' if args.length != 1
327
+ delete_note(args.first.to_i)
310
328
  when 'list'
311
329
  list(nil, args)
312
330
  when 'show'
313
- show(args.first.to_i) if args.length == 1
331
+ raise action + ' command requires exactly one parameter' if args.length != 1
332
+ show(args.first.to_i)
314
333
  when 'help'
315
334
  puts usage
316
335
  when 'repl'
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
4
+ version: 0.1.9
5
5
  platform: ruby
6
6
  authors:
7
7
  - Gabor Bata
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2020-10-02 00:00:00.000000000 Z
11
+ date: 2020-10-05 00:00:00.000000000 Z
12
12
  dependencies: []
13
13
  description:
14
14
  email: