lib/bundler/audit/cli.rb in bundler-audit-0.8.0 vs lib/bundler/audit/cli.rb in bundler-audit-0.9.0
- old
+ new
@@ -10,11 +10,11 @@
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
-# along with bundler-audit. If not, see <http://www.gnu.org/licenses/>.
+# along with bundler-audit. If not, see <https://www.gnu.org/licenses/>.
#
require 'bundler/audit/scanner'
require 'bundler/audit/version'
require 'bundler/audit/cli/formats'
@@ -23,25 +23,30 @@
require 'bundler/audit/cli/thor_ext/shell/basic/say_error'
require 'bundler'
module Bundler
module Audit
+ #
+ # The `bundle-audit` command.
+ #
class CLI < ::Thor
default_task :check
map '--version' => :version
desc 'check [DIR]', 'Checks the Gemfile.lock for insecure dependencies'
- method_option :quiet, :type => :boolean, :aliases => '-q'
- method_option :verbose, :type => :boolean, :aliases => '-v'
- method_option :ignore, :type => :array, :aliases => '-i'
- method_option :update, :type => :boolean, :aliases => '-u'
- method_option :database, :type => :string, :aliases => '-D', :default => Database::USER_PATH
- method_option :format, :type => :string, :default => 'text',
- :aliases => '-F'
- method_option :gemfile_lock, :type => :string, :aliases => '-G', :default => 'Gemfile.lock'
- method_option :output, :type => :string, :aliases => '-o'
+ method_option :quiet, type: :boolean, aliases: '-q'
+ method_option :verbose, type: :boolean, aliases: '-v'
+ method_option :ignore, type: :array, aliases: '-i'
+ method_option :update, type: :boolean, aliases: '-u'
+ method_option :database, type: :string, aliases: '-D',
+ default: Database::USER_PATH
+ method_option :format, type: :string, default: 'text', aliases: '-F'
+ method_option :config, type: :string, aliases: '-c', default: '.bundler-audit.yml'
+ method_option :gemfile_lock, type: :string, aliases: '-G',
+ default: 'Gemfile.lock'
+ method_option :output, type: :string, aliases: '-o'
def check(dir=Dir.pwd)
unless File.directory?(dir)
say_error "No such file or directory: #{dir}", :red
exit 1
@@ -60,17 +65,18 @@
update(options[:database])
end
database = Database.new(options[:database])
scanner = begin
- Scanner.new(dir,options[:gemfile_lock],database)
+ 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)
+ report = scanner.report(ignore: options.ignore)
+
output = if options[:output] then File.new(options[:output],'w')
else $stdout
end
print_report(report,output)
@@ -79,22 +85,26 @@
exit(1) if report.vulnerable?
end
desc 'stats', 'Prints ruby-advisory-db stats'
- method_option :quiet, :type => :boolean, :aliases => '-q'
+ method_option :quiet, type: :boolean, aliases: '-q'
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
desc 'download', 'Downloads ruby-advisory-db'
- method_option :quiet, :type => :boolean, :aliases => '-q'
+ method_option :quiet, type: :boolean, aliases: '-q'
def download(path=Database.path)
if Database.exists?(path)
say "Database already exists", :yellow
return
@@ -111,11 +121,11 @@
stats(path) unless options.quiet?
end
desc 'update', 'Updates the ruby-advisory-db'
- method_option :quiet, :type => :boolean, :aliases => '-q'
+ method_option :quiet, type: :boolean, aliases: '-q'
def update(path=Database.path)
unless Database.exists?(path)
download(path)
return
@@ -147,9 +157,16 @@
def version
puts "bundler-audit #{VERSION}"
end
protected
+
+ #
+ # @note Silence deprecation warnings from Thor.
+ #
+ def self.exit_on_failure?
+ true
+ end
#
# @abstract
#
def print_report(report)