Skip to content

Commit

Permalink
Fixed #45 - Added selective error level reporting
Browse files Browse the repository at this point in the history
Added a new command-line option `--error-level` with
values of:

* warning - only return warning messages
* error - only return error messages
* all - the default return all messages
  • Loading branch information
jamtur01 committed Dec 27, 2011
1 parent 8f5b1e7 commit 25bf61f
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 4 deletions.
7 changes: 6 additions & 1 deletion bin/puppet-lint
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,11 @@ opts = OptionParser.new do |opts|
exit 0
end

options[:error_level] = :all
opts.on("--error-level LEVEL", [:all, :warning, :error], "The level of error to return (warning, error, all).") do |el|
options[:error_level] = el
end

opts.on("--fail-on-warnings", "Return a non-zero exit status for warnings.") do
options[:fail_on_warnings] = true
end
Expand All @@ -47,7 +52,7 @@ if ARGV[0].nil?
end

begin
l = PuppetLint.new
l = PuppetLint.new(options)
l.file = ARGV[0]
l.run

Expand Down
14 changes: 11 additions & 3 deletions lib/puppet-lint.rb
Original file line number Diff line number Diff line change
Expand Up @@ -17,10 +17,11 @@ class PuppetLint

attr_reader :code, :file

def initialize
def initialize(options)
@data = nil
@errors = 0
@warnings = 0
@error_level = options[:error_level]
end

def file=(path)
Expand Down Expand Up @@ -58,8 +59,15 @@ def run

PuppetLint::CheckPlugin.repository.each do |plugin|
problems = plugin.new.run(@data)
problems[:errors].each { |error| report :errors, error }
problems[:warnings].each { |warning| report :warnings, warning }
case @error_level
when :warning
problems[:warnings].each { |warning| report :warnings, warning }
when :error
problems[:errors].each { |error| report :errors, error }
else
problems[:warnings].each { |warning| report :warnings, warning }
problems[:errors].each { |error| report :errors, error }
end
end
end
end
Expand Down

0 comments on commit 25bf61f

Please sign in to comment.