Let Cask doctor exit with 1 via a CaskError

This commit is contained in:
L. E. Segovia 2017-11-03 19:09:53 -03:00
parent 3d96cd156a
commit 84e41194cb

View File

@ -3,6 +3,8 @@ require "system_config"
module Hbc module Hbc
class CLI class CLI
class Doctor < AbstractCommand class Doctor < AbstractCommand
attr_accessor :failed
def initialize(*) def initialize(*)
super super
return if args.empty? return if args.empty?
@ -35,6 +37,8 @@ module Hbc
] ]
(self.class.locale_variables + environment_variables).sort.each(&self.class.method(:render_env_var)) (self.class.locale_variables + environment_variables).sort.each(&self.class.method(:render_env_var))
raise CaskError, "One or more checks failed." if @failed
end end
def self.locale_variables def self.locale_variables
@ -61,6 +65,7 @@ module Hbc
def self.cask_count_for_tap(tap) def self.cask_count_for_tap(tap)
Formatter.pluralize(tap.cask_files.count, "cask") Formatter.pluralize(tap.cask_files.count, "cask")
rescue StandardError rescue StandardError
@failed = true
"0 #{error_string "error reading #{tap.path}"}" "0 #{error_string "error reading #{tap.path}"}"
end end
@ -92,6 +97,7 @@ module Hbc
if locations.empty? if locations.empty?
none_string none_string
else else
@failed = true
locations.collect do |l| locations.collect do |l|
"#{l} #{error_string 'error: legacy install. Run "brew uninstall --force brew-cask".'}" "#{l} #{error_string 'error: legacy install. Run "brew uninstall --force brew-cask".'}"
end end
@ -101,8 +107,10 @@ module Hbc
def self.render_staging_location(path) def self.render_staging_location(path)
path = Pathname.new(user_tilde(path.to_s)) path = Pathname.new(user_tilde(path.to_s))
if !path.exist? if !path.exist?
@failed = true
"#{path} #{error_string "error: path does not exist"}" "#{path} #{error_string "error: path does not exist"}"
elsif !path.writable? elsif !path.writable?
@failed = true
"#{path} #{error_string "error: not writable by current user"}" "#{path} #{error_string "error: not writable by current user"}"
else else
path path