lib/todidnt.rb in todidnt-0.0.0 vs lib/todidnt.rb in todidnt-0.1.0
- old
+ new
@@ -1,25 +1,69 @@
-require_relative 'todidnt/git_repo'
-require_relative 'todidnt/git_command'
-require_relative 'todidnt/todo_line'
+require 'todidnt/git_repo'
+require 'todidnt/git_command'
+require 'todidnt/todo_line'
+require 'chronic'
+
module Todidnt
- class Runner
- def self.start(options)
+ class CLI
+ VALID_COMMANDS = %w{all overdue}
+
+ def self.run(command, options)
+ if command && VALID_COMMANDS.include?(command)
+ self.send(command, options)
+ elsif command
+ $stderr.puts("Sorry, `#{command}` is not a valid command.")
+ exit
+ else
+ $stderr.puts("You must specify a command! Try `todidnt all`.")
+ end
+ end
+
+ def self.all(options)
+ all_lines = self.all_lines(options)
+
+ puts "\nResults:"
+ all_lines.sort_by do |line|
+ line.timestamp
+ end.each do |line|
+ puts line.pretty
+ end
+ end
+
+ def self.overdue(options)
+ date = Chronic.parse(options[:date] || 'now', :context => :past)
+ if date.nil?
+ $stderr.puts("Invalid date passed: #{options[:date]}")
+ exit
+ else
+ puts "Finding overdue TODOs (created before #{date.strftime('%F')})..."
+ end
+
+ all_lines = self.all_lines(options)
+
+ puts "\nResults:"
+ all_lines.sort_by do |line|
+ line.timestamp
+ end.select do |line|
+ line.timestamp < date.to_i
+ end.each do |line|
+ puts line.pretty
+ end
+ end
+
+ def self.all_lines(options)
GitRepo.new(options[:path]).run do |path|
puts "Running in #{path || 'current directory'}..."
lines = TodoLine.all(["TODO"])
puts "Found #{lines.count} TODOs. Blaming..."
lines.each_with_index do |todo, i|
todo.populate_blame
$stdout.write "\rBlamed: #{i}/#{lines.count}"
end
- puts "\nResults:"
- lines.each do |line|
- puts line.pretty
- end
+ lines
end
end
end
end