class Bundler::Audit::CLI

def check(dir=Dir.pwd)

def check(dir=Dir.pwd)
  unless File.directory?(dir)
    say "No such file or directory: #{dir}", :red
    exit 1
  end
  begin
    extend Formats.load(options[:format])
  rescue Formats::FormatNotFound
    say "Unknown format: #{options[:format]}", :red
    exit 1
  end
  if !Database.exists?
    download(options[:database])
  elsif options[:update]
    update(options[:database])
  end
  database = Database.new(options[:database])
  scanner  = begin
               Scanner.new(dir,options[:gemfile_lock],database)
             rescue Bundler::GemfileLockNotFound => exception
               say exception.message, :red
               exit 1
             end
  report   = scanner.report(:ignore => options.ignore)
  output = if options[:output] then File.new(options[:output],'w')
           else                     $stdout
           end
  print_report(report,output)
  output.close if options[:output]
  exit(1) if report.vulnerable?
end

def download(path=Database.path)

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

def print_report(report)

Other tags:
    Abstract: -
def print_report(report)
  raise(NotImplementedError,"#{self.class}##{__method__} not defined")
end

def say(message="", color=nil)

def say(message="", color=nil)
  color = nil unless $stdout.tty?
  super(message.to_s, color)
end

def stats(path=Database.path)

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}"
end

def update(path=Database.path)

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)
  case database.update!(quiet: options.quiet?)
  when true
    say("Updated ruby-advisory-db", :green) unless options.quiet?
  when false
    say "Failed updating ruby-advisory-db!", :red
    exit 1
  when nil
    unless Bundler.git_present?
      say "Git is not installed!", :red
      exit 1
    end
    say "Skipping update", :yellow
  end
  stats(path) unless options.quiet?
end

def version

def version
  database = Database.new
  puts "#{File.basename($0)} #{VERSION} (advisories: #{database.size})"
end