Class: SecurityReport::CLI

Inherits:
Object
  • Object
show all
Defined in:
lib/security_report/cli.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initializeCLI

Returns a new instance of CLI.



7
8
9
# File 'lib/security_report/cli.rb', line 7

def initialize
  @format = "plain"
end

Instance Attribute Details

#formatObject

Returns the value of attribute format.



5
6
7
# File 'lib/security_report/cli.rb', line 5

def format
  @format
end

Instance Method Details

#helpObject



11
12
13
14
15
16
17
18
19
20
21
22
23
# File 'lib/security_report/cli.rb', line 11

def help
  puts <<~HELPTEXT
    security_report [options] files...

    -h, --help
      Print this message
    --format
      Provide the format: plain or table (default: plain)
    --update
      Update the vulnerability database before running
  HELPTEXT
  exit
end

#reporterObject



25
26
27
28
29
30
31
32
33
34
35
36
37
# File 'lib/security_report/cli.rb', line 25

def reporter
  case format
  when "plain"
    require 'security_report/plain_reporter'
    @reporter = PlainReporter.new
  when "table"
    require 'security_report/table_reporter'
    @reporter = TableReporter.new
  else
    puts "Unknown format '#{format}'"
    exit 1
  end
end

#run(files) ⇒ Object



45
46
47
48
49
# File 'lib/security_report/cli.rb', line 45

def run(files)
  auditor = Auditor.audit(files)
  reporter.report(auditor.results, auditor.skipped)
  exit 1 if auditor.results.any?
end

#updateObject



39
40
41
42
43
# File 'lib/security_report/cli.rb', line 39

def update
  return if Database.update
  puts "Failed updating database!"
  exit 1
end