Class: KhoinguyenEhTodoList::CLI

Inherits:
Thor
  • Object
show all
Defined in:
lib/khoinguyen_eh_todo_list/cli.rb

Overview

Command line interface for the todo list

Constant Summary collapse

TASKS_FILE =
"tasks.yml"

Instance Method Summary collapse

Constructor Details

#initialize(args = [], options = {}, config = {}) ⇒ CLI

Returns a new instance of CLI.



15
16
17
18
19
# File 'lib/khoinguyen_eh_todo_list/cli.rb', line 15

def initialize(args = [], options = {}, config = {})
  super(args, options, config)
  @tasks = load_tasks
  @caretaker = Caretaker.new
end

Instance Method Details

#add(title) ⇒ Object



23
24
25
# File 'lib/khoinguyen_eh_todo_list/cli.rb', line 23

def add(title)
  execute_action(KhoinguyenEhTodoList::Services::AddTaskService, title)
end

#clear ⇒ Object



35
36
37
# File 'lib/khoinguyen_eh_todo_list/cli.rb', line 35

def clear
  execute_action(KhoinguyenEhTodoList::Services::ClearTasksService)
end

#history ⇒ Object



71
72
73
74
# File 'lib/khoinguyen_eh_todo_list/cli.rb', line 71

def history
  puts "Undoable actions: #{@caretaker.undo_history_count}"
  puts "Redoable actions: #{@caretaker.redo_history_count}"
end

#list ⇒ Object



65
66
67
# File 'lib/khoinguyen_eh_todo_list/cli.rb', line 65

def list
  @tasks.each_with_index { |task, index| puts "#{index + 1}. #{task}" }
end

#move(from, to) ⇒ Object



41
42
43
# File 'lib/khoinguyen_eh_todo_list/cli.rb', line 41

def move(from, to)
  execute_action(KhoinguyenEhTodoList::Services::MoveTaskService, from, to)
end

#redo ⇒ Object



59
60
61
# File 'lib/khoinguyen_eh_todo_list/cli.rb', line 59

def redo
  execute_action(KhoinguyenEhTodoList::Services::UndoRedoService, @caretaker, :redo)
end

#remove(index) ⇒ Object



29
30
31
# File 'lib/khoinguyen_eh_todo_list/cli.rb', line 29

def remove(index)
  execute_action(KhoinguyenEhTodoList::Services::RemoveTaskService, index)
end

#toggle(index) ⇒ Object



47
48
49
# File 'lib/khoinguyen_eh_todo_list/cli.rb', line 47

def toggle(index)
  execute_action(KhoinguyenEhTodoList::Services::ToggleCompletionService, index)
end

#undo ⇒ Object



53
54
55
# File 'lib/khoinguyen_eh_todo_list/cli.rb', line 53

def undo
  execute_action(KhoinguyenEhTodoList::Services::UndoRedoService, @caretaker, :undo)
end