-
Notifications
You must be signed in to change notification settings - Fork 0
/
todo.rb
42 lines (31 loc) · 989 Bytes
/
todo.rb
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
require_relative 'config/application'
require_relative 'app/controllers/task_controller'
require_relative 'app/models/task'
require "byebug"
# puts "Put your application code in #{File.expand_path(__FILE__)}"
def list
list = TaskController.list
puts "TODO list:"
list.each do |task|
if task[:completed] == 1
puts "#{task[:id]}. #{task[:task_name]} --- DONE"
elsif task[:completed] == 0
puts "#{task[:id]}. #{task[:task_name]}"
end
end
end
input = ARGV
if input[0] == "list"
list
elsif input[0] == "add"
TaskController.add(input[1..-1].join(" "))
puts "Appended #{input[1..-1].join(" ")} to your TODO list..."
elsif input[0] == "delete"
puts "Deleted #{TaskController.task_name(input[1].to_i)} from your TODO list..."
TaskController.delete(input[1].to_i)
elsif input[0] == "complete"
TaskController.update(input[1].to_i)
list
else
"Command unidentified. Please input list, add, delete or complete."
end