Class: DependencySpy::CLI

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

Constant Summary collapse

FORMATTERS =
[
  DependencySpy::Formatters::Text,
  DependencySpy::Formatters::Json,
  DependencySpy::Formatters::Yaml
]

Instance Method Summary collapse

Instance Method Details

#checkObject



52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
# File 'lib/dependency_spy/cli.rb', line 52

def check
  manifests = API.check(options['path'], options['files'], options['platform'], options['database-path'], options['offline'])

  formatted_output = if (options['formatter'] == 'text') && !options['output-path'] && options['with-color']
                       DependencySpy::Formatters::Text.format(manifests, options['severity-threshold'])
                     else
                       FORMATTERS
                         .find { |f| f.name.split('::').last.downcase == options['formatter'] }
                         .format(manifests)
                     end

  if options['output-path']
    DependencySpy::Outputs::FileSystem.write(options['output-path'], formatted_output)
  else
    DependencySpy::Outputs::StdOut.write(formatted_output)
  end

  has_vulnerabilities =
    manifests.any? do |manifest|
      manifest[:dependencies]&.any? do |dependency|
        dependency[:vulnerabilities]&.any? do |vuln|
          DependencySpy::Helper.severity_above_threshold?(vuln.severity, options['severity-threshold'])
        end
      end
    end

  exit(1) if has_vulnerabilities
end

#updateObject



84
85
86
# File 'lib/dependency_spy/cli.rb', line 84

def update
  API.update(options['vuln-db-path'])
end