Port Homebrew::Cmd::Upgrade
This commit is contained in:
parent
d5add6565c
commit
1362890f2a
@ -1,7 +1,7 @@
|
|||||||
# typed: true
|
# typed: strict
|
||||||
# frozen_string_literal: true
|
# frozen_string_literal: true
|
||||||
|
|
||||||
require "cli/parser"
|
require "abstract_command"
|
||||||
require "formula_installer"
|
require "formula_installer"
|
||||||
require "install"
|
require "install"
|
||||||
require "upgrade"
|
require "upgrade"
|
||||||
@ -11,11 +11,9 @@ require "cask/macos"
|
|||||||
require "api"
|
require "api"
|
||||||
|
|
||||||
module Homebrew
|
module Homebrew
|
||||||
module_function
|
module Cmd
|
||||||
|
class UpgradeCmd < AbstractCommand
|
||||||
sig { returns(CLI::Parser) }
|
cmd_args do
|
||||||
def upgrade_args
|
|
||||||
Homebrew::CLI::Parser.new do
|
|
||||||
description <<~EOS
|
description <<~EOS
|
||||||
Upgrade outdated casks and outdated, unpinned formulae using the same options they were originally
|
Upgrade outdated casks and outdated, unpinned formulae using the same options they were originally
|
||||||
installed with, plus any appended brew formula options. If <cask> or <formula> are specified,
|
installed with, plus any appended brew formula options. If <cask> or <formula> are specified,
|
||||||
@ -124,12 +122,9 @@ module Homebrew
|
|||||||
|
|
||||||
named_args [:installed_formula, :installed_cask]
|
named_args [:installed_formula, :installed_cask]
|
||||||
end
|
end
|
||||||
end
|
|
||||||
|
|
||||||
sig { void }
|
|
||||||
def upgrade
|
|
||||||
args = upgrade_args.parse
|
|
||||||
|
|
||||||
|
sig { override.void }
|
||||||
|
def run
|
||||||
# Deprecated since this is now the default behavior.
|
# Deprecated since this is now the default behavior.
|
||||||
odeprecated "`brew upgrade --ignore-pinned`" if args.ignore_pinned?
|
odeprecated "`brew upgrade --ignore-pinned`" if args.ignore_pinned?
|
||||||
|
|
||||||
@ -140,16 +135,18 @@ module Homebrew
|
|||||||
only_upgrade_formulae = formulae.present? && casks.blank?
|
only_upgrade_formulae = formulae.present? && casks.blank?
|
||||||
only_upgrade_casks = casks.present? && formulae.blank?
|
only_upgrade_casks = casks.present? && formulae.blank?
|
||||||
|
|
||||||
upgrade_outdated_formulae(formulae, args:) unless only_upgrade_casks
|
upgrade_outdated_formulae(formulae) unless only_upgrade_casks
|
||||||
upgrade_outdated_casks(casks, args:) unless only_upgrade_formulae
|
upgrade_outdated_casks(casks) unless only_upgrade_formulae
|
||||||
|
|
||||||
Cleanup.periodic_clean!(dry_run: args.dry_run?)
|
Cleanup.periodic_clean!(dry_run: args.dry_run?)
|
||||||
|
|
||||||
Homebrew.messages.display_messages(display_times: args.display_times?)
|
Homebrew.messages.display_messages(display_times: args.display_times?)
|
||||||
end
|
end
|
||||||
|
|
||||||
sig { params(formulae: T::Array[Formula], args: T.untyped).returns(T::Boolean) }
|
private
|
||||||
def upgrade_outdated_formulae(formulae, args:)
|
|
||||||
|
sig { params(formulae: T::Array[Formula]).returns(T::Boolean) }
|
||||||
|
def upgrade_outdated_formulae(formulae)
|
||||||
return false if args.cask?
|
return false if args.cask?
|
||||||
|
|
||||||
if args.build_from_source?
|
if args.build_from_source?
|
||||||
@ -209,7 +206,8 @@ module Homebrew
|
|||||||
oh1 "No packages to upgrade"
|
oh1 "No packages to upgrade"
|
||||||
else
|
else
|
||||||
verb = args.dry_run? ? "Would upgrade" : "Upgrading"
|
verb = args.dry_run? ? "Would upgrade" : "Upgrading"
|
||||||
oh1 "#{verb} #{formulae_to_install.count} outdated #{Utils.pluralize("package", formulae_to_install.count)}:"
|
oh1 "#{verb} #{formulae_to_install.count} outdated #{Utils.pluralize("package",
|
||||||
|
formulae_to_install.count)}:"
|
||||||
formulae_upgrades = formulae_to_install.map do |f|
|
formulae_upgrades = formulae_to_install.map do |f|
|
||||||
if f.optlinked?
|
if f.optlinked?
|
||||||
"#{f.full_specified_name} #{Keg.new(f.opt_prefix).version} -> #{f.pkg_version}"
|
"#{f.full_specified_name} #{Keg.new(f.opt_prefix).version} -> #{f.pkg_version}"
|
||||||
@ -256,8 +254,8 @@ module Homebrew
|
|||||||
true
|
true
|
||||||
end
|
end
|
||||||
|
|
||||||
sig { params(casks: T::Array[Cask::Cask], args: T.untyped).returns(T::Boolean) }
|
sig { params(casks: T::Array[Cask::Cask]).returns(T::Boolean) }
|
||||||
def upgrade_outdated_casks(casks, args:)
|
def upgrade_outdated_casks(casks)
|
||||||
return false if args.formula?
|
return false if args.formula?
|
||||||
|
|
||||||
Cask::Upgrade.upgrade_casks(
|
Cask::Upgrade.upgrade_casks(
|
||||||
@ -276,3 +274,5 @@ module Homebrew
|
|||||||
)
|
)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
|
@ -1,8 +1,9 @@
|
|||||||
# frozen_string_literal: true
|
# frozen_string_literal: true
|
||||||
|
|
||||||
require "cmd/shared_examples/args_parse"
|
require "cmd/shared_examples/args_parse"
|
||||||
|
require "cmd/upgrade"
|
||||||
|
|
||||||
RSpec.describe "brew upgrade" do
|
RSpec.describe Homebrew::Cmd::UpgradeCmd do
|
||||||
it_behaves_like "parseable arguments"
|
it_behaves_like "parseable arguments"
|
||||||
|
|
||||||
it "upgrades a Formula and cleans up old versions", :integration_test do
|
it "upgrades a Formula and cleans up old versions", :integration_test do
|
||||||
|
Loading…
x
Reference in New Issue
Block a user