todo-jsonl 1.0.3 → 1.0.4

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 +15 -19
  3. metadata +2 -2
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 40ddf723c9cd6d6f2bbfd6a2e79d793b2e4a9e566ab03decb98ffa2b26ab7aae
4
- data.tar.gz: f503bf830367cca971c40625adbf5d2ac73f75055c0ec1aa7d5d76676b2a8dce
3
+ metadata.gz: fc4e0e129e6dae5b09b233027e88344b5439b805a732a97c9162ea0cd57159d4
4
+ data.tar.gz: 3d521e8f11ccc2295bc32bc7bfdea49aca23c7b55023b19b8d90a8a0f002229a
5
5
  SHA512:
6
- metadata.gz: e6938c3a54128c70a606db10c737a482bf9192d2f6dfa8f01c66e1805ec3af1f7da1ddba7f99769015e29349c63f153eb409fea3b68db5f68c8629ac99113dff
7
- data.tar.gz: b63dd1f3e0f93b1ef2677040695b75d9b4ed373cda2243a0e08f60a5f4e4f77187f918d97ee4a54ccfb20467d58980c016af67ceec8e07ad69e8ba69dce95fe6
6
+ metadata.gz: 75b546efb040d46254728b62a5d27962d9a96495a1c0295bc334580ac88beeaeb611359e04e881baa846de199684486850f96390b8efff2445e506375eab0bc0
7
+ data.tar.gz: c6115760b9b524d8624ccd8491119b289a5def26910c07b1cf5d295c91ad84e07a3dbb71ae6dc44dfa7fc838a666cac67dd922aa954b1660cb1a93a79611b7ab
data/bin/todo.rb CHANGED
@@ -107,8 +107,8 @@ class Todo
107
107
  raise action + ' command requires at least two parameters' if args.length < 2
108
108
  add_note(args.first.to_i, args[1..-1].join(' '))
109
109
  when 'delnote'
110
- raise action + ' command requires exactly one parameter' if args.length != 1
111
- delete_note(args.first.to_i)
110
+ raise action + ' command requires one or two parameters' if args.length < 1 || args.length > 2
111
+ delete_note(args.first.to_i, args[1])
112
112
  when 'list'
113
113
  list(nil, args)
114
114
  when 'show'
@@ -151,7 +151,7 @@ class Todo
151
151
  * rename <tasknumber> <text> rename task
152
152
  * del <tasknumber> delete task
153
153
  * note <tasknumber> <text> add note to task
154
- * delnote <tasknumber> delete all notes from task
154
+ * delnote <tasknumber> [number] delete a specific or all notes from task
155
155
 
156
156
  * list <regex> [regex...] list tasks (only active tasks by default)
157
157
  * show <tasknumber> show all task details
@@ -212,9 +212,7 @@ class Todo
212
212
 
213
213
  def write_tasks(tasks)
214
214
  File.open(TODO_FILE, 'w:UTF-8') do |file|
215
- tasks.keys.sort.each do |key|
216
- file.write(JSON.generate(tasks[key]) + "\n")
217
- end
215
+ tasks.keys.sort.each { |key| file.write(JSON.generate(tasks[key]) + "\n") }
218
216
  end
219
217
  end
220
218
 
@@ -228,15 +226,9 @@ class Todo
228
226
  end
229
227
 
230
228
  def add(text)
231
- task = {
232
- state: 'new',
233
- title: text,
234
- modified: @today.strftime(DATE_FORMAT)
235
- }
229
+ task = { state: 'new', title: text, modified: @today.strftime(DATE_FORMAT) }
236
230
  postprocess_tags(task)
237
- File.open(TODO_FILE, 'a:UTF-8') do |file|
238
- file.write(JSON.generate(task) + "\n")
239
- end
231
+ File.open(TODO_FILE, 'a:UTF-8') { |file| file.write(JSON.generate(task) + "\n") }
240
232
  list
241
233
  end
242
234
 
@@ -344,17 +336,21 @@ class Todo
344
336
  end)
345
337
  end
346
338
 
347
- def delete_note(item)
339
+ def delete_note(item, num = nil)
348
340
  update_task(item, :show, lambda do |task|
349
- task.delete(:note)
341
+ return task.delete(:note) if num.to_s.empty?
342
+ raise "#{num.to_i}: Note does not exist" if num.to_i <= 0 || task[:note].to_a.size < num.to_i
343
+ task[:note].delete_at(num.to_i - 1)
344
+ task.delete(:note) if task[:note].empty?
350
345
  end)
351
346
  end
352
347
 
353
348
  def show(item, tasks = nil)
354
349
  tasks ||= load_tasks(item)
355
- tasks[item].each do |key, value|
356
- val = value.kind_of?(Array) ? "\n" + value.join("\n") : value
357
- puts "#{colorize(key.to_s.rjust(10, ' ') + ':', :cyan)} #{val}"
350
+ tasks[item].each do |k, v|
351
+ v = "\n" + v.each_with_index.map { |n, i| "#{(i + 1).to_s.rjust(v.size.to_s.size, ' ')}: #{n}" }.
352
+ join("\n") if v.is_a?(Array)
353
+ puts "#{colorize(k.to_s.rjust(10, ' ') + ':', :cyan)} #{v}"
358
354
  end
359
355
  end
360
356
 
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: 1.0.3
4
+ version: 1.0.4
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-22 00:00:00.000000000 Z
11
+ date: 2021-03-24 00:00:00.000000000 Z
12
12
  dependencies: []
13
13
  description:
14
14
  email: