Class: PuppetLint::Bin
- Inherits:
-
Object
- Object
- PuppetLint::Bin
- Defined in:
- lib/puppet-lint/bin.rb
Instance Method Summary collapse
-
#initialize(args) ⇒ Bin
constructor
A new instance of Bin.
- #run ⇒ Object
Constructor Details
#initialize(args) ⇒ Bin
Returns a new instance of Bin.
4 5 6 |
# File 'lib/puppet-lint/bin.rb', line 4 def initialize(args) @args = args end |
Instance Method Details
#run ⇒ Object
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 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 |
# File 'lib/puppet-lint/bin.rb', line 8 def run help = <<-EOHELP Puppet-lint Basic Command Line Usage: puppet-lint [OPTIONS] [PATH] PATH The path to the Puppet manifest. Options: EOHELP opts = OptionParser.new do |opts| opts. = help opts.on("--version", "Display current version.") do puts "Puppet-lint " + PuppetLint::VERSION return 0 end opts.on('--with-context', 'Show where in the manifest the problem is') do PuppetLint.configuration.with_context = true end opts.on("--with-filename", "Display the filename before the warning") do PuppetLint.configuration.with_filename = true end opts.on("--fail-on-warnings", "Return a non-zero exit status for warnings.") do PuppetLint.configuration.fail_on_warnings = 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("--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('/etc/puppet-lint.rc') if ENV['HOME'] opts.load(File.('~/.puppet-lint.rc')) if opts.load(File.('~/.puppet-lintrc')) $stderr.puts 'Depreciated: Found ~/.puppet-lintrc instead of ~/.puppet-lint.rc' end end opts.load('.puppet-lint.rc') if opts.load('.puppet-lintrc') $stderr.puts 'Depreciated: Read .puppet-lintrc instead of .puppet-lint.rc' end end begin opts.parse!(@args) rescue OptionParser::InvalidOption puts "puppet-lint: #{$!.}" puts "puppet-lint: try 'puppet-lint --help' for more information" return 1 end if @args[0].nil? puts "puppet-lint: no file specified" puts "puppet-lint: try 'puppet-lint --help' for more information" return 1 end begin path = @args[0] if File.directory?(path) path = Dir.glob("#{path}/**/*.pp") else path = @args end return_val = 0 path.each do |f| l = PuppetLint.new l.file = f l.run if l.errors? or (l.warnings? and PuppetLint.configuration.fail_on_warnings) return_val = 1 end end return return_val 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" return 1 end end |