to-do 1.3.0 → 1.3.1
Sign up to get free protection for your applications and to get access to all the features.
- data/README.md +10 -1
- data/Rakefile +2 -9
- data/VERSION +1 -1
- data/lib/to-do.rb +10 -10
- data/lib/to-do/cli.rb +59 -266
- data/lib/to-do/config.rb +4 -4
- data/lib/to-do/helpers/helpers.rb +22 -0
- data/lib/to-do/helpers/helpers_CLI.rb +301 -0
- data/lib/to-do/helpers/helpers_tasks.rb +34 -0
- data/lib/to-do/tasks.rb +17 -55
- data/to-do.gemspec +5 -2
- metadata +22 -19
data/README.md
CHANGED
@@ -1,7 +1,12 @@
|
|
1
|
-
#to-do 1.3 [![Build Status](https://secure.travis-ci.org/kristenmills/to-do.png?branch=master)](http://travis-ci.org/kristenmills/to-do)
|
1
|
+
#to-do 1.3.1 [![Build Status](https://secure.travis-ci.org/kristenmills/to-do.png?branch=master)](http://travis-ci.org/kristenmills/to-do) [![Dependency Status](https://gemnasium.com/kristenmills/to-do.png)](https://gemnasium.com/kristenmills/to-do) [![Code Climate](https://codeclimate.com/badge.png)](https://codeclimate.com/github/kristenmills/to-do)
|
2
2
|
|
3
3
|
A simple command line todo application written in Ruby.
|
4
4
|
|
5
|
+
## What's new in 1.3.1
|
6
|
+
* Bug Fixes
|
7
|
+
* Text color adjustments for dark and light color schemes
|
8
|
+
* Add a default list automatically as opposed to the message that tells you to create a default list
|
9
|
+
|
5
10
|
##What's new in 1.3
|
6
11
|
* Priorities
|
7
12
|
* Sorting
|
@@ -102,6 +107,10 @@ This is just basic usage. For more information, view
|
|
102
107
|
* Tab Completion
|
103
108
|
* Reorganizing
|
104
109
|
|
110
|
+
##Similar Projects
|
111
|
+
* [timetrap](https://github.com/samg/timetrap) is hip. You should probably check it out.
|
112
|
+
* [tracking](https://github.com/thenickperson/tracking) is also pretty hip. You should probably check it out.
|
113
|
+
|
105
114
|
##Contributing to to-do
|
106
115
|
|
107
116
|
* Check out the latest master to make sure the feature hasn't been implemented or the bug hasn't been fixed yet.
|
data/Rakefile
CHANGED
@@ -41,12 +41,5 @@ end
|
|
41
41
|
|
42
42
|
task :default => :test
|
43
43
|
|
44
|
-
require '
|
45
|
-
Rake::
|
46
|
-
version = File.exist?('VERSION') ? File.read('VERSION') : ""
|
47
|
-
|
48
|
-
rdoc.rdoc_dir = 'rdoc'
|
49
|
-
rdoc.title = "to-do #{version}"
|
50
|
-
rdoc.rdoc_files.include('README*')
|
51
|
-
rdoc.rdoc_files.include('lib/**/*.rb')
|
52
|
-
end
|
44
|
+
require 'yard'
|
45
|
+
YARD::Rake::YardocTask.new
|
data/VERSION
CHANGED
@@ -1 +1 @@
|
|
1
|
-
1.3.
|
1
|
+
1.3.1
|
data/lib/to-do.rb
CHANGED
@@ -14,6 +14,13 @@ Sequel::Migrator.apply(database, File.join(File.dirname(__FILE__),'to-do', 'dbmi
|
|
14
14
|
|
15
15
|
# If a lists file exists from back when we were using YAML populate the database with that information
|
16
16
|
if File.exists?(File.join(ENV['HOME'], '.to-do', 'lists')) && database[:Lists].empty?
|
17
|
+
add_tasks = Proc.new { |list_object, list_id, completed|
|
18
|
+
list_object.completed_tasks.each do |num, task|
|
19
|
+
database[:Tasks].insert(:Task_number => num.to_s, :Name => task, :Completed => completed)
|
20
|
+
task_id = database[:Tasks].count
|
21
|
+
database[:Task_list].insert(:Task_id => task_id, :List_id => list_id)
|
22
|
+
end
|
23
|
+
}
|
17
24
|
Dir.chdir(File.join(ENV['HOME'], '.to-do', 'lists')) do
|
18
25
|
lists = Dir.entries "."
|
19
26
|
lists.each do |file|
|
@@ -21,20 +28,13 @@ if File.exists?(File.join(ENV['HOME'], '.to-do', 'lists')) && database[:Lists].e
|
|
21
28
|
list_object = YAML.load_file(file)
|
22
29
|
database[:Lists].insert(:Name => list_object.name, :Total => list_object.count)
|
23
30
|
list_id = database[:Lists].count
|
24
|
-
|
25
|
-
|
26
|
-
task_id = database[:Tasks].count
|
27
|
-
database[:Task_list].insert(:Task_id => task_id, :List_id => list_id)
|
28
|
-
end
|
29
|
-
list_object.completed_tasks.each do |num, task|
|
30
|
-
database[:Tasks].insert(:Task_number => num.to_s, :Name => task, :Completed => 1)
|
31
|
-
task_id = database[:Tasks].count
|
32
|
-
database[:Task_list].insert(:Task_id => task_id, :List_id => list_id)
|
33
|
-
end
|
31
|
+
add_tasks.call list_object, list_id, 0
|
32
|
+
add_tasks.call list_object, list_id, 1
|
34
33
|
end
|
35
34
|
end
|
36
35
|
end
|
37
36
|
|
37
|
+
require File.join(File.dirname(__FILE__), 'to-do', 'helpers', 'helpers')
|
38
38
|
require File.join(File.dirname(__FILE__), 'to-do', 'tasks')
|
39
39
|
require File.join(File.dirname(__FILE__), 'to-do', 'cli')
|
40
40
|
|
data/lib/to-do/cli.rb
CHANGED
@@ -8,31 +8,6 @@ module Todo
|
|
8
8
|
module CLI
|
9
9
|
extend self
|
10
10
|
|
11
|
-
# The database
|
12
|
-
DATABASE = Sequel.sqlite Todo::Config[:task_database]
|
13
|
-
|
14
|
-
# The option flags
|
15
|
-
OPTIONS = {
|
16
|
-
:is_num => false,
|
17
|
-
:clear_all => false,
|
18
|
-
:change_priority => false,
|
19
|
-
:priority => 1,
|
20
|
-
:sort => "n"
|
21
|
-
}
|
22
|
-
|
23
|
-
# Usage messages for each of the commnands
|
24
|
-
USAGE = {
|
25
|
-
:default => "todo [COMMAND] [option] [arguments]",
|
26
|
-
:create => "todo create|switch <LIST NAME>",
|
27
|
-
:display => "todo [display|d] [-s {p,n}]",
|
28
|
-
:add => "todo add|a [-p {high, medium, low}] <TASK>",
|
29
|
-
:finish => "todo finish|f [-n <TASK_NUMBER>] [<TASK>]",
|
30
|
-
:undo => "todo undo|u [-n <TASK_NUMBER>] [<TASK>]",
|
31
|
-
:clear => "todo clear [-a]",
|
32
|
-
:remove => "todo remove|rm <LIST NAME>",
|
33
|
-
:set => "todo set|s [-p {high, medium, low}] [-n <TASK_NUMBER>] [<TASK>]"
|
34
|
-
}
|
35
|
-
|
36
11
|
# Displays the list in a human readable form:
|
37
12
|
#
|
38
13
|
# @example
|
@@ -48,248 +23,101 @@ module Todo
|
|
48
23
|
# 3. Task 3
|
49
24
|
# 4. Task 4
|
50
25
|
def display
|
51
|
-
|
52
|
-
|
53
|
-
|
54
|
-
tasks = OPTIONS[:sort] == "n" ? tasks.order(:Task_number) : tasks.order(:Priority, :Task_number)
|
55
|
-
list = DATABASE[:Lists][:Name=>Config[:working_list_name]]
|
26
|
+
|
27
|
+
colors = Helpers::CLI.create_color_hash
|
28
|
+
tasks = Helpers.task_names
|
29
|
+
tasks = Helpers::CLI::OPTIONS[:sort] == "n" ? tasks.order(:Task_number) : tasks.order(:Priority, :Task_number)
|
30
|
+
list = Helpers::DATABASE[:Lists][:Name=>Config[:working_list_name]]
|
56
31
|
count = list.nil? ? 0 : list[:Total]
|
57
32
|
completed_count = tasks.filter(:Completed=>1).count
|
58
33
|
|
59
|
-
priority = {
|
60
|
-
0 => "**",
|
61
|
-
1 => "*",
|
62
|
-
2 => ""
|
63
|
-
}
|
64
34
|
#print out the header
|
65
|
-
|
66
|
-
|
67
|
-
end
|
68
|
-
puts
|
69
|
-
split_name = split Config[:working_list_name], Config[:width]
|
70
|
-
split_name.each do |line|
|
71
|
-
puts line.center(Config[:width]).colorize(:light_cyan)
|
72
|
-
end
|
73
|
-
Config[:width].times do
|
74
|
-
print "*".colorize(:light_red)
|
75
|
-
end
|
35
|
+
Helpers::CLI.print_header colors
|
36
|
+
|
76
37
|
puts
|
77
38
|
puts
|
78
39
|
|
79
40
|
#prints out incomplete tasks
|
80
|
-
puts "Todo:".colorize(:
|
81
|
-
|
82
|
-
next if task[:Completed] == 1
|
83
|
-
printf "%2s".colorize(:light_magenta), priority[task[:Priority]]
|
84
|
-
printf "%3d. ".colorize(:light_yellow), task[:Task_number]
|
85
|
-
split_v = split task[:Name], Config[:width] - 7
|
86
|
-
puts split_v[0]
|
87
|
-
split_v.shift
|
88
|
-
split_v.each do |line|
|
89
|
-
printf " %s\n", line
|
90
|
-
end
|
91
|
-
end
|
41
|
+
puts "Todo:".colorize(colors[:green])
|
42
|
+
Helpers::CLI.print_tasks 1, tasks, colors
|
92
43
|
|
93
44
|
#Prints out complete tasks
|
94
|
-
print "\nCompleted:".colorize(:
|
95
|
-
printf "%#{Config[:width]+4}s\n", "#{completed_count}/#{count}".colorize(:
|
96
|
-
|
97
|
-
next if task[:Completed] == 0
|
98
|
-
printf "%2s".colorize(:light_magenta), priority[task[:Priority]]
|
99
|
-
printf "%3d. ".to_s.colorize(:light_yellow), task[:Task_number]
|
100
|
-
split_v = split task[:Name], Config[:width]-7
|
101
|
-
puts split_v[0]
|
102
|
-
split_v.shift
|
103
|
-
split_v.each do |line|
|
104
|
-
printf " %s\n", line
|
105
|
-
end
|
106
|
-
end
|
45
|
+
print "\nCompleted:".colorize(colors[:green])
|
46
|
+
printf "%#{Config[:width]+4}s\n", "#{completed_count}/#{count}".colorize(colors[:cyan])
|
47
|
+
Helpers::CLI.print_tasks 0, tasks, colors
|
107
48
|
puts
|
108
49
|
end
|
109
50
|
|
110
51
|
# Helper method for parsing the options using OptionParser
|
111
52
|
def option_parser
|
53
|
+
colors = Helpers::CLI.create_color_hash
|
112
54
|
OptionParser.new do |opts|
|
113
|
-
|
114
|
-
|
115
|
-
|
116
|
-
|
117
|
-
|
118
|
-
|
119
|
-
|
120
|
-
|
121
|
-
|
122
|
-
opts
|
123
|
-
|
124
|
-
|
125
|
-
|
126
|
-
opts.separator " *".colorize(:light_cyan) + " display, d".colorize(:light_yellow) + " displays the current list".colorize(:light_magenta)
|
127
|
-
opts.separator " usage: ".colorize(:light_cyan) + USAGE[:display].colorize(:light_red)
|
128
|
-
opts.on('-s TYPE', [:p, :n], "sorts the task by ") do |s|
|
129
|
-
OPTIONS[:sort] = s
|
130
|
-
end
|
131
|
-
|
132
|
-
#todo add, a
|
133
|
-
opts.separator ""
|
134
|
-
opts.separator " *".colorize(:light_cyan) + " add, a".colorize(:light_yellow) + " adds the task to the current list".colorize(:light_magenta)
|
135
|
-
opts.separator " usage: ".colorize(:light_cyan) + USAGE[:add].colorize(:light_red)
|
136
|
-
opts.on('-p PRIORITY', ["high", "medium", "low"], 'set the priority of the task to one of the following.\n' +
|
137
|
-
' Default is medium') do |p|
|
138
|
-
priorities = {
|
139
|
-
"high" => 0,
|
140
|
-
"medium" => 1,
|
141
|
-
"low" => 2
|
142
|
-
}
|
143
|
-
OPTIONS[:change_priority] = true
|
144
|
-
OPTIONS[:priority] = priorities[p]
|
145
|
-
end
|
146
|
-
|
147
|
-
#todo finish, f
|
148
|
-
opts.separator ""
|
149
|
-
opts.separator " *".colorize(:light_cyan) + " finish , f".colorize(:light_yellow) + " marks a task as finished".colorize(:light_magenta)
|
150
|
-
opts.separator " usage: ".colorize(:light_cyan) + USAGE[:finish].colorize(:light_red)
|
151
|
-
opts.on('-n', 'references a task by its number') do |n|
|
152
|
-
OPTIONS[:is_num] = true
|
153
|
-
end
|
154
|
-
|
155
|
-
#todo undo, u
|
156
|
-
opts.separator ""
|
157
|
-
opts.separator " *".colorize(:light_cyan) + " undo, u".colorize(:light_yellow) + " undos a completed task".colorize(:light_magenta)
|
158
|
-
opts.separator " usage: ".colorize(:light_cyan) + USAGE[:undo].colorize(:light_red)
|
159
|
-
opts.separator " -n references a task by its number"
|
55
|
+
Helpers::CLI.options_title opts, colors
|
56
|
+
Helpers::CLI.options_create opts, colors
|
57
|
+
Helpers::CLI.options_display opts, colors
|
58
|
+
Helpers::CLI.options_add opts, colors
|
59
|
+
Helpers::CLI.options_finish opts, colors
|
60
|
+
Helpers::CLI.options_undo opts, colors
|
61
|
+
Helpers::CLI.options_clear opts, colors
|
62
|
+
Helpers::CLI.options_remove opts, colors
|
63
|
+
Helpers::CLI.options_set opts, colors
|
64
|
+
Helpers::CLI.options_config opts, colors
|
65
|
+
Helpers::CLI.options_other opts, colors
|
66
|
+
end
|
67
|
+
end
|
160
68
|
|
161
|
-
|
162
|
-
|
163
|
-
|
164
|
-
|
165
|
-
|
166
|
-
OPTIONS[:clear_all]
|
69
|
+
# Helper method for parsing commands.
|
70
|
+
def commands_parser
|
71
|
+
if ARGV.count > 0
|
72
|
+
should_display = command_switch
|
73
|
+
if ARGV[0] == "clear"
|
74
|
+
Tasks.clear Helpers::CLI::OPTIONS[:clear_all]
|
75
|
+
should_display = true
|
167
76
|
end
|
168
77
|
|
169
|
-
|
170
|
-
|
171
|
-
|
172
|
-
|
173
|
-
|
174
|
-
|
175
|
-
|
176
|
-
opts.separator " *".colorize(:light_cyan) + " set, s".colorize(:light_yellow) + " adds additional information to a task".colorize(:light_magenta)
|
177
|
-
opts.separator " usage: ".colorize(:light_cyan) + USAGE[:set].colorize(:light_red)
|
178
|
-
opts.separator " -p TYPE set the priority of the task to one of the following.\n" +
|
179
|
-
" Default is medium"
|
180
|
-
opts.separator " -n references a task by its number"
|
181
|
-
|
182
|
-
opts.separator ""
|
183
|
-
opts.separator "Other Options: ".colorize(:light_green)
|
184
|
-
|
185
|
-
#todo -h
|
186
|
-
opts.on('-h', '--help', 'displays this screen' ) do
|
187
|
-
puts opts
|
188
|
-
exit
|
189
|
-
end
|
190
|
-
#todo -w
|
191
|
-
opts.on('-w', "displays the name of the current list") do
|
192
|
-
if Config[:working_list_exists]
|
193
|
-
puts "Working list is #{Config[:working_list_name]}"
|
194
|
-
else
|
195
|
-
puts "Working List does not exist yet. Please create one"
|
196
|
-
puts "todo create <list name>"
|
197
|
-
end
|
198
|
-
exit
|
78
|
+
if ARGV[0] == "display" || ARGV[0] == "d" || should_display
|
79
|
+
puts
|
80
|
+
display
|
81
|
+
elsif Helpers::CLI::USAGE[ARGV[0].to_sym].nil? && ARGV.count == 1
|
82
|
+
puts "Invalid command. See todo -h for help."
|
83
|
+
elsif ARGV.count == 1
|
84
|
+
puts "Usage: #{Helpers::CLI::USAGE[ARGV[0].to_sym]}"
|
199
85
|
end
|
200
86
|
|
87
|
+
else
|
88
|
+
display
|
201
89
|
end
|
202
90
|
end
|
203
91
|
|
204
|
-
# Helper method for parsing
|
205
|
-
def
|
206
|
-
if ARGV.count >
|
92
|
+
# Helper method for parsing commmands.
|
93
|
+
def command_switch
|
94
|
+
if ARGV.count > 1
|
95
|
+
should_display = true
|
207
96
|
case ARGV[0]
|
208
|
-
when "display", "d"
|
209
|
-
if Config[:working_list_exists]
|
210
|
-
display
|
211
|
-
else
|
212
|
-
puts "Working List does not exist yet. Please create one"
|
213
|
-
puts "Usage: #{USAGE[:create]}"
|
214
|
-
end
|
215
97
|
when "create", "switch"
|
216
|
-
if ARGV.count > 0
|
217
98
|
name = ARGV[1..-1].map{|word| word.capitalize}.join(' ')
|
218
99
|
Config[:working_list_name] = name
|
219
100
|
Config[:working_list_exists] = true
|
220
101
|
puts "Switch to #{name}"
|
221
|
-
puts
|
222
|
-
display
|
223
|
-
else
|
224
|
-
puts "Usage: #{USAGE[:create]}"
|
225
|
-
end
|
226
102
|
when "add", "a"
|
227
|
-
|
228
|
-
ARGV.count > 1 ? Tasks.add(ARGV[1..-1].join(' '), OPTIONS[:priority]) : puts("Usage: #{USAGE[:add]}")
|
229
|
-
puts
|
230
|
-
display
|
231
|
-
else
|
232
|
-
puts "Working List does not exist yet. Please create one"
|
233
|
-
puts "Usage: #{USAGE[:create]}"
|
234
|
-
end
|
103
|
+
Tasks.add(ARGV[1..-1].join(' '), Helpers::CLI::OPTIONS[:priority])
|
235
104
|
when "finish", "f"
|
236
|
-
|
237
|
-
ARGV.count > 1 ? Tasks.finish(ARGV[1..-1].join(' '), OPTIONS[:is_num]) : puts("Usage: #{USAGE[:finish]}")
|
238
|
-
puts
|
239
|
-
display
|
240
|
-
else
|
241
|
-
puts "Working List does not exist yet. Please create one"
|
242
|
-
puts "Usage: #{USAGE[:create]}"
|
243
|
-
end
|
105
|
+
Tasks.finish(ARGV[1..-1].join(' '), Helpers::CLI::OPTIONS[:is_num])
|
244
106
|
when "undo", "u"
|
245
|
-
|
246
|
-
ARGV.count > 1 ? Tasks.undo(ARGV[1..-1].join(' '), OPTIONS[:is_num]) : puts("Usage: #{USAGE[:undo]}")
|
247
|
-
puts
|
248
|
-
display
|
249
|
-
else
|
250
|
-
puts "Working List does not exist yet. Please create one"
|
251
|
-
puts "Usage: #{USAGE[:create]}"
|
252
|
-
end
|
253
|
-
when "clear"
|
254
|
-
if Config[:working_list_exists]
|
255
|
-
Tasks.clear OPTIONS[:clear_all]
|
256
|
-
puts
|
257
|
-
display
|
258
|
-
else
|
259
|
-
puts "Working List does not exist yet. Please create one"
|
260
|
-
puts "Usage: #{USAGE[:create]}"
|
261
|
-
end
|
107
|
+
Tasks.undo(ARGV[1..-1].join(' '), Helpers::CLI::OPTIONS[:is_num])
|
262
108
|
when "remove", "r"
|
263
|
-
|
264
|
-
|
265
|
-
else
|
266
|
-
puts "Usage: #{USAGE[:remove]}"
|
267
|
-
end
|
109
|
+
Tasks.clear true, ARGV[1..-1].map{|word| word.capitalize}.join(' ')
|
110
|
+
should_display = false
|
268
111
|
when "set", "s"
|
269
|
-
if
|
270
|
-
|
271
|
-
|
272
|
-
Tasks.set_priority OPTIONS[:priority], ARGV[1..-1].join(' '), OPTIONS[:is_num]
|
273
|
-
end
|
274
|
-
display
|
275
|
-
else
|
276
|
-
puts "Usage: #{USAGE[:set]}"
|
277
|
-
end
|
278
|
-
else
|
279
|
-
puts "Working List does not exist yet. Please create one"
|
280
|
-
puts "Usage: #{USAGE[:create]}"
|
281
|
-
end
|
112
|
+
if Helpers::CLI::OPTIONS[:change_priority]
|
113
|
+
Tasks.set_priority Helpers::CLI::OPTIONS[:priority], ARGV[1..-1].join(' '), OPTIONS[:is_num]
|
114
|
+
end
|
282
115
|
else
|
283
116
|
puts "Invalid command. See todo -h for help."
|
284
|
-
|
285
|
-
else
|
286
|
-
if Config[:working_list_exists]
|
287
|
-
display
|
288
|
-
else
|
289
|
-
puts "Working List does not exist yet. Please create one"
|
290
|
-
puts "Usage: #{USAGE[:create]}"
|
117
|
+
should_display = false
|
291
118
|
end
|
292
119
|
end
|
120
|
+
should_display
|
293
121
|
end
|
294
122
|
|
295
123
|
# Parses the commands and options
|
@@ -298,45 +126,10 @@ module Todo
|
|
298
126
|
begin
|
299
127
|
optparse.parse!
|
300
128
|
commands_parser
|
301
|
-
rescue OptionParser::InvalidOption, OptionParser::InvalidArgument
|
302
|
-
|
129
|
+
rescue OptionParser::InvalidOption, OptionParser::InvalidArgument,
|
130
|
+
OptionParser::MissingArgument, OptionParser::NeedlessArgument => e
|
131
|
+
puts "#{e.to_s. capitalize}. See todo -h for help."
|
303
132
|
end
|
304
133
|
end
|
305
|
-
|
306
|
-
# splits string for wrapping
|
307
|
-
def split string, width
|
308
|
-
split = Array.new
|
309
|
-
if string.length > width #if the string needs to be split
|
310
|
-
string_words = string.split(" ")
|
311
|
-
line = ""
|
312
|
-
string_words.each do |x|
|
313
|
-
if x.length > width #if the word needs to be split
|
314
|
-
#add the start of the word onto the first line (even if it has already started)
|
315
|
-
while line.length < width
|
316
|
-
line += x[0]
|
317
|
-
x = x[1..-1]
|
318
|
-
end
|
319
|
-
split << line
|
320
|
-
#split the rest of the word up onto new lines
|
321
|
-
split_word = x.scan(%r[.{1,#{width}}])
|
322
|
-
split_word[0..-2].each do |word|
|
323
|
-
split << word
|
324
|
-
end
|
325
|
-
line = split_word.last+" "
|
326
|
-
elsif (line + x).length > width-1 #if the word would fit alone on its own line
|
327
|
-
split << line.chomp
|
328
|
-
line = x
|
329
|
-
else #if the word can be added to this line
|
330
|
-
line += x + " "
|
331
|
-
end
|
332
|
-
end
|
333
|
-
split << line
|
334
|
-
else #if the string doesn't need to be split
|
335
|
-
split = [string]
|
336
|
-
end
|
337
|
-
#give back the split line
|
338
|
-
return split
|
339
|
-
end
|
340
|
-
|
341
134
|
end
|
342
135
|
end
|
data/lib/to-do/config.rb
CHANGED
@@ -21,11 +21,11 @@ module Todo
|
|
21
21
|
# a sqlite3 databse that contains all of the tasks
|
22
22
|
:task_database => File.join(ENV["HOME"], ".to-do", "to-do.sqlite"),
|
23
23
|
# the current working list
|
24
|
-
:working_list_name => "
|
25
|
-
# does the working list actually exist
|
26
|
-
:working_list_exists => false,
|
24
|
+
:working_list_name => "My New List",
|
27
25
|
# default width for formatting
|
28
|
-
:width => 50
|
26
|
+
:width => 50,
|
27
|
+
# default color scheme options
|
28
|
+
:color => "light"
|
29
29
|
}
|
30
30
|
end
|
31
31
|
|
@@ -0,0 +1,22 @@
|
|
1
|
+
module Todo
|
2
|
+
|
3
|
+
#A module that contains helper methods
|
4
|
+
module Helpers
|
5
|
+
extend self
|
6
|
+
|
7
|
+
# The database
|
8
|
+
DATABASE = Sequel.sqlite Todo::Config[:task_database]
|
9
|
+
|
10
|
+
# Gets a list of the tasks in the working lists
|
11
|
+
#
|
12
|
+
# @return [Dataset] the dataset containing all of the tasks in the working lists
|
13
|
+
def task_names
|
14
|
+
Helpers::DATABASE[:Tasks].join(:Task_list, :Tasks__Id => :Task_list__Task_Id).join(
|
15
|
+
:Lists, :Lists__Id => :Task_list__List_id).select(:Tasks__Id, :Tasks__Task_number,
|
16
|
+
:Tasks__Name, :Tasks__Completed, :Tasks__Priority).filter(:Lists__Name => Config[:working_list_name])
|
17
|
+
end
|
18
|
+
end
|
19
|
+
end
|
20
|
+
|
21
|
+
require File.join(File.dirname(__FILE__), 'helpers_CLI')
|
22
|
+
require File.join(File.dirname(__FILE__), 'helpers_tasks')
|
@@ -0,0 +1,301 @@
|
|
1
|
+
module Todo
|
2
|
+
module Helpers
|
3
|
+
|
4
|
+
# Helper methods used in the Todo::CLI module
|
5
|
+
module CLI
|
6
|
+
extend self
|
7
|
+
|
8
|
+
# The option flags
|
9
|
+
OPTIONS = {
|
10
|
+
:is_num => false,
|
11
|
+
:clear_all => false,
|
12
|
+
:change_priority => false,
|
13
|
+
:priority => 1,
|
14
|
+
:sort => "n"
|
15
|
+
}
|
16
|
+
|
17
|
+
# Usage messages for each of the commnands
|
18
|
+
USAGE = {
|
19
|
+
:default => "todo [COMMAND] [option] [arguments]",
|
20
|
+
:create => "todo create|switch <LIST NAME>",
|
21
|
+
:display => "todo [display|d] [-s {p,n}]",
|
22
|
+
:add => "todo add|a [-p {high, medium, low}] <TASK>",
|
23
|
+
:finish => "todo finish|f [-n <TASK_NUMBER>] [<TASK>]",
|
24
|
+
:undo => "todo undo|u [-n <TASK_NUMBER>] [<TASK>]",
|
25
|
+
:clear => "todo clear [-a]",
|
26
|
+
:remove => "todo remove|rm <LIST NAME>",
|
27
|
+
:set => "todo set|s [-p {high, medium, low}] [-n <TASK_NUMBER>] [<TASK>]",
|
28
|
+
:config => "todo [--color-scheme {light, dark, none}] [--width <WIDTH_NUMBER>]"
|
29
|
+
}
|
30
|
+
|
31
|
+
# splits string for wrapping
|
32
|
+
#
|
33
|
+
# @param [String] string the string to be split
|
34
|
+
# @param [Width] width the width of the line
|
35
|
+
def split string, width
|
36
|
+
split = Array.new
|
37
|
+
if string.length > width #if the string needs to be split
|
38
|
+
string_words = string.split(" ")
|
39
|
+
line = ""
|
40
|
+
string_words.each do |x|
|
41
|
+
if x.length > width #if the word needs to be split
|
42
|
+
#add the start of the word onto the first line (even if it has already started)
|
43
|
+
while line.length < width
|
44
|
+
line += x[0]
|
45
|
+
x = x[1..-1]
|
46
|
+
end
|
47
|
+
split << line
|
48
|
+
#split the rest of the word up onto new lines
|
49
|
+
split_word = x.scan(%r[.{1,#{width}}])
|
50
|
+
split_word[0..-2].each do |word|
|
51
|
+
split << word
|
52
|
+
end
|
53
|
+
line = split_word.last+" "
|
54
|
+
elsif (line + x).length > width-1 #if the word would fit alone on its own line
|
55
|
+
split << line.chomp
|
56
|
+
line = x + " "
|
57
|
+
else #if the word can be added to this line
|
58
|
+
line += x + " "
|
59
|
+
end
|
60
|
+
end
|
61
|
+
split << line
|
62
|
+
else #if the string doesn't need to be split
|
63
|
+
split = [string]
|
64
|
+
end
|
65
|
+
#give back the split line
|
66
|
+
return split
|
67
|
+
end
|
68
|
+
|
69
|
+
#create a hash of the colors needed for display based on the config file
|
70
|
+
def create_color_hash
|
71
|
+
colors = [:black, :red, :green, :yellow, :blue, :magenta, :cyan, :white, :default]
|
72
|
+
type = Config[:color]
|
73
|
+
color_hash = Hash.new
|
74
|
+
colors.each do |c|
|
75
|
+
case type
|
76
|
+
when "light"
|
77
|
+
color_hash[c] = c
|
78
|
+
when "dark"
|
79
|
+
color_hash[c] = ("light_" + c.to_s).to_sym
|
80
|
+
else
|
81
|
+
color_hash[c] = :default
|
82
|
+
end
|
83
|
+
end
|
84
|
+
color_hash
|
85
|
+
end
|
86
|
+
|
87
|
+
# Helper method for the options parser that displays the title
|
88
|
+
#
|
89
|
+
# @param opts the options switch
|
90
|
+
# @param [Hash] colors the color hash
|
91
|
+
def options_title opts, colors
|
92
|
+
version_path = File.expand_path("../../VERSION", File.dirname(__FILE__))
|
93
|
+
opts.version = File.exist?(version_path) ? File.read(version_path) : ""
|
94
|
+
opts.banner = "Todo: A simple command line todo application\n\n".colorize(colors[:green]) +
|
95
|
+
" usage:".colorize(colors[:cyan]) + " todo [COMMAND] [option] [arguments]".colorize(colors[:red])
|
96
|
+
opts.separator ""
|
97
|
+
opts.separator "Commands:".colorize(colors[:green])
|
98
|
+
end
|
99
|
+
|
100
|
+
# Helper method for the options parser for create, switch
|
101
|
+
#
|
102
|
+
# @param opts the options switch
|
103
|
+
# @param [Hash] colors the color hash
|
104
|
+
def options_create opts, colors
|
105
|
+
#todo create, switch
|
106
|
+
opts.separator " *".colorize(colors[:cyan]) + " create, switch".colorize(colors[:yellow]) +
|
107
|
+
" creates a new list or switches to an existing one".colorize(colors[:magenta])
|
108
|
+
opts.separator " usage: ".colorize(colors[:cyan]) + USAGE[:create].colorize(colors[:red])
|
109
|
+
end
|
110
|
+
|
111
|
+
# Helper method for the options parser for display
|
112
|
+
#
|
113
|
+
# @param opts the options switch
|
114
|
+
# @param [Hash] colors the color hash
|
115
|
+
def options_display opts, colors
|
116
|
+
opts.separator ""
|
117
|
+
opts.separator " *".colorize(colors[:cyan]) + " display, d".colorize(colors[:yellow]) +
|
118
|
+
" displays the current list".colorize(colors[:magenta])
|
119
|
+
opts.separator " usage: ".colorize(colors[:cyan]) + USAGE[:display].colorize(colors[:red])
|
120
|
+
opts.on('-s TYPE', [:p, :n], "sorts the task by Type") do |s|
|
121
|
+
OPTIONS[:sort] = s
|
122
|
+
end
|
123
|
+
end
|
124
|
+
|
125
|
+
# Helper method for the options parser that for add
|
126
|
+
#
|
127
|
+
# @param opts the options switch
|
128
|
+
# @param [Hash] colors the color hash
|
129
|
+
def options_add opts, colors
|
130
|
+
opts.separator ""
|
131
|
+
opts.separator " *".colorize(colors[:cyan]) + " add, a".colorize(colors[:yellow]) +
|
132
|
+
" adds the task to the current list".colorize(colors[:magenta])
|
133
|
+
opts.separator " usage: ".colorize(colors[:cyan]) + USAGE[:add].colorize(colors[:red])
|
134
|
+
opts.on('-p PRIORITY', ["high", "medium", "low"], 'set the priority of the task to one of the', 'following. Default is medium') do |p|
|
135
|
+
priorities = {
|
136
|
+
"high" => 0,
|
137
|
+
"medium" => 1,
|
138
|
+
"low" => 2
|
139
|
+
}
|
140
|
+
OPTIONS[:change_priority] = true
|
141
|
+
OPTIONS[:priority] = priorities[p]
|
142
|
+
end
|
143
|
+
end
|
144
|
+
|
145
|
+
# Helper method for the options parser that for finish
|
146
|
+
#
|
147
|
+
# @param opts the options switch
|
148
|
+
# @param [Hash] colors the color hash
|
149
|
+
def options_finish opts, colors
|
150
|
+
opts.separator ""
|
151
|
+
opts.separator " *".colorize(colors[:cyan]) + " finish , f".colorize(colors[:yellow]) +
|
152
|
+
" marks a task as finished".colorize(colors[:magenta])
|
153
|
+
opts.separator " usage: ".colorize(colors[:cyan]) + USAGE[:finish].colorize(colors[:red])
|
154
|
+
opts.on('-n', 'references a task by its number') do |n|
|
155
|
+
OPTIONS[:is_num] = true
|
156
|
+
end
|
157
|
+
end
|
158
|
+
|
159
|
+
# Helper method for the options parser for undo
|
160
|
+
#
|
161
|
+
# @param opts the options switch
|
162
|
+
# @param [Hash] colors the color hash
|
163
|
+
def options_undo opts, colors
|
164
|
+
opts.separator ""
|
165
|
+
opts.separator " *".colorize(colors[:cyan]) + " undo, u".colorize(colors[:yellow]) +
|
166
|
+
" undos a completed task".colorize(colors[:magenta])
|
167
|
+
opts.separator " usage: ".colorize(colors[:cyan]) + USAGE[:undo].colorize(colors[:red])
|
168
|
+
opts.separator " -n references a task by its number"
|
169
|
+
end
|
170
|
+
|
171
|
+
# Helper method for the options parser for clear
|
172
|
+
#
|
173
|
+
# @param opts the options switch
|
174
|
+
# @param [Hash] colors the color hash
|
175
|
+
def options_clear opts, colors
|
176
|
+
opts.separator ""
|
177
|
+
opts.separator " *".colorize(colors[:cyan]) + " clear".colorize(colors[:yellow]) +
|
178
|
+
" clears a completed tasks".colorize(colors[:magenta])
|
179
|
+
opts.separator " usage: ".colorize(colors[:cyan]) + USAGE[:clear].colorize(colors[:red])
|
180
|
+
opts.on('-a', 'resets the entire list') do
|
181
|
+
OPTIONS[:clear_all] = true
|
182
|
+
end
|
183
|
+
end
|
184
|
+
|
185
|
+
# Helper method for the options parser for remove
|
186
|
+
#
|
187
|
+
# @param opts the options switch
|
188
|
+
# @param [Hash] colors the color hash
|
189
|
+
def options_remove opts, colors
|
190
|
+
opts.separator ""
|
191
|
+
opts.separator " *".colorize(colors[:cyan]) + " remove, rm".colorize(colors[:yellow]) +
|
192
|
+
" removes the list completely.".colorize(colors[:magenta])
|
193
|
+
opts.separator " usage: ".colorize(colors[:cyan]) + USAGE[:remove].colorize(colors[:red])
|
194
|
+
end
|
195
|
+
|
196
|
+
# Helper method for the options parser that for set
|
197
|
+
#
|
198
|
+
# @param opts the options switch
|
199
|
+
# @param [Hash] colors the color hash
|
200
|
+
def options_set opts, colors
|
201
|
+
opts.separator ""
|
202
|
+
opts.separator " *".colorize(colors[:cyan]) + " set, s".colorize(colors[:yellow]) +
|
203
|
+
" adds additional information to a task".colorize(colors[:magenta])
|
204
|
+
opts.separator " usage: ".colorize(colors[:cyan]) + USAGE[:set].colorize(colors[:red])
|
205
|
+
opts.separator " -p TYPE set the priority of the task to one of the \n" +
|
206
|
+
" following. Default is medium"
|
207
|
+
opts.separator " -n references a task by its number"
|
208
|
+
end
|
209
|
+
|
210
|
+
# Helper method for the options parser for help and display working list
|
211
|
+
#
|
212
|
+
# @param opts the options switch
|
213
|
+
# @param [Hash] colors the color hash
|
214
|
+
def options_other opts, colors
|
215
|
+
opts.separator ""
|
216
|
+
opts.separator "Other Options: ".colorize(colors[:green])
|
217
|
+
|
218
|
+
#todo -h
|
219
|
+
opts.on('-h', '--help', 'displays this screen' ) do
|
220
|
+
puts opts
|
221
|
+
exit
|
222
|
+
end
|
223
|
+
#todo -w
|
224
|
+
opts.on('-w', "displays the name of the current list") do
|
225
|
+
puts "Working list is #{Config[:working_list_name]}"
|
226
|
+
exit
|
227
|
+
end
|
228
|
+
end
|
229
|
+
|
230
|
+
# Helper method for the options parser for help and display working list
|
231
|
+
#
|
232
|
+
# @param opts the options switch
|
233
|
+
# @param [Hash] colors the color hash
|
234
|
+
def options_config opts, colors
|
235
|
+
opts.separator ""
|
236
|
+
opts.separator "Configuration Options: ".colorize(colors[:green])
|
237
|
+
opts.separator " usage: ".colorize(colors[:cyan]) + USAGE[:config].colorize(colors[:red])
|
238
|
+
|
239
|
+
#todo -h
|
240
|
+
opts.on('--color-scheme SCHEME', ["light", "dark", "none"], "State whether you are using a light" ,
|
241
|
+
"scheme or dark scheme. This is used","for the text colors. If none work", "with your current
|
242
|
+
color scheme,", "you can turn it off. Default is light." ) do |scheme|
|
243
|
+
Config[:color] = scheme
|
244
|
+
exit
|
245
|
+
end
|
246
|
+
#todo -w
|
247
|
+
opts.on('--width WIDTH', Integer, "Changes the width for formatting") do |width|
|
248
|
+
Config[:width] = width
|
249
|
+
exit
|
250
|
+
end
|
251
|
+
end
|
252
|
+
|
253
|
+
# Print out the tasks
|
254
|
+
#
|
255
|
+
# @param [Integer] completed whether to print out completed or uncompleted
|
256
|
+
# items. 0 if completed. 1 if not
|
257
|
+
# @param [Dataset] tasks the dataset of tasks to print out
|
258
|
+
# @param [Hash] colors the color hash
|
259
|
+
def print_tasks completed, tasks, colors
|
260
|
+
priority = {
|
261
|
+
0 => "**",
|
262
|
+
1 => "*",
|
263
|
+
2 => ""
|
264
|
+
}
|
265
|
+
tasks.each do |task|
|
266
|
+
next if task[:Completed] == completed
|
267
|
+
printf "%2s".colorize(colors[:magenta]), priority[task[:Priority]]
|
268
|
+
printf "%3d. ".to_s.colorize(colors[:yellow]), task[:Task_number]
|
269
|
+
split_v = split task[:Name], Config[:width]-7
|
270
|
+
puts split_v[0]
|
271
|
+
split_v.shift
|
272
|
+
split_v.each do |line|
|
273
|
+
printf " %s\n", " " + line
|
274
|
+
end
|
275
|
+
end
|
276
|
+
end
|
277
|
+
|
278
|
+
# print asterisks
|
279
|
+
#
|
280
|
+
# @param [Hash] colors the color hash
|
281
|
+
def print_stars colors
|
282
|
+
Config[:width].times do
|
283
|
+
print "*".colorize(colors[:red])
|
284
|
+
end
|
285
|
+
end
|
286
|
+
|
287
|
+
# print the header out
|
288
|
+
#
|
289
|
+
# @param [Hash] colors the color hash
|
290
|
+
def print_header colors
|
291
|
+
Helpers::CLI::print_stars colors
|
292
|
+
puts
|
293
|
+
split_name = split Config[:working_list_name], Config[:width]
|
294
|
+
split_name.each do |line|
|
295
|
+
puts line.center(Config[:width]).colorize(colors[:cyan])
|
296
|
+
end
|
297
|
+
Helpers::CLI::print_stars colors
|
298
|
+
end
|
299
|
+
end
|
300
|
+
end
|
301
|
+
end
|
@@ -0,0 +1,34 @@
|
|
1
|
+
module Todo
|
2
|
+
module Helpers
|
3
|
+
|
4
|
+
# Helper methods used in the Todo::Tasks module
|
5
|
+
module Tasks
|
6
|
+
extend self
|
7
|
+
|
8
|
+
# Update a task
|
9
|
+
#
|
10
|
+
# @param [Bool] is_num is the task a number
|
11
|
+
# @param [Dataset] names a dataset of all the tasks in the working list
|
12
|
+
# @param task the task name or number that we are updating
|
13
|
+
# @param [Symbol] key the key we are updating
|
14
|
+
# @param [Integer] value the value that we are changing it too.
|
15
|
+
def update_task is_num, names, task, key, value
|
16
|
+
if is_num
|
17
|
+
found_task = names[:Task_number => task]
|
18
|
+
if found_task
|
19
|
+
Helpers::DATABASE[:Tasks].filter(:Id => found_task[:Id]).update(key => value)
|
20
|
+
else
|
21
|
+
puts "Task ##{task} is not in the list."
|
22
|
+
end
|
23
|
+
else
|
24
|
+
found_task = names.with_sql("SELECT * FROM :table WHERE Name = :task COLLATE NOCASE",:table=>names, :task=>task).first
|
25
|
+
if found_task
|
26
|
+
Helpers::DATABASE[:Tasks].filter(:Id => found_task[:Id]).update(key => value)
|
27
|
+
else
|
28
|
+
puts "Task '#{task}' is not in the list."
|
29
|
+
end
|
30
|
+
end
|
31
|
+
end
|
32
|
+
end
|
33
|
+
end
|
34
|
+
end
|
data/lib/to-do/tasks.rb
CHANGED
@@ -4,25 +4,22 @@ module Todo
|
|
4
4
|
module Tasks
|
5
5
|
extend self
|
6
6
|
|
7
|
-
# The Database
|
8
|
-
DATABASE = Sequel.sqlite Todo::Config[:task_database]
|
9
|
-
|
10
7
|
# Adds the tast to the list
|
11
8
|
#
|
12
9
|
# @param [String] task the task to add to the list
|
13
10
|
# @param [Integer] priority the priority of the task
|
14
11
|
def add task, priority=1
|
15
|
-
list = DATABASE[:Lists].select(:Total, :Id)[:Name=>Todo::Config[:working_list_name]]
|
12
|
+
list = Helpers::DATABASE[:Lists].select(:Total, :Id)[:Name=>Todo::Config[:working_list_name]]
|
16
13
|
if !list
|
17
|
-
DATABASE[:Lists] << {:Name => Config[:working_list_name], :Total => 0}
|
18
|
-
list = DATABASE[:Lists].select(:Total, :Id)[:Name=>Todo::Config[:working_list_name]]
|
14
|
+
Helpers::DATABASE[:Lists] << {:Name => Config[:working_list_name], :Total => 0}
|
15
|
+
list = Helpers::DATABASE[:Lists].select(:Total, :Id)[:Name=>Todo::Config[:working_list_name]]
|
19
16
|
end
|
20
17
|
count = list[:Total]+1
|
21
|
-
DATABASE[:Tasks] << {:Task_number => count, :Name => task, :Completed => 0, :Priority => priority}
|
18
|
+
Helpers::DATABASE[:Tasks] << {:Task_number => count, :Name => task, :Completed => 0, :Priority => priority}
|
22
19
|
list_id = list[:Id]
|
23
|
-
task_id = DATABASE[:Tasks].with_sql("SELECT last_insert_rowid() FROM Tasks")
|
24
|
-
DATABASE[:Task_list] << {:Task_id => task_id, :List_id => list_id}
|
25
|
-
DATABASE[:Lists].filter(:Id => list_id).update(:Total => count)
|
20
|
+
task_id = Helpers::DATABASE[:Tasks].with_sql("SELECT last_insert_rowid() FROM Tasks")
|
21
|
+
Helpers::DATABASE[:Task_list] << {:Task_id => task_id, :List_id => list_id}
|
22
|
+
Helpers::DATABASE[:Lists].filter(:Id => list_id).update(:Total => count)
|
26
23
|
end
|
27
24
|
|
28
25
|
# finish the task. task is either a case insensitive task on the list or
|
@@ -52,12 +49,12 @@ module Todo
|
|
52
49
|
# @param completed [Integer] 1 if clearing completed tasks, 0 if clearing
|
53
50
|
# Uncompleted tasks
|
54
51
|
def clear_each completed ,list_name
|
55
|
-
tasks = DATABASE[:Tasks].join(:Task_list, :Tasks__id => :Task_list__Task_id).join(
|
52
|
+
tasks = Helpers::DATABASE[:Tasks].join(:Task_list, :Tasks__id => :Task_list__Task_id).join(
|
56
53
|
:Lists, :Lists__id => :Task_list__List_id).select(:Tasks__Id).filter(
|
57
54
|
:Lists__Name => Config[:working_list_name]).filter(:Tasks__Completed => completed)
|
58
55
|
tasks.each do |task|
|
59
|
-
DATABASE[:Task_list].filter(:Task_id => task[:Id]).delete
|
60
|
-
DATABASE[:Tasks].filter(:Id => task[:Id]).delete
|
56
|
+
Helpers::DATABASE[:Task_list].filter(:Task_id => task[:Id]).delete
|
57
|
+
Helpers::DATABASE[:Tasks].filter(:Id => task[:Id]).delete
|
61
58
|
end
|
62
59
|
end
|
63
60
|
|
@@ -69,8 +66,8 @@ module Todo
|
|
69
66
|
clear_each 1, list_name
|
70
67
|
if clear_all
|
71
68
|
clear_each 0, list_name
|
72
|
-
#DATABASE[:Lists].filter(:Name => list_name).update(:Total => 0)
|
73
|
-
DATABASE[:Lists].filter(:Name => list_name).delete
|
69
|
+
#Helpers::DATABASE[:Lists].filter(:Name => list_name).update(:Total => 0)
|
70
|
+
Helpers::DATABASE[:Lists].filter(:Name => list_name).delete
|
74
71
|
puts "Cleared all tasks in #{list_name}"
|
75
72
|
else
|
76
73
|
puts "Cleared completed tasks in #{Config[:working_list_name]}"
|
@@ -85,54 +82,19 @@ module Todo
|
|
85
82
|
# @param initial [Integer] 0 if you are finishing a task, 1 if you are undoing a task
|
86
83
|
# @param final [Integer] 1 if you are finishing a task, 0 if you ara undoing a task
|
87
84
|
def finish_undo task , is_num, initial, final
|
88
|
-
|
89
|
-
names
|
90
|
-
:Lists, :Lists__Id => :Task_list__List_id).select(:Tasks__Id, :Tasks__Task_number,
|
91
|
-
:Tasks__Name).filter(:Lists__Name => Config[:working_list_name]).filter(
|
92
|
-
:Tasks__Completed => initial)
|
93
|
-
if is_num
|
94
|
-
found_task = names[:Task_number => task]
|
95
|
-
if found_task
|
96
|
-
DATABASE[:Tasks].filter(:Id => found_task[:Id]).update(:Completed => final)
|
97
|
-
else
|
98
|
-
puts "Task ##{task} is not in the list."
|
99
|
-
end
|
100
|
-
else
|
101
|
-
found_task = names.with_sql("SELECT * FROM :table WHERE Name = :task COLLATE NOCASE",:table=>names, :task=>task).first
|
102
|
-
if found_task
|
103
|
-
DATABASE[:Tasks].filter(:Id => found_task[:Id]).update(:Completed => final)
|
104
|
-
else
|
105
|
-
puts "Task '#{task}' is not in the list."
|
106
|
-
end
|
107
|
-
end
|
85
|
+
names =Helpers::task_names.filter(:Tasks__Completed => initial)
|
86
|
+
Helpers::Tasks::update_task is_num, names, task, :Completed, final
|
108
87
|
end
|
109
88
|
|
110
89
|
# Sets the priority of a task
|
111
90
|
#
|
112
91
|
# @param priority [Integer] the new priority
|
113
|
-
# @param
|
92
|
+
# @param task either a task number or a task name to change the priority of
|
114
93
|
# @param [Bool] is_num if the task param represents the task number, true.
|
115
94
|
# false if it is the task name
|
116
95
|
def set_priority priority, task, is_num
|
117
|
-
|
118
|
-
names
|
119
|
-
:Lists, :Lists__Id => :Task_list__List_id).select(:Tasks__Id, :Tasks__Task_number,
|
120
|
-
:Tasks__Name).filter(:Lists__Name => Config[:working_list_name])
|
121
|
-
if is_num
|
122
|
-
found_task = names[:Task_number => task]
|
123
|
-
if found_task
|
124
|
-
DATABASE[:Tasks].filter(:Id => found_task[:Id]).update(:Priority => priority)
|
125
|
-
else
|
126
|
-
puts "Task ##{task} is not in the list."
|
127
|
-
end
|
128
|
-
else
|
129
|
-
found_task = names.with_sql("SELECT * FROM :table WHERE Name = :task COLLATE NOCASE",:table=>names, :task=>task).first
|
130
|
-
if found_task
|
131
|
-
DATABASE[:Tasks].filter(:Id => found_task[:Id]).update(:Priority => priority)
|
132
|
-
else
|
133
|
-
puts "Task '#{task}' is not in the list."
|
134
|
-
end
|
135
|
-
end
|
96
|
+
names =Helpers::Tasks::task_names
|
97
|
+
Helpers::Tasks::update_task is_num, names, task, :Priority, priority
|
136
98
|
end
|
137
99
|
end
|
138
100
|
end
|
data/to-do.gemspec
CHANGED
@@ -5,11 +5,11 @@
|
|
5
5
|
|
6
6
|
Gem::Specification.new do |s|
|
7
7
|
s.name = "to-do"
|
8
|
-
s.version = "1.3.
|
8
|
+
s.version = "1.3.1"
|
9
9
|
|
10
10
|
s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
|
11
11
|
s.authors = ["Kristen Mills"]
|
12
|
-
s.date = "2012-
|
12
|
+
s.date = "2012-10-09"
|
13
13
|
s.description = "A simple command line todo application"
|
14
14
|
s.email = "kristen@kristen-mills.com"
|
15
15
|
s.executables = ["todo"]
|
@@ -32,6 +32,9 @@ Gem::Specification.new do |s|
|
|
32
32
|
"lib/to-do/dbmigrations/001_create_tables.rb",
|
33
33
|
"lib/to-do/dbmigrations/002_rename_name_column.rb",
|
34
34
|
"lib/to-do/dbmigrations/003_priorities.rb",
|
35
|
+
"lib/to-do/helpers/helpers.rb",
|
36
|
+
"lib/to-do/helpers/helpers_CLI.rb",
|
37
|
+
"lib/to-do/helpers/helpers_tasks.rb",
|
35
38
|
"lib/to-do/old/list.rb",
|
36
39
|
"lib/to-do/tasks.rb",
|
37
40
|
"test/helper.rb",
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: to-do
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.3.
|
4
|
+
version: 1.3.1
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -9,11 +9,11 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date: 2012-
|
12
|
+
date: 2012-10-09 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: shoulda
|
16
|
-
requirement: &
|
16
|
+
requirement: &70186149754420 !ruby/object:Gem::Requirement
|
17
17
|
none: false
|
18
18
|
requirements:
|
19
19
|
- - ! '>='
|
@@ -21,10 +21,10 @@ dependencies:
|
|
21
21
|
version: '0'
|
22
22
|
type: :runtime
|
23
23
|
prerelease: false
|
24
|
-
version_requirements: *
|
24
|
+
version_requirements: *70186149754420
|
25
25
|
- !ruby/object:Gem::Dependency
|
26
26
|
name: sqlite3
|
27
|
-
requirement: &
|
27
|
+
requirement: &70186149766420 !ruby/object:Gem::Requirement
|
28
28
|
none: false
|
29
29
|
requirements:
|
30
30
|
- - ! '>='
|
@@ -32,10 +32,10 @@ dependencies:
|
|
32
32
|
version: '0'
|
33
33
|
type: :runtime
|
34
34
|
prerelease: false
|
35
|
-
version_requirements: *
|
35
|
+
version_requirements: *70186149766420
|
36
36
|
- !ruby/object:Gem::Dependency
|
37
37
|
name: sequel
|
38
|
-
requirement: &
|
38
|
+
requirement: &70186149763580 !ruby/object:Gem::Requirement
|
39
39
|
none: false
|
40
40
|
requirements:
|
41
41
|
- - ! '>='
|
@@ -43,10 +43,10 @@ dependencies:
|
|
43
43
|
version: '3.12'
|
44
44
|
type: :runtime
|
45
45
|
prerelease: false
|
46
|
-
version_requirements: *
|
46
|
+
version_requirements: *70186149763580
|
47
47
|
- !ruby/object:Gem::Dependency
|
48
48
|
name: bundler
|
49
|
-
requirement: &
|
49
|
+
requirement: &70186149560360 !ruby/object:Gem::Requirement
|
50
50
|
none: false
|
51
51
|
requirements:
|
52
52
|
- - ! '>='
|
@@ -54,10 +54,10 @@ dependencies:
|
|
54
54
|
version: 1.0.0
|
55
55
|
type: :runtime
|
56
56
|
prerelease: false
|
57
|
-
version_requirements: *
|
57
|
+
version_requirements: *70186149560360
|
58
58
|
- !ruby/object:Gem::Dependency
|
59
59
|
name: jeweler
|
60
|
-
requirement: &
|
60
|
+
requirement: &70186149567920 !ruby/object:Gem::Requirement
|
61
61
|
none: false
|
62
62
|
requirements:
|
63
63
|
- - ~>
|
@@ -65,10 +65,10 @@ dependencies:
|
|
65
65
|
version: 1.8.4
|
66
66
|
type: :runtime
|
67
67
|
prerelease: false
|
68
|
-
version_requirements: *
|
68
|
+
version_requirements: *70186149567920
|
69
69
|
- !ruby/object:Gem::Dependency
|
70
70
|
name: simplecov
|
71
|
-
requirement: &
|
71
|
+
requirement: &70186149562240 !ruby/object:Gem::Requirement
|
72
72
|
none: false
|
73
73
|
requirements:
|
74
74
|
- - ! '>='
|
@@ -76,10 +76,10 @@ dependencies:
|
|
76
76
|
version: '0'
|
77
77
|
type: :runtime
|
78
78
|
prerelease: false
|
79
|
-
version_requirements: *
|
79
|
+
version_requirements: *70186149562240
|
80
80
|
- !ruby/object:Gem::Dependency
|
81
81
|
name: colorize
|
82
|
-
requirement: &
|
82
|
+
requirement: &70186149842620 !ruby/object:Gem::Requirement
|
83
83
|
none: false
|
84
84
|
requirements:
|
85
85
|
- - ! '>='
|
@@ -87,10 +87,10 @@ dependencies:
|
|
87
87
|
version: '0'
|
88
88
|
type: :runtime
|
89
89
|
prerelease: false
|
90
|
-
version_requirements: *
|
90
|
+
version_requirements: *70186149842620
|
91
91
|
- !ruby/object:Gem::Dependency
|
92
92
|
name: yard
|
93
|
-
requirement: &
|
93
|
+
requirement: &70186149854300 !ruby/object:Gem::Requirement
|
94
94
|
none: false
|
95
95
|
requirements:
|
96
96
|
- - ! '>='
|
@@ -98,7 +98,7 @@ dependencies:
|
|
98
98
|
version: '0'
|
99
99
|
type: :development
|
100
100
|
prerelease: false
|
101
|
-
version_requirements: *
|
101
|
+
version_requirements: *70186149854300
|
102
102
|
description: A simple command line todo application
|
103
103
|
email: kristen@kristen-mills.com
|
104
104
|
executables:
|
@@ -122,6 +122,9 @@ files:
|
|
122
122
|
- lib/to-do/dbmigrations/001_create_tables.rb
|
123
123
|
- lib/to-do/dbmigrations/002_rename_name_column.rb
|
124
124
|
- lib/to-do/dbmigrations/003_priorities.rb
|
125
|
+
- lib/to-do/helpers/helpers.rb
|
126
|
+
- lib/to-do/helpers/helpers_CLI.rb
|
127
|
+
- lib/to-do/helpers/helpers_tasks.rb
|
125
128
|
- lib/to-do/old/list.rb
|
126
129
|
- lib/to-do/tasks.rb
|
127
130
|
- test/helper.rb
|
@@ -142,7 +145,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
142
145
|
version: '0'
|
143
146
|
segments:
|
144
147
|
- 0
|
145
|
-
hash:
|
148
|
+
hash: 1542733467158236008
|
146
149
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
147
150
|
none: false
|
148
151
|
requirements:
|