Port Homebrew::Cmd::UpdateReport

This commit is contained in:
Douglas Eichelberger 2024-04-01 11:55:05 -07:00
parent 48f4adad33
commit d5add6565c
2 changed files with 368 additions and 366 deletions

View File

@ -1,6 +1,7 @@
# typed: true # typed: true
# frozen_string_literal: true # frozen_string_literal: true
require "abstract_command"
require "migrator" require "migrator"
require "formulary" require "formulary"
require "cask/cask_loader" require "cask/cask_loader"
@ -8,23 +9,13 @@ require "cask/migrator"
require "descriptions" require "descriptions"
require "cleanup" require "cleanup"
require "description_cache_store" require "description_cache_store"
require "cli/parser"
require "settings" require "settings"
require "linuxbrew-core-migration" require "linuxbrew-core-migration"
module Homebrew module Homebrew
module_function module Cmd
class UpdateReport < AbstractCommand
def auto_update_header(args:) cmd_args do
@auto_update_header ||= begin
ohai "Auto-updated Homebrew!" if args.auto_update?
true
end
end
sig { returns(CLI::Parser) }
def update_report_args
Homebrew::CLI::Parser.new do
description <<~EOS description <<~EOS
The Ruby implementation of `brew update`. Never called manually. The Ruby implementation of `brew update`. Never called manually.
EOS EOS
@ -36,9 +27,9 @@ module Homebrew
hide_from_man_page! hide_from_man_page!
end end
end
def update_report sig { override.void }
def run
return output_update_report if $stdout.tty? return output_update_report if $stdout.tty?
redirect_stdout($stderr) do redirect_stdout($stderr) do
@ -46,9 +37,16 @@ module Homebrew
end end
end end
def output_update_report private
args = update_report_args.parse
def auto_update_header
@auto_update_header ||= begin
ohai "Auto-updated Homebrew!" if args.auto_update?
true
end
end
def output_update_report
# Run `brew update` (again) if we've got a linuxbrew-core CoreTap # Run `brew update` (again) if we've got a linuxbrew-core CoreTap
if CoreTap.instance.installed? && CoreTap.instance.linuxbrew_core? && if CoreTap.instance.installed? && CoreTap.instance.linuxbrew_core? &&
ENV["HOMEBREW_LINUXBREW_CORE_MIGRATION"].blank? ENV["HOMEBREW_LINUXBREW_CORE_MIGRATION"].blank?
@ -109,7 +107,7 @@ module Homebrew
odie "update-report should not be called directly!" if initial_revision.empty? || current_revision.empty? odie "update-report should not be called directly!" if initial_revision.empty? || current_revision.empty?
if initial_revision != current_revision if initial_revision != current_revision
auto_update_header(args:) auto_update_header
updated = true updated = true
@ -122,7 +120,8 @@ module Homebrew
Settings.write "latesttag", new_tag if new_tag != old_tag Settings.write "latesttag", new_tag if new_tag != old_tag
if new_tag == old_tag if new_tag == old_tag
ohai "Updated Homebrew from #{shorten_revision(initial_revision)} to #{shorten_revision(current_revision)}." ohai "Updated Homebrew from #{shorten_revision(initial_revision)} " \
"to #{shorten_revision(current_revision)}."
elsif old_tag.blank? elsif old_tag.blank?
ohai "Updated Homebrew from #{shorten_revision(initial_revision)} " \ ohai "Updated Homebrew from #{shorten_revision(initial_revision)} " \
"to #{new_tag} (#{shorten_revision(current_revision)})." "to #{new_tag} (#{shorten_revision(current_revision)})."
@ -219,8 +218,9 @@ module Homebrew
end end
unless updated_taps.empty? unless updated_taps.empty?
auto_update_header(args:) auto_update_header
puts "Updated #{Utils.pluralize("tap", updated_taps.count, include_count: true)} (#{updated_taps.to_sentence})." puts "Updated #{Utils.pluralize("tap", updated_taps.count,
include_count: true)} (#{updated_taps.to_sentence})."
updated = true updated = true
end end
@ -408,6 +408,8 @@ module Homebrew
Settings.write "installfromapimessage", true if $stdout.tty? Settings.write "installfromapimessage", true if $stdout.tty?
end end
end end
end
end
require "extend/os/cmd/update-report" require "extend/os/cmd/update-report"

View File

@ -5,7 +5,7 @@ require "formula_versions"
require "yaml" require "yaml"
require "cmd/shared_examples/args_parse" require "cmd/shared_examples/args_parse"
RSpec.describe "brew update-report" do RSpec.describe Homebrew::Cmd::UpdateReport do
it_behaves_like "parseable arguments" it_behaves_like "parseable arguments"
describe Reporter do describe Reporter do