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
# frozen_string_literal: true
require "abstract_command"
require "migrator"
require "formulary"
require "cask/cask_loader"
@ -8,23 +9,13 @@ require "cask/migrator"
require "descriptions"
require "cleanup"
require "description_cache_store"
require "cli/parser"
require "settings"
require "linuxbrew-core-migration"
module Homebrew
module_function
def auto_update_header(args:)
@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
module Cmd
class UpdateReport < AbstractCommand
cmd_args do
description <<~EOS
The Ruby implementation of `brew update`. Never called manually.
EOS
@ -36,9 +27,9 @@ module Homebrew
hide_from_man_page!
end
end
def update_report
sig { override.void }
def run
return output_update_report if $stdout.tty?
redirect_stdout($stderr) do
@ -46,9 +37,16 @@ module Homebrew
end
end
def output_update_report
args = update_report_args.parse
private
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
if CoreTap.instance.installed? && CoreTap.instance.linuxbrew_core? &&
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?
if initial_revision != current_revision
auto_update_header(args:)
auto_update_header
updated = true
@ -122,7 +120,8 @@ module Homebrew
Settings.write "latesttag", new_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?
ohai "Updated Homebrew from #{shorten_revision(initial_revision)} " \
"to #{new_tag} (#{shorten_revision(current_revision)})."
@ -219,8 +218,9 @@ module Homebrew
end
unless updated_taps.empty?
auto_update_header(args:)
puts "Updated #{Utils.pluralize("tap", updated_taps.count, include_count: true)} (#{updated_taps.to_sentence})."
auto_update_header
puts "Updated #{Utils.pluralize("tap", updated_taps.count,
include_count: true)} (#{updated_taps.to_sentence})."
updated = true
end
@ -408,6 +408,8 @@ module Homebrew
Settings.write "installfromapimessage", true if $stdout.tty?
end
end
end
end
require "extend/os/cmd/update-report"

View File

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