module Dependagrab

Constants

VERSION

Public Class Methods

run(options) click to toggle source
# File lib/dependagrab.rb, line 13
def self.run(options)
  result = Dependagrab::GithubClient.new(options).grab

  if options[:output]
    begin
      output_file = FileWriter.new(options[:output]).write!(result[:alerts])
      if options[:print]
        puts "#{result[:alerts].count} dependency warnings written to '#{options.fetch(:output)}'"
      end
      output_file
    rescue => e
      STDERR.puts "Failed to write file '#{options.fetch(:output)}'"
      STDERR.puts "Error: #{e.message} (set DEBUG=true for detailed backtrace)"
      STDERR.puts e.backtrace if ENV['DEBUG']
      exit 1
    end
  else
    if options[:print]
      ConsoleWriter.new.write!(result[:alerts])
    else
      result[:alerts]
    end
  end
end