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
|
||||
|
||||
require "cli/parser"
|
||||
require "abstract_command"
|
||||
require "formula_installer"
|
||||
require "install"
|
||||
require "upgrade"
|
||||
@ -11,11 +11,9 @@ require "cask/macos"
|
||||
require "api"
|
||||
|
||||
module Homebrew
|
||||
module_function
|
||||
|
||||
sig { returns(CLI::Parser) }
|
||||
def upgrade_args
|
||||
Homebrew::CLI::Parser.new do
|
||||
module Cmd
|
||||
class UpgradeCmd < AbstractCommand
|
||||
cmd_args do
|
||||
description <<~EOS
|
||||
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,
|
||||
@ -124,12 +122,9 @@ module Homebrew
|
||||
|
||||
named_args [:installed_formula, :installed_cask]
|
||||
end
|
||||
end
|
||||
|
||||
sig { void }
|
||||
def upgrade
|
||||
args = upgrade_args.parse
|
||||
|
||||
sig { override.void }
|
||||
def run
|
||||
# Deprecated since this is now the default behavior.
|
||||
odeprecated "`brew upgrade --ignore-pinned`" if args.ignore_pinned?
|
||||
|
||||
@ -140,16 +135,18 @@ module Homebrew
|
||||
only_upgrade_formulae = formulae.present? && casks.blank?
|
||||
only_upgrade_casks = casks.present? && formulae.blank?
|
||||
|
||||
upgrade_outdated_formulae(formulae, args:) unless only_upgrade_casks
|
||||
upgrade_outdated_casks(casks, args:) unless only_upgrade_formulae
|
||||
upgrade_outdated_formulae(formulae) unless only_upgrade_casks
|
||||
upgrade_outdated_casks(casks) unless only_upgrade_formulae
|
||||
|
||||
Cleanup.periodic_clean!(dry_run: args.dry_run?)
|
||||
|
||||
Homebrew.messages.display_messages(display_times: args.display_times?)
|
||||
end
|
||||
|
||||
sig { params(formulae: T::Array[Formula], args: T.untyped).returns(T::Boolean) }
|
||||
def upgrade_outdated_formulae(formulae, args:)
|
||||
private
|
||||
|
||||
sig { params(formulae: T::Array[Formula]).returns(T::Boolean) }
|
||||
def upgrade_outdated_formulae(formulae)
|
||||
return false if args.cask?
|
||||
|
||||
if args.build_from_source?
|
||||
@ -209,7 +206,8 @@ module Homebrew
|
||||
oh1 "No packages to upgrade"
|
||||
else
|
||||
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|
|
||||
if f.optlinked?
|
||||
"#{f.full_specified_name} #{Keg.new(f.opt_prefix).version} -> #{f.pkg_version}"
|
||||
@ -256,8 +254,8 @@ module Homebrew
|
||||
true
|
||||
end
|
||||
|
||||
sig { params(casks: T::Array[Cask::Cask], args: T.untyped).returns(T::Boolean) }
|
||||
def upgrade_outdated_casks(casks, args:)
|
||||
sig { params(casks: T::Array[Cask::Cask]).returns(T::Boolean) }
|
||||
def upgrade_outdated_casks(casks)
|
||||
return false if args.formula?
|
||||
|
||||
Cask::Upgrade.upgrade_casks(
|
||||
@ -276,3 +274,5 @@ module Homebrew
|
||||
)
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
@ -1,8 +1,9 @@
|
||||
# frozen_string_literal: true
|
||||
|
||||
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 "upgrades a Formula and cleans up old versions", :integration_test do
|
||||
|
Loading…
x
Reference in New Issue
Block a user