do_stuff 0.2.4 → 0.3.0

Sign up to get free protection for your applications and to get access to all the features.
@@ -12,6 +12,9 @@ module DoStuff
12
12
  abort "Error: Couldn't find #{dostuffrc}.\nPlease create it and put " +
13
13
  "the path to your todo.txt file in it." unless File.exists?(dostuffrc)
14
14
 
15
+ # This will be set by options if we are to change the text of a task.
16
+ edit_target = nil
17
+
15
18
  taskfile = File.expand_path(File.read(dostuffrc).chomp)
16
19
  unless File.exists?(taskfile)
17
20
  FileUtils.mkdir_p(File.dirname(taskfile))
@@ -20,8 +23,12 @@ module DoStuff
20
23
 
21
24
  opts = OptionParser.new do |opts|
22
25
  opts.on('-e [TASK NUM]') do |task_num|
23
- edit(taskfile, task_num)
24
- exit
26
+ if argv.empty?
27
+ edit(taskfile, task_num)
28
+ exit
29
+ else
30
+ edit_target = task_num
31
+ end
25
32
  end
26
33
 
27
34
  opts.on('--standalone FILE') do |file|
@@ -52,6 +59,22 @@ module DoStuff
52
59
  abort e.message
53
60
  end
54
61
 
62
+ if edit_target
63
+ before_text = tasklist[edit_target]
64
+ tasklist[edit_target] = argv.join(' ')
65
+ tasklist.write!
66
+
67
+ if !before_text
68
+ puts "Added ##{edit_target}: #{tasklist[edit_target]}"
69
+ else
70
+ puts "Changed ##{edit_target}:"
71
+ puts "#{RED}-#{before_text}#{RESET}"
72
+ puts "#{GREEN}+#{tasklist[edit_target]}#{RESET}"
73
+ end
74
+
75
+ exit
76
+ end
77
+
55
78
  if argv.length == 0
56
79
  tasklist.tasks.sort.each do |num, task|
57
80
  puts "#{num}. #{task}"
@@ -145,16 +168,17 @@ module DoStuff
145
168
  program = File.basename($0)
146
169
 
147
170
  print <<-EOS
148
- usage: #{program} list unfinished tasks
149
- #{program} <task desc> add a new task
150
- #{program} <task num> erase task
151
- #{program} -e [task num] edit task file and jump to given task
152
- #{program} -h, --help show this message
171
+ usage: #{program} list unfinished tasks
172
+ #{program} <task desc> add a new task
173
+ #{program} <task num> erase task
174
+ #{program} -e [task num] edit task file [and jump to given task]
175
+ #{program} -e<task num> <text> replace task with given text
176
+ #{program} -h, --help show this message
153
177
  EOS
154
178
 
155
179
  if defined?(::DoStuff::Standalone)
156
180
  print <<-EOS
157
- #{program} --standalone FILE generate a standalone version of do_stuff
181
+ #{program} --standalone FILE generate a standalone version of do_stuff
158
182
  EOS
159
183
  end
160
184
  end
@@ -19,11 +19,15 @@ module DoStuff
19
19
  end
20
20
 
21
21
  def [](task_num)
22
- @tasks[task_num]
22
+ @tasks[task_num.to_i]
23
+ end
24
+
25
+ def []=(task_num, task)
26
+ @tasks[task_num.to_i] = task
23
27
  end
24
28
 
25
29
  def delete(task_num)
26
- @tasks.delete(task_num)
30
+ @tasks.delete(task_num.to_i)
27
31
  end
28
32
 
29
33
  def write!
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.4
4
+ version: 0.3.0
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-03-03 00:00:00.000000000 Z
12
+ date: 2012-03-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