Class: Abide::CLI::CemGenerateCoverageReport

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

Constant Summary collapse

CMD_NAME =
'coverage-report'
CMD_SHORT =
'Generates control coverage report'
CMD_LONG =
<<-EOLC.chomp
Generates report of resources that are associated with controls in mapping data. This command must
be run from a module directory.
EOLC

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

#initializeCemGenerateCoverageReport

Returns a new instance of CemGenerateCoverageReport.



41
42
43
44
45
46
47
48
49
50
51
52
# File 'lib/abide_dev_utils/cli/cem.rb', line 41

def initialize
  super(CMD_NAME, CMD_SHORT, CMD_LONG, takes_commands: false)
  options.on('-o [FILE]', '--out-file [FILE]', 'Path to save the coverage report') { |f| @data[:file] = f }
  options.on('-f [FORMAT]', '--format [FORMAT]', 'The format to output the report in (hash, json, yaml)') do |f|
    @data[:format] = f
  end
  options.on('-I', '--ignore-benchmark-errors', 'Ignores errors while generating benchmark reports') do
    @data[:ignore_all] = true
  end
  options.on('-v', '--verbose', 'Will output the report to the console') { @data[:verbose] = true }
  options.on('-q', '--quiet', 'Will not output anything to the console') { @data[:quiet] = true }
end

Instance Method Details

#executeObject



54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
# File 'lib/abide_dev_utils/cli/cem.rb', line 54

def execute
  file_name = @data.fetch(:file, 'coverage_report')
  out_format = @data.fetch(:format, 'yaml')
  quiet = @data.fetch(:quiet, false)
  console = @data.fetch(:verbose, false) && !quiet
  ignore_all = @data.fetch(:ignore_all, false)
  AbideDevUtils::Output.simple('Generating coverage report...') unless quiet
  coverage = AbideDevUtils::CEM::CoverageReport.basic_coverage(format_func: :to_h, ignore_benchmark_errors: ignore_all)
  AbideDevUtils::Output.simple("Saving coverage report to #{file_name}...")
  case out_format
  when /yaml/i
    AbideDevUtils::Output.yaml(coverage, console: console, file: file_name)
  when /json/i
    AbideDevUtils::Output.json(coverage, console: console, file: file_name)
  else
    File.open(file_name, 'w') do |f|
      AbideDevUtils::Output.simple(coverage.to_s, stream: f)
    end
  end
end