-
-
Notifications
You must be signed in to change notification settings - Fork 9.9k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #3396 from amyspark/hacktoberfest-upgrade
Implement `brew cask upgrade`
- Loading branch information
Showing
12 changed files
with
397 additions
and
24 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,87 @@ | ||
module Hbc | ||
class CLI | ||
class Upgrade < AbstractCommand | ||
option "--greedy", :greedy, false | ||
option "--quiet", :quiet, false | ||
option "--force", :force, 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: lambda { | ||
Hbc.installed.select do |cask| | ||
cask.outdated?(greedy?) | ||
end | ||
}).select { |cask| cask.outdated?(true) } | ||
|
||
if outdated_casks.empty? | ||
oh1 "No Casks to upgrade" | ||
return | ||
end | ||
|
||
oh1 "Upgrading #{Formatter.pluralize(outdated_casks.length, "outdated package")}, with result:" | ||
puts outdated_casks.map { |f| "#{f.full_name} #{f.version}" } * ", " | ||
|
||
outdated_casks.each do |old_cask| | ||
odebug "Started upgrade process for Cask #{old_cask}" | ||
raise CaskNotInstalledError, old_cask unless old_cask.installed? || force? | ||
|
||
raise CaskUnavailableError.new(old_cask, "The Caskfile is missing!") if old_cask.installed_caskfile.nil? | ||
|
||
old_cask = CaskLoader.load(old_cask.installed_caskfile) | ||
|
||
old_cask_installer = Installer.new(old_cask, binaries: binaries?, verbose: verbose?, force: force?, upgrade: true) | ||
|
||
new_cask = CaskLoader.load(old_cask.to_s) | ||
|
||
new_cask_installer = | ||
Installer.new(new_cask, binaries: binaries?, | ||
verbose: verbose?, | ||
force: force?, | ||
skip_cask_deps: skip_cask_deps?, | ||
require_sha: require_sha?, | ||
upgrade: true) | ||
|
||
started_upgrade = false | ||
new_artifacts_installed = false | ||
|
||
begin | ||
# Start new Cask's installation steps | ||
new_cask_installer.check_conflicts | ||
|
||
new_cask_installer.fetch | ||
|
||
new_cask_installer.stage | ||
|
||
# Move the old Cask's artifacts back to staging | ||
old_cask_installer.start_upgrade | ||
# And flag it so in case of error | ||
started_upgrade = true | ||
|
||
# Install the new Cask | ||
new_cask_installer.install_artifacts | ||
new_artifacts_installed = true | ||
|
||
new_cask_installer.enable_accessibility_access | ||
|
||
# If successful, wipe the old Cask from staging | ||
old_cask_installer.finalize_upgrade | ||
rescue CaskError => e | ||
new_cask_installer.uninstall_artifacts if new_artifacts_installed | ||
new_cask_installer.purge_versioned_files | ||
old_cask_installer.revert_upgrade if started_upgrade | ||
raise e | ||
end | ||
end | ||
end | ||
|
||
def self.help | ||
"upgrades all outdated casks" | ||
end | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.