aboutsummaryrefslogtreecommitdiffstats
path: root/Library/Homebrew/cask/lib
diff options
context:
space:
mode:
authorL. E. Segovia2017-10-29 17:31:07 -0300
committerL. E. Segovia2017-10-29 17:34:53 -0300
commit55727b789532fbfa7997929aa0506d7843eda3ce (patch)
tree7b69cc7b0b5ee506bb5c2b9eddf898c8858b5cf2 /Library/Homebrew/cask/lib
parent4c44266aa5cfab215b92ef0aa5bb12112d8a4cb8 (diff)
downloadbrew-55727b789532fbfa7997929aa0506d7843eda3ce.tar.bz2
Hack a first working version of upgrade
Diffstat (limited to 'Library/Homebrew/cask/lib')
-rw-r--r--Library/Homebrew/cask/lib/hbc/cli.rb1
-rw-r--r--Library/Homebrew/cask/lib/hbc/cli/upgrade.rb65
-rw-r--r--Library/Homebrew/cask/lib/hbc/installer.rb16
3 files changed, 79 insertions, 3 deletions
diff --git a/Library/Homebrew/cask/lib/hbc/cli.rb b/Library/Homebrew/cask/lib/hbc/cli.rb
index e147c8280..215b59843 100644
--- a/Library/Homebrew/cask/lib/hbc/cli.rb
+++ b/Library/Homebrew/cask/lib/hbc/cli.rb
@@ -21,6 +21,7 @@ require "hbc/cli/reinstall"
require "hbc/cli/search"
require "hbc/cli/style"
require "hbc/cli/uninstall"
+require "hbc/cli/upgrade"
require "hbc/cli/--version"
require "hbc/cli/zap"
diff --git a/Library/Homebrew/cask/lib/hbc/cli/upgrade.rb b/Library/Homebrew/cask/lib/hbc/cli/upgrade.rb
new file mode 100644
index 000000000..49a538704
--- /dev/null
+++ b/Library/Homebrew/cask/lib/hbc/cli/upgrade.rb
@@ -0,0 +1,65 @@
+module Hbc
+ class CLI
+ class Upgrade < AbstractCommand
+ option "--greedy", :greedy, false
+ option "--quiet", :quiet, false
+ option "--force", :force, false
+ option "--force-update", :force_update, false
+ option "--skip-cask-deps", :skip_cask_deps, false
+
+ def initialize(*)
+ super
+ self.verbose = ($stdout.tty? || verbose?) && !quiet?
+ end
+
+ def run
+ outdated_casks = casks(alternative: -> { Hbc.installed }).find_all { |cask| cask.outdated?(greedy?) }
+
+ if outdated_casks.empty?
+ oh1 "No packages to upgrade"
+ else
+ oh1 "Upgrading #{Formatter.pluralize(outdated_casks.length, "outdated package")}, with result:"
+ puts outdated_casks.map { |f| "#{f.full_name} #{f.version}" } * ", "
+ end
+
+ outdated_casks.each do |old_cask|
+ odebug "Uninstalling Cask #{old_cask}"
+
+ raise CaskNotInstalledError, old_cask unless old_cask.installed? || force?
+
+ unless old_cask.installed_caskfile.nil?
+ # use the same cask file that was used for installation, if possible
+ old_cask = CaskLoader.load(old_cask.installed_caskfile) if old_cask.installed_caskfile.exist?
+ end
+
+ old_cask_installer = Installer.new(old_cask, binaries: binaries?, verbose: verbose?, force: force?, upgrade: true)
+
+ old_cask_installer.uninstall
+
+ begin
+ odebug "Installing new version of Cask #{old_cask}"
+
+ new_cask = CaskLoader.load(old_cask.to_s)
+
+ Installer.new(new_cask, binaries: binaries?,
+ verbose: verbose?,
+ force: force?,
+ skip_cask_deps: skip_cask_deps?,
+ require_sha: require_sha?,
+ upgrade: true).install
+
+ old_cask_installer.finalize_upgrade
+ rescue CaskUnavailableError => e
+ opoo e.message
+ rescue CaskAlreadyInstalledError => e
+ opoo e.message
+ end
+ end
+ end
+
+ def self.help
+ "upgrades all outdated casks"
+ end
+ end
+ end
+end
diff --git a/Library/Homebrew/cask/lib/hbc/installer.rb b/Library/Homebrew/cask/lib/hbc/installer.rb
index 1063f488b..629a20f31 100644
--- a/Library/Homebrew/cask/lib/hbc/installer.rb
+++ b/Library/Homebrew/cask/lib/hbc/installer.rb
@@ -19,7 +19,7 @@ module Hbc
PERSISTENT_METADATA_SUBDIRS = ["gpg"].freeze
- def initialize(cask, command: SystemCommand, force: false, skip_cask_deps: false, binaries: true, verbose: false, require_sha: false)
+ def initialize(cask, command: SystemCommand, force: false, skip_cask_deps: false, binaries: true, verbose: false, require_sha: false, upgrade: false)
@cask = cask
@command = command
@force = force
@@ -28,6 +28,7 @@ module Hbc
@verbose = verbose
@require_sha = require_sha
@reinstall = false
+ @upgrade = upgrade
end
attr_predicate :binaries?, :force?, :skip_cask_deps?, :require_sha?, :verbose?
@@ -82,7 +83,7 @@ module Hbc
def install
odebug "Hbc::Installer#install"
- if @cask.installed? && !force? && !@reinstall
+ if @cask.installed? && !force? && !@reinstall && !@upgrade
raise CaskAlreadyInstalledError, @cask
end
@@ -129,7 +130,7 @@ module Hbc
installed_cask = installed_caskfile.exist? ? CaskLoader.load(installed_caskfile) : @cask
# Always force uninstallation, ignore method parameter
- Installer.new(installed_cask, binaries: binaries?, verbose: verbose?, force: true).uninstall
+ Installer.new(installed_cask, binaries: binaries?, verbose: verbose?, force: true, upgrade: @upgrade).uninstall
end
def summary
@@ -368,6 +369,15 @@ module Hbc
oh1 "Uninstalling Cask #{@cask}"
disable_accessibility_access
uninstall_artifacts
+ return if @upgrade
+
+ purge_versioned_files
+ purge_caskroom_path if force?
+ end
+
+ def finalize_upgrade
+ return unless @upgrade
+
purge_versioned_files
purge_caskroom_path if force?
end