Skip to content

Commit

Permalink
Removed result output duplication
Browse files Browse the repository at this point in the history
Now both the roodi executable and the rake task have pretty colours.

Solving issue #20
  • Loading branch information
evjan committed Nov 9, 2013
1 parent dc17b2c commit a1acc5f
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 22 deletions.
6 changes: 0 additions & 6 deletions bin/roodi
Expand Up @@ -10,12 +10,6 @@ config_param = ARGV.detect {|arg| arg =~ /-config=.*/}
runner.config = config_param.split("=")[1] if config_param
ARGV.delete config_param

puts "\nRunning Roodi checks"

runner.start(ARGV)
runner.errors.each {|error| puts error}

puts "\nChecked #{runner.files_checked} files"
puts "Found #{runner.errors.size} errors"

exit runner.errors.size
16 changes: 16 additions & 0 deletions lib/roodi/core/runner.rb
Expand Up @@ -19,12 +19,28 @@ def initialize(*checks)
end

def start(paths)
puts "\nRunning Roodi checks"

paths = ['.'] if paths == []
all_files = collect_files(paths)
@files_checked = all_files.count
all_files.each do |path|
check_file(path)
end

output_result(errors, @files_checked)
end

def output_result(errors, files_checked)
errors.each {|error| puts "\e[31m#{error}\e[0m"}

puts "\nChecked #{files_checked} files"
result = "Found #{errors.size} errors."
if errors.empty?
puts "\e[32m#{result}\e[0m"
else
raise "\e[31m#{result}\e[0m"
end
end

def collect_files(paths)
Expand Down
16 changes: 0 additions & 16 deletions lib/roodi_task.rb
Expand Up @@ -21,28 +21,12 @@ def initialize name = :roodi, patterns = nil, config = nil
def define
desc "Run Roodi against all source files"
task name do
puts "\nRunning Roodi checks"

runner = Roodi::Core::Runner.new

runner.config = config if config

runner.start(@patterns)

output_result(runner.errors, runner.files_checked)
end
self
end

def output_result(errors, files_checked)
errors.each {|error| puts "\e[31m#{error}\e[0m"}

puts "\nChecked #{files_checked} files"
result = "Found #{errors.size} errors."
if errors.empty?
puts "\e[32m#{result}\e[0m"
else
raise "\e[31m#{result}\e[0m"
end
end
end

0 comments on commit a1acc5f

Please sign in to comment.