aboutsummaryrefslogtreecommitdiffstats
path: root/Library/Homebrew/cask/lib/hbc/cli/install.rb
diff options
context:
space:
mode:
authorMarkus Reiter2016-09-24 13:52:43 +0200
committerMarkus Reiter2016-09-24 16:00:58 +0200
commitb86c8efb79b3ed835d552c4d7416640ef10caf21 (patch)
tree7e1edc8a8f339e4d2781f43576d40c9c79aebcdc /Library/Homebrew/cask/lib/hbc/cli/install.rb
parent687f0fcf721c8e36f32570ed72d0988a6eaf986f (diff)
downloadbrew-b86c8efb79b3ed835d552c4d7416640ef10caf21.tar.bz2
Cask: Use nested classes and modules.
Diffstat (limited to 'Library/Homebrew/cask/lib/hbc/cli/install.rb')
-rw-r--r--Library/Homebrew/cask/lib/hbc/cli/install.rb107
1 files changed, 55 insertions, 52 deletions
diff --git a/Library/Homebrew/cask/lib/hbc/cli/install.rb b/Library/Homebrew/cask/lib/hbc/cli/install.rb
index 16e3b8121..d7575344d 100644
--- a/Library/Homebrew/cask/lib/hbc/cli/install.rb
+++ b/Library/Homebrew/cask/lib/hbc/cli/install.rb
@@ -1,60 +1,63 @@
+module Hbc
+ class CLI
+ class Install < Base
+ def self.run(*args)
+ cask_tokens = cask_tokens_from(args)
+ raise CaskUnspecifiedError if cask_tokens.empty?
+ force = args.include? "--force"
+ skip_cask_deps = args.include? "--skip-cask-deps"
+ require_sha = args.include? "--require-sha"
+ retval = install_casks cask_tokens, force, skip_cask_deps, require_sha
+ # retval is ternary: true/false/nil
-class Hbc::CLI::Install < Hbc::CLI::Base
- def self.run(*args)
- cask_tokens = cask_tokens_from(args)
- raise Hbc::CaskUnspecifiedError if cask_tokens.empty?
- force = args.include? "--force"
- skip_cask_deps = args.include? "--skip-cask-deps"
- require_sha = args.include? "--require-sha"
- retval = install_casks cask_tokens, force, skip_cask_deps, require_sha
- # retval is ternary: true/false/nil
-
- raise Hbc::CaskError, "nothing to install" if retval.nil?
- raise Hbc::CaskError, "install incomplete" unless retval
- end
+ raise CaskError, "nothing to install" if retval.nil?
+ raise CaskError, "install incomplete" unless retval
+ end
- def self.install_casks(cask_tokens, force, skip_cask_deps, require_sha)
- count = 0
- cask_tokens.each do |cask_token|
- begin
- cask = Hbc.load(cask_token)
- Hbc::Installer.new(cask,
- force: force,
- skip_cask_deps: skip_cask_deps,
- require_sha: require_sha).install
- count += 1
- rescue Hbc::CaskAlreadyInstalledError => e
- opoo e.message
- count += 1
- rescue Hbc::CaskAutoUpdatesError => e
- opoo e.message
- count += 1
- rescue Hbc::CaskUnavailableError => e
- warn_unavailable_with_suggestion cask_token, e
- rescue Hbc::CaskNoShasumError => e
- opoo e.message
- count += 1
+ def self.install_casks(cask_tokens, force, skip_cask_deps, require_sha)
+ count = 0
+ cask_tokens.each do |cask_token|
+ begin
+ cask = Hbc.load(cask_token)
+ Installer.new(cask,
+ force: force,
+ skip_cask_deps: skip_cask_deps,
+ require_sha: require_sha).install
+ count += 1
+ rescue CaskAlreadyInstalledError => e
+ opoo e.message
+ count += 1
+ rescue CaskAutoUpdatesError => e
+ opoo e.message
+ count += 1
+ rescue CaskUnavailableError => e
+ warn_unavailable_with_suggestion cask_token, e
+ rescue CaskNoShasumError => e
+ opoo e.message
+ count += 1
+ end
+ end
+ count.zero? ? nil : count == cask_tokens.length
end
- end
- count.zero? ? nil : count == cask_tokens.length
- end
- def self.warn_unavailable_with_suggestion(cask_token, e)
- exact_match, partial_matches = Hbc::CLI::Search.search(cask_token)
- 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#{puts_columns(partial_matches.take(20))}\n")
- end
- onoe errmsg
- end
+ def self.warn_unavailable_with_suggestion(cask_token, e)
+ exact_match, partial_matches = Search.search(cask_token)
+ 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#{puts_columns(partial_matches.take(20))}\n")
+ end
+ onoe errmsg
+ end
- def self.help
- "installs the given Cask"
- end
+ def self.help
+ "installs the given Cask"
+ end
- def self.needs_init?
- true
+ def self.needs_init?
+ true
+ end
+ end
end
end