aboutsummaryrefslogtreecommitdiffstats
path: root/Library
diff options
context:
space:
mode:
authorMarkus Reiter2017-05-20 02:27:13 +0200
committerMarkus Reiter2017-05-22 02:51:16 +0200
commit33580c283a5122424edbfa6a1f70e6c11bf29b36 (patch)
tree9f89affc675e5f2953a9393a82bb5b7c977e9aa8 /Library
parente17641bdd9d976a45e95501167a0aa76bf521cbc (diff)
downloadbrew-33580c283a5122424edbfa6a1f70e6c11bf29b36.tar.bz2
Refactor `CLI::Install`.
Diffstat (limited to 'Library')
-rw-r--r--Library/Homebrew/cask/lib/hbc/cli/install.rb34
-rw-r--r--Library/Homebrew/cask/lib/hbc/cli/reinstall.rb15
2 files changed, 29 insertions, 20 deletions
diff --git a/Library/Homebrew/cask/lib/hbc/cli/install.rb b/Library/Homebrew/cask/lib/hbc/cli/install.rb
index 5b5ef82c4..53c510774 100644
--- a/Library/Homebrew/cask/lib/hbc/cli/install.rb
+++ b/Library/Homebrew/cask/lib/hbc/cli/install.rb
@@ -2,27 +2,34 @@ 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
+ new(*args).run
+ end
+
+ def initialize(*args)
+ @cask_tokens = self.class.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"
+ end
+
+ def run
+ retval = install_casks
# retval is ternary: true/false/nil
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)
+ def install_casks
count = 0
- cask_tokens.each do |cask_token|
+ @cask_tokens.each do |cask_token|
begin
cask = CaskLoader.load(cask_token)
Installer.new(cask, binaries: CLI.binaries?,
- force: force,
- skip_cask_deps: skip_cask_deps,
- require_sha: require_sha).install
+ force: @force,
+ skip_cask_deps: @skip_cask_deps,
+ require_sha: @require_sha).install
count += 1
rescue CaskAlreadyInstalledError => e
opoo e.message
@@ -31,7 +38,7 @@ module Hbc
opoo e.message
count += 1
rescue CaskUnavailableError => e
- warn_unavailable_with_suggestion cask_token, e
+ self.class.warn_unavailable_with_suggestion cask_token, e
rescue CaskNoShasumError => e
opoo e.message
count += 1
@@ -39,7 +46,8 @@ module Hbc
onoe e.message
end
end
- count.zero? ? nil : count == cask_tokens.length
+
+ count.zero? ? nil : count == @cask_tokens.length
end
def self.warn_unavailable_with_suggestion(cask_token, e)
diff --git a/Library/Homebrew/cask/lib/hbc/cli/reinstall.rb b/Library/Homebrew/cask/lib/hbc/cli/reinstall.rb
index 662899d5f..b675a79fa 100644
--- a/Library/Homebrew/cask/lib/hbc/cli/reinstall.rb
+++ b/Library/Homebrew/cask/lib/hbc/cli/reinstall.rb
@@ -1,27 +1,28 @@
module Hbc
class CLI
class Reinstall < Install
- def self.install_casks(cask_tokens, force, skip_cask_deps, require_sha)
+ def install_casks
count = 0
- cask_tokens.each do |cask_token|
+ @cask_tokens.each do |cask_token|
begin
cask = CaskLoader.load(cask_token)
Installer.new(cask,
binaries: CLI.binaries?,
- force: force,
- skip_cask_deps: skip_cask_deps,
- require_sha: require_sha).reinstall
+ force: @force,
+ skip_cask_deps: @skip_cask_deps,
+ require_sha: @require_sha).reinstall
count += 1
rescue CaskUnavailableError => e
- warn_unavailable_with_suggestion cask_token, e
+ self.class.warn_unavailable_with_suggestion cask_token, e
rescue CaskNoShasumError => e
opoo e.message
count += 1
end
end
- count.zero? ? nil : count == cask_tokens.length
+
+ count.zero? ? nil : count == @cask_tokens.length
end
def self.help