do_stuff 0.2.0 → 0.2.1

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.
@@ -14,7 +14,60 @@ module DoStuff
14
14
 
15
15
  opts = OptionParser.new do |opts|
16
16
  opts.on('-e [TASK NUM]') do |task_num|
17
- Tasklist.edit(todofile)
17
+ begin
18
+ pre_todolist = Tasklist.new(todofile)
19
+ rescue Tasklist::ParseError => e
20
+ pre_error = e
21
+ end
22
+
23
+ run_editor(todofile, task_num)
24
+
25
+ begin
26
+ post_todolist = Tasklist.new(todofile)
27
+ rescue Tasklist::ParseError => e
28
+ post_error = e
29
+ end
30
+
31
+ if post_error
32
+ if pre_error
33
+ if pre_error.message == post_error.message
34
+ puts "Syntax error unchanged by edit.\n#{pre_error.message}"
35
+ else
36
+ puts "Pre-edit syntax error: #{pre_error.message}"
37
+ puts "Post-edit syntax error: #{post_error.message}"
38
+ end
39
+ else
40
+ puts "New syntax error introduced.\n#{post_error.message}"
41
+ end
42
+ abort
43
+ end
44
+
45
+ if pre_error && !post_error
46
+ puts "Syntax error fixed by edit."
47
+ exit
48
+ end
49
+
50
+ # If there were no errors, compare the old todolist with the new
51
+ # one, finding what was added, removed, and changed.
52
+ added_keys = post_todolist.tasks.keys - pre_todolist.tasks.keys
53
+ added_keys.each do |task_num|
54
+ puts "Added ##{task_num}: #{post_todolist[task_num]}"
55
+ end
56
+
57
+ removed_keys = pre_todolist.tasks.keys - post_todolist.tasks.keys
58
+ removed_keys.each do |task_num|
59
+ puts "Erased ##{task_num}: #{pre_todolist[task_num]}"
60
+ end
61
+
62
+ old_keys = pre_todolist.tasks.keys & post_todolist.tasks.keys
63
+ old_keys.each do |task_num|
64
+ if pre_todolist[task_num] != post_todolist[task_num]
65
+ puts "Changed ##{task_num}:"
66
+ puts "\033[31;1m-#{pre_todolist[task_num]}" # red
67
+ puts "\033[32;1m+#{post_todolist[task_num]}" # green
68
+ end
69
+ end
70
+
18
71
  exit
19
72
  end
20
73
 
@@ -43,11 +96,11 @@ module DoStuff
43
96
  begin
44
97
  todolist = Tasklist.new(todofile)
45
98
  rescue Tasklist::ParseError => e
46
- abort "Error parsing #{e.file}: #{e.message}"
99
+ abort e.message
47
100
  end
48
101
 
49
102
  if argv.length == 0
50
- todolist.tasks.each do |num, task|
103
+ todolist.tasks.sort.each do |num, task|
51
104
  puts "#{num}. #{task}"
52
105
  end
53
106
  elsif argv.length == 1 && argv[0] =~ /^\d+$/
@@ -66,6 +119,11 @@ module DoStuff
66
119
  end
67
120
  end
68
121
 
122
+ def self.run_editor(file, task_num)
123
+ # TODO: Use task_num to jump to a line
124
+ system(ENV['EDITOR'], file)
125
+ end
126
+
69
127
  def self.usage
70
128
  program = File.basename($0)
71
129
 
@@ -73,7 +131,7 @@ module DoStuff
73
131
  usage: #{program} list unfinished tasks
74
132
  #{program} <task desc> add a new task
75
133
  #{program} <task num> erase task
76
- #{program} -e[task num] edit task file and jump to given task
134
+ #{program} -e [task num edit task file and jump to given task
77
135
  #{program} -h, --help show this message
78
136
  EOS
79
137
 
@@ -28,15 +28,10 @@ module DoStuff
28
28
 
29
29
  def write!
30
30
  File.open(@file, 'w') do |f|
31
- tasks.each{|num, task| f.puts("#{num}. #{task}") }
31
+ tasks.sort.each{|num, task| f.puts("#{num}. #{task}") }
32
32
  end
33
33
  end
34
34
 
35
- def self.edit(file)
36
- # TODO: Use task_num to jump to a line
37
- system(ENV['EDITOR'], file)
38
- end
39
-
40
35
  class ParseError < ::StandardError
41
36
  attr_accessor :file
42
37
  def initialize(file, msg)
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: do_stuff
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.0
4
+ version: 0.2.1
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2012-02-26 00:00:00.000000000 Z
12
+ date: 2012-02-27 00:00:00.000000000 Z
13
13
  dependencies: []
14
14
  description: A minimalistic command-line todo list
15
15
  email: scott@scott-olson.org