Class: PuppetLint::OptParser
- Inherits:
-
Object
- Object
- PuppetLint::OptParser
- Defined in:
- lib/puppet-lint/optparser.rb
Overview
Public: Contains the puppet-lint option parser so that it can be used easily in multiple places.
Constant Summary collapse
- HELP_TEXT =
<<-EOF puppet-lint Basic Command Line Usage: puppet-lint [OPTIONS] PATH PATH The path to the Puppet manifest. Option: EOF
Class Method Summary collapse
-
.build ⇒ Object
Public: Initialise a new puppet-lint OptionParser.
Class Method Details
.build ⇒ Object
Public: Initialise a new puppet-lint OptionParser.
Returns an OptionParser object.
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 123 124 125 126 127 |
# File 'lib/puppet-lint/optparser.rb', line 20 def self.build OptionParser.new do |opts| opts. = HELP_TEXT opts.on('--version', 'Display the current version.') do PuppetLint.configuration.display_version = true end opts.on('-c', '--config FILE', 'Load puppet-lint options from file.') do |file| opts.load(file) 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 or all).') do |el| PuppetLint.configuration.error_level = el end opts.on('--show-ignored', 'Show problems that have been ignored by control comments') do PuppetLint.configuration.show_ignored = true end opts.on('--relative', 'Compare module layout relative to the module root') do PuppetLint.configuration.relative = true end opts.on('-l', '--load FILE', 'Load a file containing custom puppet-lint checks.') do |f| load f end opts.on('--load-from-puppet MODULEPATH', 'Load plugins from the given Puppet module path.') do |path| path.split(':').each do |p| Dir["#{p}/*/lib/puppet-lint/plugins/*.rb"].each do |file| load file end end end opts.on('-f', '--fix', 'Attempt to automatically fix errors') do PuppetLint.configuration.fix = 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 to puppet-lint.', '%{fullpath} - Expanded path to the file.', '%{line} - Line number.', '%{column} - Column number.', '%{kind} - The kind of message (warning, error).', '%{KIND} - Uppercase version of %{kind}.', '%{check} - The name of the check.', '%{message} - The message.' ) do |format| PuppetLint.configuration.log_format = format end opts.on('--json', 'Log output as JSON') do PuppetLint.configuration.json = true end opts.separator '' opts.separator ' Checks:' opts.on('--only-checks CHECKS', 'A comma separated list of checks that should be run') do |checks| enable_checks = checks.split(',').map(&:to_sym) (PuppetLint.configuration.checks).each do |check| if enable_checks.include? check PuppetLint.configuration.send("enable_#{check}") else PuppetLint.configuration.send("disable_#{check}") end end end PuppetLint.configuration.checks.each do |check| opts.on("--no-#{check}-check", "Skip the #{check} check.") do PuppetLint.configuration.send("disable_#{check}") end unless PuppetLint.configuration.send("#{check}_enabled?") opts.on("--#{check}-check", "Enable the #{check} check.") do PuppetLint.configuration.send("enable_#{check}") end end end opts.load('/etc/puppet-lint.rc') begin opts.load(File.('~/.puppet-lint.rc')) if ENV['HOME'] rescue Errno::EACCES # silently skip loading this file if HOME is set to a directory that # the user doesn't have read access to. end opts.load('.puppet-lint.rc') end end |