Class: Gitodo::ListTodoCommand

Inherits:
Slayer::Command
  • Object
show all
Defined in:
lib/gitodo/commands/list_todo_command.rb

Instance Method Summary collapse

Instance Method Details

#call(list_form: nil) ⇒ Object



3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
# File 'lib/gitodo/commands/list_todo_command.rb', line 3

def call(list_form: nil)
  fail! message: "Not in a git repository." unless GitService.is_git_repo

  branch = GitService.current_branch
  todo_service = TodoService.new

  matching = list_form ? list_form.todo_indexes : nil

  if matching
    validated = todo_service.validate_todo_indexes(branch: branch, todo_indexes: matching)
    fail! message: "One of the todo indexes was not valid." unless validated
  end

  todos = todo_service.get_todos(branch: branch, todo_indexes: matching)

  pass! value: OpenStruct.new(todos: todos, branch: branch)
end