ineedto 0.0.1 → 0.0.2
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/bin/ineedto +20 -10
- data/lib/cmd.rb +3 -1
- data/lib/cmd/clean.rb +9 -15
- data/lib/cmd/complete.rb +12 -16
- data/lib/cmd/completed.rb +13 -18
- data/lib/cmd/list.rb +13 -19
- data/lib/cmd/new.rb +23 -29
- data/lib/cmd/pending.rb +14 -20
- data/lib/cmd/root.rb +5 -15
- data/lib/cmd/search.rb +13 -17
- data/lib/cmd/today.rb +14 -20
- metadata +1 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: b82885942b51f481340652730bee824d8e6a2ab92a8fea6fe96e11e5b7a68dc4
|
4
|
+
data.tar.gz: 20b160d9ff7726c1b779e6f6cde1e0a99065d0853eb095aea70e8b98c409c479
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: b4bbc32083fb398c11366c0c2765d556a37efdab9eebb693eab926f85f2b7202902d8cd649f9e9ab302ac97d7ddfed00406e7c4b128372fe884f6ffa79bcde3e
|
7
|
+
data.tar.gz: 8e44ecf516f1e426a535ff11458471371ff57c0391ee73d9bbace5ec8fc4a07577d577ea21a21685164b30e7840c869854872d82b7b1935167be8ee08d1ef442
|
data/bin/ineedto
CHANGED
@@ -26,30 +26,40 @@ end unless DB.table_exists?(:todos)
|
|
26
26
|
cmd = case ARGV.first
|
27
27
|
when "new"
|
28
28
|
ARGV.shift
|
29
|
-
Cmd::NewTask.new(DB
|
29
|
+
Cmd::NewTask.new(DB)
|
30
30
|
when "complete"
|
31
31
|
ARGV.shift
|
32
|
-
Cmd::CompleteTask.new(DB
|
32
|
+
Cmd::CompleteTask.new(DB)
|
33
33
|
when "list"
|
34
34
|
ARGV.shift
|
35
|
-
Cmd::ListTasks.new(DB
|
35
|
+
Cmd::ListTasks.new(DB)
|
36
36
|
when "pending"
|
37
37
|
ARGV.shift
|
38
|
-
Cmd::PendingTasks.new(DB
|
38
|
+
Cmd::PendingTasks.new(DB)
|
39
39
|
when "completed"
|
40
40
|
ARGV.shift
|
41
|
-
Cmd::CompletedTasks.new(DB
|
41
|
+
Cmd::CompletedTasks.new(DB)
|
42
42
|
when "search"
|
43
43
|
ARGV.shift
|
44
|
-
Cmd::SearchTasks.new(DB
|
44
|
+
Cmd::SearchTasks.new(DB)
|
45
45
|
when "today"
|
46
46
|
ARGV.shift
|
47
|
-
Cmd::TodayTasks.new(DB
|
47
|
+
Cmd::TodayTasks.new(DB)
|
48
48
|
when "clean"
|
49
49
|
ARGV.shift
|
50
|
-
Cmd::CleanTasks.new(DB
|
50
|
+
Cmd::CleanTasks.new(DB)
|
51
51
|
else
|
52
|
-
Cmd::Root.new
|
52
|
+
Cmd::Root.new
|
53
|
+
end
|
54
|
+
|
55
|
+
begin
|
56
|
+
puts cmd.(ARGV)
|
57
|
+
rescue Cmd::CmdError => e
|
58
|
+
puts e.message
|
59
|
+
exit(1)
|
60
|
+
rescue => e
|
61
|
+
puts "Failed to execute cmd"
|
62
|
+
puts e
|
63
|
+
exit(1)
|
53
64
|
end
|
54
65
|
|
55
|
-
cmd.(ARGV)
|
data/lib/cmd.rb
CHANGED
data/lib/cmd/clean.rb
CHANGED
@@ -3,37 +3,31 @@ require 'terminal-table'
|
|
3
3
|
|
4
4
|
module Cmd
|
5
5
|
class CleanTasks
|
6
|
-
def initialize(db
|
6
|
+
def initialize(db)
|
7
7
|
@db = db
|
8
|
-
@logger = logger
|
9
|
-
@stdout = stdout
|
10
|
-
@stderr = stderr
|
11
8
|
end
|
12
9
|
|
13
10
|
def call(argv)
|
14
|
-
|
15
|
-
|
16
|
-
|
11
|
+
parse(argv)
|
12
|
+
@out || begin
|
13
|
+
todos = @db[:todos].delete
|
14
|
+
"Tasks cleaned up succesffully"
|
15
|
+
end
|
17
16
|
end
|
18
17
|
|
19
18
|
private
|
20
19
|
|
21
20
|
def parse(args)
|
22
|
-
options = {}
|
23
21
|
parser = OptionParser.new do |opts|
|
24
22
|
opts.banner = "Usage: ineedto clean"
|
25
23
|
|
26
24
|
opts.on("-h", "--help", "Show help and exit") do
|
27
|
-
@
|
28
|
-
exit(0)
|
25
|
+
@out = opts.help
|
29
26
|
end
|
30
27
|
end
|
31
28
|
parser.parse!(args)
|
32
|
-
|
33
|
-
|
34
|
-
@stderr.puts e.message
|
35
|
-
@stderr.puts parser
|
36
|
-
exit(1)
|
29
|
+
rescue OptionParser::ParseError => e
|
30
|
+
raise CmdError, e.message
|
37
31
|
end
|
38
32
|
end
|
39
33
|
end
|
data/lib/cmd/complete.rb
CHANGED
@@ -3,22 +3,21 @@ require 'optparse'
|
|
3
3
|
|
4
4
|
module Cmd
|
5
5
|
class CompleteTask
|
6
|
-
def initialize(db
|
6
|
+
def initialize(db)
|
7
7
|
@db = db
|
8
|
-
@logger = logger
|
9
|
-
@stdout = stdout
|
10
|
-
@stderr = stderr
|
11
8
|
end
|
12
9
|
|
13
10
|
def call(args)
|
14
11
|
options = parse(args)
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
12
|
+
@out || begin
|
13
|
+
todo = @db[:todos].where(id: options[:id]).first
|
14
|
+
if todo.nil?
|
15
|
+
"Not found"
|
16
|
+
else
|
17
|
+
@db[:todos].where(id: options[:id]).update(done: true, completed_on: Date.today)
|
18
|
+
"Task completed"
|
19
|
+
end
|
19
20
|
end
|
20
|
-
@db[:todos].where(id: options[:id]).update(done: true, completed_on: Date.today)
|
21
|
-
@stdout.puts "Task completed"
|
22
21
|
end
|
23
22
|
|
24
23
|
private
|
@@ -29,8 +28,7 @@ module Cmd
|
|
29
28
|
opts.banner = "Usage: ineedto complete"
|
30
29
|
|
31
30
|
opts.on("--h", "--help", "Show this help and exit") do
|
32
|
-
@
|
33
|
-
exit(0)
|
31
|
+
@out = opts.help
|
34
32
|
end
|
35
33
|
|
36
34
|
opts.on("-t ID", "--task ID", Integer, "Task to complete") do |id|
|
@@ -39,10 +37,8 @@ module Cmd
|
|
39
37
|
end
|
40
38
|
parser.parse!(args)
|
41
39
|
options
|
42
|
-
rescue => e
|
43
|
-
|
44
|
-
@stderr.puts parser
|
45
|
-
exit(1)
|
40
|
+
rescue OptionParser::ParseError => e
|
41
|
+
raise CmdError, e.message
|
46
42
|
end
|
47
43
|
end
|
48
44
|
end
|
data/lib/cmd/completed.rb
CHANGED
@@ -3,24 +3,22 @@ require 'terminal-table'
|
|
3
3
|
|
4
4
|
module Cmd
|
5
5
|
class CompletedTasks
|
6
|
-
def initialize(db
|
6
|
+
def initialize(db)
|
7
7
|
@db = db
|
8
|
-
@logger = logger
|
9
|
-
@stdout = stdout
|
10
|
-
@stderr = stderr
|
11
8
|
end
|
12
9
|
|
13
10
|
def call(argv)
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
11
|
+
parse(argv)
|
12
|
+
@out || begin
|
13
|
+
todos = @db[:todos].where(done: true).all
|
14
|
+
table = Terminal::Table.new do |t|
|
15
|
+
t.headings = ["ID", "Priority", "Name", "Done", "Due Date", "Completed On"]
|
16
|
+
todos.each do |todo|
|
17
|
+
t.add_row [todo[:id], todo[:priority], todo[:name], todo[:done], todo[:due_date].strftime(DATE_FORMAT), todo[:completed_on].strftime(DATE_FORMAT)]
|
18
|
+
end
|
20
19
|
end
|
20
|
+
table
|
21
21
|
end
|
22
|
-
|
23
|
-
@stdout.puts(table)
|
24
22
|
end
|
25
23
|
|
26
24
|
private
|
@@ -31,16 +29,13 @@ module Cmd
|
|
31
29
|
opts.banner = "Usage: todo completed"
|
32
30
|
|
33
31
|
opts.on("-h", "--help", "Show help and exit") do
|
34
|
-
@
|
35
|
-
exit(0)
|
32
|
+
@out = opts.help
|
36
33
|
end
|
37
34
|
end
|
38
35
|
parser.parse!(args)
|
39
36
|
options
|
40
|
-
rescue => e
|
41
|
-
|
42
|
-
@stderr.puts parser
|
43
|
-
exit(1)
|
37
|
+
rescue OptionParser::ParseError => e
|
38
|
+
raise CmdError, e.message
|
44
39
|
end
|
45
40
|
end
|
46
41
|
end
|
data/lib/cmd/list.rb
CHANGED
@@ -3,44 +3,38 @@ require 'terminal-table'
|
|
3
3
|
|
4
4
|
module Cmd
|
5
5
|
class ListTasks
|
6
|
-
def initialize(db
|
6
|
+
def initialize(db)
|
7
7
|
@db = db
|
8
|
-
@logger = logger
|
9
|
-
@stdout = stdout
|
10
|
-
@stderr = stderr
|
11
8
|
end
|
12
9
|
|
13
10
|
def call(argv)
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
11
|
+
parse(argv)
|
12
|
+
@out || begin
|
13
|
+
todos = @db[:todos].all
|
14
|
+
table = Terminal::Table.new do |t|
|
15
|
+
t.headings = ["ID", "Priority", "Name", "Done", "Due Date", "Completed On"]
|
16
|
+
todos.each do |todo|
|
17
|
+
t.add_row [todo[:id], todo[:priority], todo[:name], todo[:done], todo[:due_date].strftime(DATE_FORMAT), todo[:completed_on] && todo[:completed_on].strftime(DATE_FORMAT)]
|
18
|
+
end
|
20
19
|
end
|
21
|
-
end
|
22
20
|
|
23
|
-
|
21
|
+
table
|
22
|
+
end
|
24
23
|
end
|
25
24
|
|
26
25
|
private
|
27
26
|
|
28
27
|
def parse(args)
|
29
|
-
options = {}
|
30
28
|
parser = OptionParser.new do |opts|
|
31
29
|
opts.banner = "Usage: ineedto list"
|
32
30
|
|
33
31
|
opts.on("-h", "--help", "Show help and exit") do
|
34
|
-
@
|
35
|
-
exit(0)
|
32
|
+
@out = opts.help
|
36
33
|
end
|
37
34
|
end
|
38
35
|
parser.parse!(args)
|
39
|
-
options
|
40
36
|
rescue => e
|
41
|
-
|
42
|
-
@stderr.puts parser
|
43
|
-
exit(1)
|
37
|
+
raise CmdError, e.message
|
44
38
|
end
|
45
39
|
end
|
46
40
|
end
|
data/lib/cmd/new.rb
CHANGED
@@ -18,39 +18,36 @@ module Cmd
|
|
18
18
|
end
|
19
19
|
|
20
20
|
class NewTask
|
21
|
-
def initialize(db
|
21
|
+
def initialize(db)
|
22
22
|
@db = db
|
23
|
-
@logger = logger
|
24
|
-
@stdout = stdout
|
25
|
-
@stderr = stderr
|
26
23
|
@contract = NewTaskContract.new
|
24
|
+
@out = nil
|
27
25
|
end
|
28
26
|
|
29
27
|
def call(args)
|
30
28
|
options = parse(args)
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
|
29
|
+
@out || begin
|
30
|
+
errors = @contract.(options).errors(full: true).to_h
|
31
|
+
unless errors.empty?
|
32
|
+
table = Terminal::Table.new do |t|
|
33
|
+
errors.each do |field, errors|
|
34
|
+
row = []
|
35
|
+
row.push(field)
|
36
|
+
errors.each do |err|
|
37
|
+
row.push(err)
|
38
|
+
end
|
39
|
+
t.add_row(row)
|
39
40
|
end
|
40
|
-
t.add_row(row)
|
41
41
|
end
|
42
|
+
"Failed to create task\n" + table.to_s
|
43
|
+
else
|
44
|
+
options[:done] = false
|
45
|
+
@db[:todos].insert(options)
|
46
|
+
"Task added successfully"
|
42
47
|
end
|
43
|
-
@stderr.puts "Failed to create task"
|
44
|
-
@stderr.puts table
|
45
|
-
return
|
46
48
|
end
|
47
|
-
|
48
|
-
|
49
|
-
@stdout.puts "Task added successfully"
|
50
|
-
rescue => e
|
51
|
-
@stderr.puts e.message
|
52
|
-
@stderr.puts parser
|
53
|
-
exit(1)
|
49
|
+
rescue OptionParser::ParseError => e
|
50
|
+
raise CmdError, e.message
|
54
51
|
end
|
55
52
|
|
56
53
|
private
|
@@ -61,8 +58,7 @@ module Cmd
|
|
61
58
|
opts.banner = "Usage: ineedto new"
|
62
59
|
|
63
60
|
opts.on("-h", "--help", "Prints this help") do
|
64
|
-
|
65
|
-
exit
|
61
|
+
@out = opts.help
|
66
62
|
end
|
67
63
|
|
68
64
|
opts.on("-n", "--name NAME", "Task Name") do |name|
|
@@ -79,10 +75,8 @@ module Cmd
|
|
79
75
|
end
|
80
76
|
parser.parse(args)
|
81
77
|
options
|
82
|
-
rescue => e
|
83
|
-
|
84
|
-
@logger.debug(e.message)
|
85
|
-
exit(1)
|
78
|
+
rescue OptionParser::ParseError => e
|
79
|
+
raise CmdError, e.message
|
86
80
|
end
|
87
81
|
end
|
88
82
|
end
|
data/lib/cmd/pending.rb
CHANGED
@@ -4,44 +4,38 @@ require 'terminal-table'
|
|
4
4
|
|
5
5
|
module Cmd
|
6
6
|
class PendingTasks
|
7
|
-
def initialize(db
|
7
|
+
def initialize(db)
|
8
8
|
@db = db
|
9
|
-
@logger = logger
|
10
|
-
@stdout = stdout
|
11
|
-
@stderr = stderr
|
12
9
|
end
|
13
10
|
|
14
11
|
def call(argv)
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
12
|
+
parse(argv)
|
13
|
+
@out || begin
|
14
|
+
todos = @db[:todos].where(done: false).all
|
15
|
+
table = Terminal::Table.new do |t|
|
16
|
+
t.headings = ["ID", "Priority", "Name", "Done", "Due Date"]
|
17
|
+
todos.each do |todo|
|
18
|
+
t.add_row [todo[:id], todo[:priority], todo[:name], todo[:done], todo[:due_date].strftime(DATE_FORMAT)]
|
19
|
+
end
|
21
20
|
end
|
22
|
-
end
|
23
21
|
|
24
|
-
|
22
|
+
table
|
23
|
+
end
|
25
24
|
end
|
26
25
|
|
27
26
|
private
|
28
27
|
|
29
28
|
def parse(args)
|
30
|
-
options = {}
|
31
29
|
parser = OptionParser.new do |opts|
|
32
30
|
opts.banner = "Usage: ineedto pending"
|
33
31
|
|
34
32
|
opts.on("-h", "--help", "Show help and exit") do
|
35
|
-
|
36
|
-
exit(0)
|
33
|
+
@out = opts.help
|
37
34
|
end
|
38
35
|
end
|
39
36
|
parser.parse!(args)
|
40
|
-
|
41
|
-
|
42
|
-
@stderr.puts e.message
|
43
|
-
@stderr.puts parser
|
44
|
-
exit(1)
|
37
|
+
rescue OptionParser::ParseError => e
|
38
|
+
raise CmdError, e.message
|
45
39
|
end
|
46
40
|
end
|
47
41
|
end
|
data/lib/cmd/root.rb
CHANGED
@@ -2,32 +2,22 @@ require 'optparse'
|
|
2
2
|
|
3
3
|
module Cmd
|
4
4
|
class Root
|
5
|
-
def initialize(logger, stdout, stderr)
|
6
|
-
@logger = logger
|
7
|
-
@stdout = stdout
|
8
|
-
@stderr = stderr
|
9
|
-
end
|
10
|
-
|
11
5
|
def call(args)
|
12
6
|
parser = OptionParser.new do |opts|
|
13
7
|
opts.banner = "Usage: ineedto [new|complete|list|pending|completed|today|search]"
|
14
8
|
|
15
9
|
opts.on("-h", "--help", "Prints this help") do
|
16
|
-
@
|
17
|
-
exit
|
10
|
+
@out = opts.help
|
18
11
|
end
|
19
12
|
|
20
13
|
opts.on("-v", "--version", "Prints version") do
|
21
|
-
@
|
22
|
-
exit
|
14
|
+
@out = VERSION
|
23
15
|
end
|
24
16
|
end
|
25
17
|
parser.parse!(args)
|
26
|
-
@
|
27
|
-
rescue => e
|
28
|
-
|
29
|
-
@stderr.puts parser
|
30
|
-
exit(1)
|
18
|
+
@out || parser.help
|
19
|
+
rescue OptionParser::ParseError => e
|
20
|
+
raise CmdError, e.message
|
31
21
|
end
|
32
22
|
end
|
33
23
|
end
|
data/lib/cmd/search.rb
CHANGED
@@ -5,24 +5,23 @@ require 'sequel'
|
|
5
5
|
|
6
6
|
module Cmd
|
7
7
|
class SearchTasks
|
8
|
-
def initialize(db
|
8
|
+
def initialize(db)
|
9
9
|
@db = db
|
10
|
-
@logger = logger
|
11
|
-
@stdout = stdout
|
12
|
-
@stderr = stderr
|
13
10
|
end
|
14
11
|
|
15
12
|
def call(argv)
|
16
13
|
options = parse(argv)
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
14
|
+
@out || begin
|
15
|
+
todos = @db[:todos].where(Sequel.ilike(:name, "%#{options[:q]}%")).all
|
16
|
+
table = Terminal::Table.new do |t|
|
17
|
+
t.headings = ["ID", "Priority", "Name", "Done", "Due Date", "Completed On"]
|
18
|
+
todos.each do |todo|
|
19
|
+
t.add_row [todo[:id], todo[:priority], todo[:name], todo[:done], todo[:due_date].strftime(DATE_FORMAT), todo[:completed_on] && todo[:completed_on].strftime(DATE_FORMAT)]
|
20
|
+
end
|
22
21
|
end
|
23
|
-
end
|
24
22
|
|
25
|
-
|
23
|
+
table
|
24
|
+
end
|
26
25
|
end
|
27
26
|
|
28
27
|
private
|
@@ -33,8 +32,7 @@ module Cmd
|
|
33
32
|
opts.banner = "Usage: ineedto search"
|
34
33
|
|
35
34
|
opts.on("-h", "--help", "Show help and exit") do
|
36
|
-
@
|
37
|
-
exit(0)
|
35
|
+
@out = opts.help
|
38
36
|
end
|
39
37
|
|
40
38
|
opts.on("-q", "--query [QUERY]", "Search tasks using q") do |q|
|
@@ -43,10 +41,8 @@ module Cmd
|
|
43
41
|
end
|
44
42
|
parser.parse!(args)
|
45
43
|
options
|
46
|
-
rescue => e
|
47
|
-
|
48
|
-
@stderr.puts parser
|
49
|
-
exit(1)
|
44
|
+
rescue OptionParser::ParseError => e
|
45
|
+
raise CmdError, e.message
|
50
46
|
end
|
51
47
|
end
|
52
48
|
end
|
data/lib/cmd/today.rb
CHANGED
@@ -3,44 +3,38 @@ require 'terminal-table'
|
|
3
3
|
|
4
4
|
module Cmd
|
5
5
|
class TodayTasks
|
6
|
-
def initialize(db
|
6
|
+
def initialize(db)
|
7
7
|
@db = db
|
8
|
-
@logger = logger
|
9
|
-
@stdout = stdout
|
10
|
-
@stderr = stderr
|
11
8
|
end
|
12
9
|
|
13
10
|
def call(argv)
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
11
|
+
parse(argv)
|
12
|
+
@out || begin
|
13
|
+
todos = @db[:todos].where(due_date: Date.today).all
|
14
|
+
table = Terminal::Table.new do |t|
|
15
|
+
t.headings = ["ID", "Priority", "Name", "Done", "Due Date", "Completed On"]
|
16
|
+
todos.each do |todo|
|
17
|
+
t.add_row [todo[:id], todo[:priority], todo[:name], todo[:done], todo[:due_date].strftime(DATE_FORMAT), todo[:completed_on] && todo[:completed_on].strftime(DATE_FORMAT)]
|
18
|
+
end
|
20
19
|
end
|
21
|
-
end
|
22
20
|
|
23
|
-
|
21
|
+
table
|
22
|
+
end
|
24
23
|
end
|
25
24
|
|
26
25
|
private
|
27
26
|
|
28
27
|
def parse(args)
|
29
|
-
options = {}
|
30
28
|
parser = OptionParser.new do |opts|
|
31
29
|
opts.banner = "Usage: ineedto today"
|
32
30
|
|
33
31
|
opts.on("-h", "--help", "Show help and exit") do
|
34
|
-
@
|
35
|
-
exit(0)
|
32
|
+
@out = opts.help
|
36
33
|
end
|
37
34
|
end
|
38
35
|
parser.parse!(args)
|
39
|
-
|
40
|
-
|
41
|
-
@stderr.puts e.message
|
42
|
-
@stderr.puts parser
|
43
|
-
exit(1)
|
36
|
+
rescue OptionParser::ParseError => e
|
37
|
+
raise CmdError, e.message
|
44
38
|
end
|
45
39
|
end
|
46
40
|
end
|