Class: PuppetCheck::CLI

Inherits:
Object
  • Object
show all
Defined in:
lib/puppet-check/cli.rb

Overview

the command line interface for PuppetCheck

Class Method Summary collapse

Class Method Details

.parse(args) ⇒ Object

parse the user arguments



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
# File 'lib/puppet-check/cli.rb', line 17

def self.parse(args)
  # show help message if no args specified
  args = %w[-h] if args.empty?

  # initialize settings hash
  settings = {}

  opt_parser = OptionParser.new do |opts|
    # usage
    opts.banner = 'usage: puppet-check [options] paths'

    # base options
    opts.on('--version', 'Display the current version.') do
      puts 'puppet-check 1.6.1'
      exit 0
    end

    # bool options
    opts.on('-f', '--future', 'Enable future parser') { settings[:future_parser] = true }
    opts.on('--fail-on-warnings', 'Fail on warnings') { settings[:fail_on_warnings] = true }
    opts.on('-s', '--style', 'Enable style checks') { settings[:style_check] = true }
    opts.on('--smoke', 'Enable smoke testing') { settings[:smoke_check] = true }
    opts.on('-r', '--regression', 'Enable regression testing (in progress, do not use)') { settings[:regression_check] = true }

    # ssl key options for eyaml checks
    opts.on('--public cert.pem', String, 'Public key for EYAML checks') { |arg| settings[:public] = arg }
    opts.on('--private cert.pem', String, 'Private key for EYAML checks') { |arg| settings[:private] = arg }

    # formatting options
    opts.on('-o', '--output format', String, 'Format for results output (default is text): text, json, or yaml') { |arg| settings[:output_format] = arg }

    # octocatalog-diff options
    opts.on('--octoconfig config_file', String, 'Octocatalog-diff configuration file to use') { |arg| settings[:octoconfig] = arg }
    opts.on('-n', '--octonodes node1.example.com,node2.example.com', Array, 'Octocatalog-diff nodes to test catalog on') { |arg| settings[:octonodes] = arg }

    # arguments to style checkers
    opts.on('--puppet-lint arg_one,arg_two', Array, 'Arguments for PuppetLint ignored checks') do |puppetlint_args|
      settings[:puppetlint_args] = puppetlint_args.map { |arg| "--#{arg}" }
    end
    opts.on('-c', '--config file', String, 'Load PuppetLint options from file') do |file|
      settings[:puppetlint_args] = File.read(file).split("\n")
    end
    opts.on('--rubocop arg_one,arg_two', String, 'Arguments for Rubocop disabled cops') { |arg| settings[:rubocop_args] = ['--except', arg] }
  end

  # remove atched args and return settings
  opt_parser.parse!(args)
  settings
end

.run(args) ⇒ Object

run method for the cli



7
8
9
10
11
12
13
14
# File 'lib/puppet-check/cli.rb', line 7

def self.run(args)
  # gather the user arguments
  settings = parse(args)
  raise 'puppet-check: no paths specified; try using --help' if args.empty?

  # run PuppetCheck with specified paths
  PuppetCheck.new.run(settings, args)
end