Class: Abide::CLI::CemGenerateCoverageReport
- Inherits:
-
AbideCommand
- Object
- CmdParse::Command
- AbideCommand
- Abide::CLI::CemGenerateCoverageReport
- 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
- #execute ⇒ Object
-
#initialize ⇒ CemGenerateCoverageReport
constructor
A new instance of CemGenerateCoverageReport.
Methods included from AbideDevUtils::Config
config_section, #config_section, fetch, #fetch, to_h, #to_h
Constructor Details
#initialize ⇒ CemGenerateCoverageReport
Returns a new instance of CemGenerateCoverageReport.
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/abide_dev_utils/cli/cem.rb', line 42 def initialize super(CMD_NAME, CMD_SHORT, CMD_LONG, takes_commands: false) .on('-o [FILE]', '--out-file [FILE]', 'Path to save the coverage report') { |f| @data[:file] = f } .on('-f [FORMAT]', '--format [FORMAT]', 'The format to output the report in (hash, json, yaml)') do |f| @data[:format] = f end .on('-B [BENCHMARK]', '--benchmark [BENCHMARK]', 'Specify the benchmark to show coverage for') do |x| @data[:benchmark] = x end .on('-P [PROFILE]', '--profile [PROFILE]', 'Specifiy the profile to show coverage for') do |x| @data[:profile] = x end .on('-L [LEVEL]', '--level [LEVEL]', 'Specify the level to show coverage for') do |l| @data[:profile] = l end .on('-I', '--ignore-benchmark-errors', 'Ignores errors while generating benchmark reports') do @data[:ignore_all] = true end .on('-X [XCCDF_DIR]', '--xccdf-dir [XCCDF_DIR]', 'If specified, the coverage report will be correlated with info from the benchmark XCCDF files') do |d| @data[:xccdf_dir] = d end .on('-v', '--verbose', 'Will output the report to the console') { @data[:verbose] = true } .on('-q', '--quiet', 'Will not output anything to the console') { @data[:quiet] = true } end |
Instance Method Details
#execute ⇒ Object
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 |
# File 'lib/abide_dev_utils/cli/cem.rb', line 67 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 generate_opts = { benchmark: @data[:benchmark], profile: @data[:profile], level: @data[:level], ignore_benchmark_errors: @data.fetch(:ignore_all, false), xccdf_dir: @data[:xccdf_dir], } AbideDevUtils::Output.simple('Generating coverage report...') unless quiet coverage = AbideDevUtils::CEM::Generate::CoverageReport.generate(format_func: :to_h, opts: generate_opts) 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 |