class Bundler::Audit::CLI

The ‘bundle-audit` command.

Public Class Methods

exit_on_failure?() click to toggle source

@note Silence deprecation warnings from Thor.

# File lib/bundler/audit/cli.rb, line 172
def self.exit_on_failure?
  true
end

Public Instance Methods

check(dir=Dir.pwd) click to toggle source
# File lib/bundler/audit/cli.rb, line 49
def check(dir=Dir.pwd)
  unless File.directory?(dir)
    say_error "No such file or directory: #{dir}", :red
    exit 1
  end

  begin
    extend Formats.load(options[:format])
  rescue Formats::FormatNotFound
    say_error "Unknown format: #{options[:format]}", :red
    exit 1
  end

  if !Database.exists?(options[:database])
    download(options[:database])
  elsif options[:update]
    update(options[:database])
  end

  database = Database.new(options[:database])
  scanner  = begin
               Scanner.new(dir,options[:gemfile_lock],database,options[:config])
             rescue Bundler::GemfileLockNotFound => exception
               say exception.message, :red
               exit 1
             end

  report = scanner.report(ignore: options.ignore)

  output = if options[:output]
             File.new(options[:output],'w')
           else
             $stdout
           end

  print_report(report,output)

  output.close if options[:output]

  exit(1) if report.vulnerable?
end
download(path=Database.path) click to toggle source
# File lib/bundler/audit/cli.rb, line 109
def download(path=Database.path)
  if Database.exists?(path)
    say "Database already exists", :yellow
    return
  end

  say("Download ruby-advisory-db ...") unless options.quiet?

  begin
    Database.download(path: path, quiet: options.quiet?)
  rescue Database::DownloadFailed => error
    say error.message, :red
    exit 1
  end

  stats(path) unless options.quiet?
end
stats(path=Database.path) click to toggle source
# File lib/bundler/audit/cli.rb, line 94
def stats(path=Database.path)
  database = Database.new(path)

  puts "ruby-advisory-db:"
  puts "  advisories:\t#{database.size} advisories"
  puts "  last updated:\t#{database.last_updated_at}"

  if (commit_id = database.commit_id)
    puts "  commit:\t#{commit_id}"
  end
end
update(path=Database.path) click to toggle source
# File lib/bundler/audit/cli.rb, line 130
def update(path=Database.path)
  unless Database.exists?(path)
    download(path)
    return
  end

  say("Updating ruby-advisory-db ...") unless options.quiet?

  database = Database.new(path)

  begin
    case database.update!(quiet: options.quiet?)
    when true
      say("Updated ruby-advisory-db", :green) unless options.quiet?
    when nil
      if Bundler.git_present?
        unless options.quiet?
          say "Skipping update, ruby-advisory-db is not a git repository", :yellow
        end
      else
        say_error "Git is not installed!", :red
        exit 1
      end
    end
  rescue Database::UpdateFailed => error
    say error.message, :red
    exit 1
  end

  stats(path) unless options.quiet?
end
version() click to toggle source
# File lib/bundler/audit/cli.rb, line 163
def version
  puts "bundler-audit #{VERSION}"
end

Protected Instance Methods

print_report(report) click to toggle source

@abstract