Class: Abide::CLI::PuppetCoverageCommand

Inherits:
AbideCommand
  • Object
show all
Defined in:
lib/abide_dev_utils/cli/puppet.rb

Constant Summary collapse

CMD_NAME =
'coverage'
CMD_SHORT =
'Generates control coverage report'
CMD_LONG =
'Generates report of valid Puppet classes that match with Hiera controls'
CMD_CLASS_DIR =
'Directory that holds Puppet manifests'
CMD_HIERA_FILE =
'Hiera file generated from an XCCDF'

Constants included from AbideDevUtils::Config

AbideDevUtils::Config::DEFAULT_PATH

Instance Method Summary collapse

Methods included from AbideDevUtils::Config

config_section, #config_section, fetch, #fetch, to_h, #to_h

Constructor Details

#initializePuppetCoverageCommand

Returns a new instance of PuppetCoverageCommand.



30
31
32
33
34
35
# File 'lib/abide_dev_utils/cli/puppet.rb', line 30

def initialize
  super(CMD_NAME, CMD_SHORT, CMD_LONG, takes_commands: false)
  argument_desc(CLASS_DIR: CMD_CLASS_DIR, HIERA_FILE: CMD_HIERA_FILE)
  options.on('-o [FILE]', '--out-file [FILE]', 'Path to save the coverage report') { |f| @data[:file] = f }
  options.on('-p [PROFILE]', '--profile [PROFILE]', 'Generate only for profile') { |p| @data[:profile] = p }
end

Instance Method Details

#execute(class_dir, hiera_file) ⇒ Object



46
47
48
49
50
51
52
53
54
55
56
57
58
59
# File 'lib/abide_dev_utils/cli/puppet.rb', line 46

def execute(class_dir, hiera_file)
  require 'abide_dev_utils/ppt/coverage'
  Abide::CLI::VALIDATE.directory(class_dir)
  Abide::CLI::VALIDATE.file(hiera_file)
  coverage = AbideDevUtils::Ppt.generate_coverage_report(class_dir, hiera_file, @data[:profile])
  coverage.each do |k, v|
    next if k.match?(/classes|benchmark/)

    Abide::CLI::OUTPUT.simple("#{k} coverage: #{v[:coverage]}%")
  end
  return if @data[:file].nil?

  Abide::CLI::OUTPUT.json(coverage, file: @data[:file])
end

#help_argumentsObject



37
38
39
40
41
42
43
44
# File 'lib/abide_dev_utils/cli/puppet.rb', line 37

def help_arguments
  <<~ARGHELP
    Arguments:
        CLASS_DIR        #{CMD_CLASS_DIR}
        HIERA_FILE       #{CMD_HIERA_FILE}

  ARGHELP
end