Class: Brew::Vulns::CLI

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

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(args) ⇒ CLI

Returns a new instance of CLI.



10
11
12
13
14
15
16
# File 'lib/brew/vulns/cli.rb', line 10

def initialize(args)
  @args = args
  @formula_filter = args.first unless args.first&.start_with?("-")
  @include_deps = args.include?("--deps") || args.include?("-d")
  @json_output = args.include?("--json") || args.include?("-j")
  @help = args.include?("--help") || args.include?("-h")
end

Class Method Details

.run(args) ⇒ Object



6
7
8
# File 'lib/brew/vulns/cli.rb', line 6

def self.run(args)
  new(args).run
end

Instance Method Details

#runObject



18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
# File 'lib/brew/vulns/cli.rb', line 18

def run
  if @help
    print_help
    return 0
  end

  formulae = load_formulae
  if formulae.empty?
    puts "No installed formulae found."
    return 0
  end

  queryable = formulae.select(&:github?).select(&:tag)
  skipped = formulae.size - queryable.size

  unless @json_output
    puts "Checking #{queryable.size} packages for vulnerabilities..."
    puts "(#{skipped} packages skipped - no GitHub source URL)" if skipped > 0
    puts
  end

  results = scan_vulnerabilities(queryable)
  output_results(results, formulae)
rescue OsvClient::Error => e
  $stderr.puts "Error querying OSV: #{e.message}"
  1
rescue Error => e
  $stderr.puts "Error: #{e.message}"
  1
rescue JSON::ParserError => e
  $stderr.puts "Error parsing brew output: #{e.message}"
  1
end