Class: TasksCLI::CLI

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

Instance Method Summary collapse

Instance Method Details

#filter(*args) ⇒ Object



17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
# File 'lib/tasks_cli/cli.rb', line 17

def filter(*args)
  criteria = {}
  args.flatten.each do |arg|
    field, value = arg.split(':', 2)
    criteria[field.to_sym] ||= []
    criteria[field.to_sym] << value
  end
  manager = TaskManager.new
  filtered_tasks = manager.filter_tasks(criteria)
  if filtered_tasks.empty?
    puts Rainbow('No tasks found matching the given criteria.').yellow
  else
    print_tasks(filtered_tasks)
    puts "\nFiltered tasks: #{Rainbow(filtered_tasks.count).green}"
  end
end

#listObject



10
11
12
13
# File 'lib/tasks_cli/cli.rb', line 10

def list
  manager = TaskManager.new
  print_tasks(manager.all_tasks)
end

#update(number, status) ⇒ Object



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

def update(number, status)
  manager = TaskManager.new
  manager.update_status(number, status)
end

#view(number) ⇒ Object



35
36
37
38
39
40
41
42
43
# File 'lib/tasks_cli/cli.rb', line 35

def view(number)
  manager = TaskManager.new
  task = manager.find_task(number)
  if task
    puts task.detailed_view
  else
    puts Rainbow('Task not found').red
  end
end