homebrew-cask-versions/lib/cask/cli/install.rb
Roland Walker 4f3ecb1cc3 Downgrade Cask install errors to warnings
Including the case where a Cask is already installed.
Always continue installing when multiple Casks are specified,
only raising an exception at the end of the command (if some
portion of the attempted install actions failed).  Never
exit with an error code if "already installed" was the only
problem seen during the run.

Also tweak error messages.

Fixes #1347, #2677, #4785

Required disabling two tests regarding suggestions on Cask
spelling errors.
2014-06-10 12:13:59 -04:00

49 lines
1.5 KiB
Ruby

class Cask::CLI::Install
def self.run(*args)
raise CaskUnspecifiedError if args.empty?
cask_names = args.reject { |a| a.chars.first == '-' }
force = args.include? '--force'
retval = install_casks cask_names, force
# retval is ternary: true/false/nil
if retval.nil?
raise CaskError.new("nothing to install")
elsif ! retval
raise CaskError.new("install incomplete")
end
end
def self.install_casks(cask_names, force)
count = 0
cask_names.each do |cask_name|
begin
cask = Cask.load(cask_name)
Cask::Installer.new(cask).install(force)
count += 1
rescue CaskAlreadyInstalledError => e
# todo: downgrade this message from Error to Warning
# possibly get rid of the CaskAlreadyInstalledError exception
# and simply test cask.installed? in this loop
onoe e.message
count += 1
rescue CaskUnavailableError => e
warn_unavailable_with_suggestion cask_name, e
end
end
count == 0 ? nil : count == cask_names.length
end
def self.warn_unavailable_with_suggestion(cask_name, e)
exact_match, partial_matches, search_term = Cask::CLI::Search.search(cask_name)
errmsg = e.message
if exact_match
errmsg.concat(". Did you mean:\n#{exact_match}")
elsif !partial_matches.empty?
errmsg.concat(". Did you mean one of:\n#{stringify_columns(partial_matches.take(20))}\n")
end
onoe errmsg
end
def self.help
"installs the cask of the given name"
end
end