Class: Abide::CLI::SceGenerateCoverageReport
- Inherits:
-
AbideCommand
- Object
- CmdParse::Command
- AbideCommand
- Abide::CLI::SceGenerateCoverageReport
- Defined in:
- lib/abide_dev_utils/cli/sce.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 ⇒ SceGenerateCoverageReport
constructor
A new instance of SceGenerateCoverageReport.
Methods inherited from AbideCommand
Methods included from AbideDevUtils::Config
config_section, #config_section, fetch, #fetch, to_h, #to_h
Constructor Details
#initialize ⇒ SceGenerateCoverageReport
Returns a new instance of SceGenerateCoverageReport.
42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 |
# File 'lib/abide_dev_utils/cli/sce.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[:level] = l end .on('-I', '--no-ignore-benchmark-errors', 'Does not ignore errors while generating benchmark reports') do @data[:ignore_benchmark_errors] = false 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
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 |
# File 'lib/abide_dev_utils/cli/sce.rb', line 64 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 = @data.fetch(:ignore_benchmark_errors, true) generate_opts = { benchmark: @data[:benchmark], profile: @data[:profile], level: @data[:level], ignore_benchmark_errors: ignore } AbideDevUtils::Output.simple('Generating coverage report...') unless quiet coverage = AbideDevUtils::Sce::Generate::CoverageReport.generate(format_func: :to_h, opts: generate_opts) raise 'No coverage data found' if coverage.empty? 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 |