Class: Bundler::Audit::Fix::CLI

Inherits:
Thor
  • Object
show all
Includes:
Thor::Actions
Defined in:
lib/bundler/audit/fix/cli.rb

Overview

The ‘bundle-audit-fix` command.

Instance Method Summary collapse

Instance Method Details

#update(dir = Dir.pwd) ⇒ Object



46
47
48
49
50
51
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
80
81
82
83
# File 'lib/bundler/audit/fix/cli.rb', line 46

def update(dir = Dir.pwd)
  unless File.directory?(dir)
    say_error "No such file or directory: #{dir}", :red
    exit 1
  end

  if !Database.exists?(options[:database])
    Bundler::Audit::CLI.new.invoke(:download, options[:database])
  elsif options[:update]
    Bundler::Audit::CLI.new.invoke(:update, options[:database])
  end

  gemfile      = options[:gemfile_lock].sub(/\.lock$/, '')
  gemfile_path = File.join(dir, gemfile)

  # for https://github.com/rubygems/bundler/blob/35be6d9a603084f719fec4f4028c18860def07f6/lib/bundler/shared_helpers.rb#L229
  ENV['BUNDLE_GEMFILE'] = gemfile_path

  database = Database.new(options[:database])
  begin
    scanner = Scanner.new(dir, options[:gemfile_lock], database, options[:config])
    scanner.scan

    report = scanner.report(ignore: options.ignore)
    unless report.vulnerable?
      say 'Nothing to do, exiting.', :green
      exit 0
    end

    patcher = Patcher.new(dir, report, options[:gemfile_lock], options[:config])
    gems_to_update = patcher.patch

    Bundler::CLI::Update.new({ gemfile: gemfile_path }, gems_to_update).run
  rescue Bundler::GemfileNotFound, Bundler::GemfileLockNotFound => e
    say e.message, :red
    exit 1
  end
end

#versionObject



86
87
88
# File 'lib/bundler/audit/fix/cli.rb', line 86

def version
  puts Fix::VERSION
end