]> git.nbdom.net Git - nb.git/commitdiff
puppet-lint
authorNicolas Boisselier <nicolas.boisselier@gmail.com>
Mon, 23 Feb 2015 22:58:26 +0000 (23:58 +0100)
committerNicolas Boisselier <nicolas.boisselier@gmail.com>
Mon, 23 Feb 2015 22:58:26 +0000 (23:58 +0100)
bin/puppet-lint [new file with mode: 0755]

diff --git a/bin/puppet-lint b/bin/puppet-lint
new file mode 100755 (executable)
index 0000000..812b74a
--- /dev/null
@@ -0,0 +1,102 @@
+#!/usr/bin/ruby1.8
+
+$:.unshift File.join(File.dirname(__FILE__), *%w[.. lib])
+
+help = <<HELP
+Puppet-lint
+
+Basic Command Line Usage:
+  puppet-lint [OPTIONS] [PATH]
+
+        PATH                         The path to the Puppet manifest.
+
+Options:
+HELP
+
+require 'optparse'
+require 'puppet-lint'
+
+opts = OptionParser.new do |opts|
+  opts.banner = help
+
+  opts.on("--version", "Display current version.") do
+    puts "Puppet-lint " + PuppetLint::VERSION
+    exit 0
+  end
+
+  opts.on("--with-filename", "Display the filename before the warning") do
+    PuppetLint.configuration.with_filename = true
+  end
+
+  opts.on("--error-level LEVEL", [:all, :warning, :error], "The level of error to return.", "(warning, error, all)") do |el|
+    PuppetLint.configuration.error_level = el
+  end
+
+  opts.on("--fail-on-warnings", "Return a non-zero exit status for warnings.") do
+    PuppetLint.configuration.fail_on_warnings = true
+  end
+
+  opts.on("--log-format FORMAT",
+    "Change the log format.", "Overrides --with-filename.",
+    "The following placeholders can be used:",
+    "%{filename}   - Filename without path.",
+    "%{path}       - Path as provided.",
+    "%{fullpath}   - Full path.",
+    "%{linenumber} - Line number.",
+    "%{kind}       - The kind of message.",
+    "              - (warning, error)",
+    "%{KIND}       - Uppercase version of %{kind}",
+    "%{check}      - Name of the check.",
+    "%{message}    - The message."
+  ) do |format|
+    PuppetLint.configuration.log_format = format
+  end
+
+  opts.separator ""
+  opts.separator "    Disable checks:"
+
+  PuppetLint.configuration.checks.each do |check|
+    opts.on("--no-#{check}-check", "Skip the #{check} check") do
+      PuppetLint.configuration.send("disable_#{check}")
+    end
+  end
+
+  opts.load(File.expand_path("~/.puppet-lintrc")) unless opts.load(".puppet-lintrc")
+end
+
+begin
+  opts.parse!
+rescue OptionParser::InvalidOption
+  puts "puppet-lint: #{$!.message}"
+  puts "puppet-lint: try 'puppet-lint --help' for more information"
+  exit
+end
+
+if ARGV[0].nil?
+  puts "puppet-lint: no file specified"
+  puts "puppet-lint: try 'puppet-lint --help' for more information"
+  exit
+end
+
+begin
+  path = ARGV[0]
+  if File.directory?(path)
+    Dir.chdir(path)
+    path = Dir.glob('**/*.pp')
+  end
+
+  path.each do |f|
+    l = PuppetLint.new
+    l.file = f
+    l.run
+    if l.errors? or (l.warnings? and PuppetLint.configuration.fail_on_warnings)
+      exit 1
+    end
+  end
+
+rescue PuppetLint::NoCodeError
+  puts "puppet-lint: no file specified or specified file does not exist"
+  puts "puppet-lint: try 'puppet-lint --help' for more information"
+  exit
+end
+