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
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
|
# File 'lib/intent/todo/manager.rb', line 4
def self.run(args)
if args.empty?
print_help
else
list = ::Todo::List.new(ENV['TODO_TXT'])
case args.first.to_sym
when :list
filtered_list = list.by_not_done
unless args[1].nil?
case args[1][0]
when '@'
filtered_list = filtered_list.by_context(args[1]).by_not_done
when '+'
filtered_list = filtered_list.by_project(args[1])
end
end
filtered_list.by_not_done.each do |task|
puts task
end
when :focus
focused_list = list.by_not_done
unless args[1].nil?
case args[1][0]
when '@'
focused_list = focused_list.by_context(args[1])
when '+'
focused_list = focused_list.by_project(args[1])
end
end
prioritised_list = focused_list.by_priority('A')
if prioritised_list.any?
puts prioritised_list.sample
else
if focused_list.any?
puts focused_list.sample
else
puts "No tasks found."
end
end
when :archive
archive_path = File.dirname(ENV['TODO_TXT'])
done_file = "#{archive_path}/__done__.txt"
todo_file = "#{archive_path}/__todo__.txt"
unless File.exists?(done_file)
puts "Creating new `done.txt` in #{archive_path}."
File.write(done_file, "")
end
done_list = ::Todo::List.new(done_file)
list.by_done.each do |task|
done_list.push(task)
end
File.open(done_file, "w") do |file|
done_list.sort!.by_done.each do |task|
file.puts(task)
end
end
File.open(todo_file, "w") do |file|
list.by_not_done.each do |task|
file.puts(task)
end
end
end
end
end
|