homebrew-cask-versions/lib/cask/cli/install.rb
Roland Walker 707db75505 standardize Cask (capitalized) when used as noun
* was already done, but inconsistently
* this style follows homebrew Formula
* covers user-facing messages, test titles, comments
* some related minor orthography is included, such
  as the consistent spelling of our project name as
  "homebrew-cask"
* grammar nits
2014-10-08 10:39:51 -04:00

49 lines
1.5 KiB
Ruby

class Cask::CLI::Install < Cask::CLI::Base
def self.run(*args)
cask_names = cask_names_from(args)
raise CaskUnspecifiedError if cask_names.empty?
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#{Cask::Utils.stringify_columns(partial_matches.take(20))}\n")
end
onoe errmsg
end
def self.help
"installs the Cask of the given name"
end
end