mirror of
https://github.com/Homebrew/brew.git
synced 2025-07-14 16:09:03 +08:00
cmd: set typed: strict
This commit is contained in:
parent
09eaf1495a
commit
c4c66d41ef
@ -1,4 +1,4 @@
|
|||||||
# typed: true # rubocop:todo Sorbet/StrictSigil
|
# typed: strict
|
||||||
# frozen_string_literal: true
|
# frozen_string_literal: true
|
||||||
|
|
||||||
require "abstract_command"
|
require "abstract_command"
|
||||||
@ -6,6 +6,7 @@ require "formula"
|
|||||||
require "fetch"
|
require "fetch"
|
||||||
require "cask/download"
|
require "cask/download"
|
||||||
require "retryable_download"
|
require "retryable_download"
|
||||||
|
require "download_queue"
|
||||||
|
|
||||||
module Homebrew
|
module Homebrew
|
||||||
module Cmd
|
module Cmd
|
||||||
@ -69,15 +70,16 @@ module Homebrew
|
|||||||
named_args [:formula, :cask], min: 1
|
named_args [:formula, :cask], min: 1
|
||||||
end
|
end
|
||||||
|
|
||||||
|
sig { returns(Integer) }
|
||||||
def concurrency
|
def concurrency
|
||||||
@concurrency ||= args.concurrency&.to_i || 1
|
@concurrency ||= T.let(args.concurrency&.to_i || 1, T.nilable(Integer))
|
||||||
end
|
end
|
||||||
|
|
||||||
|
sig { returns(DownloadQueue) }
|
||||||
def download_queue
|
def download_queue
|
||||||
@download_queue ||= begin
|
@download_queue ||= T.let(begin
|
||||||
require "download_queue"
|
|
||||||
DownloadQueue.new(concurrency)
|
DownloadQueue.new(concurrency)
|
||||||
end
|
end, T.nilable(DownloadQueue))
|
||||||
end
|
end
|
||||||
|
|
||||||
class Spinner
|
class Spinner
|
||||||
@ -96,8 +98,8 @@ module Homebrew
|
|||||||
|
|
||||||
sig { void }
|
sig { void }
|
||||||
def initialize
|
def initialize
|
||||||
@start = Time.now
|
@start = T.let(Time.now, Time)
|
||||||
@i = 0
|
@i = T.let(0, Integer)
|
||||||
end
|
end
|
||||||
|
|
||||||
sig { returns(String) }
|
sig { returns(String) }
|
||||||
@ -136,7 +138,7 @@ module Homebrew
|
|||||||
bucket.each do |formula_or_cask|
|
bucket.each do |formula_or_cask|
|
||||||
case formula_or_cask
|
case formula_or_cask
|
||||||
when Formula
|
when Formula
|
||||||
formula = T.cast(formula_or_cask, Formula)
|
formula = formula_or_cask
|
||||||
ref = formula.loaded_from_api? ? formula.full_name : formula.path
|
ref = formula.loaded_from_api? ? formula.full_name : formula.path
|
||||||
|
|
||||||
os_arch_combinations.each do |os, arch|
|
os_arch_combinations.each do |os, arch|
|
||||||
@ -189,7 +191,9 @@ module Homebrew
|
|||||||
|
|
||||||
next if fetched_bottle
|
next if fetched_bottle
|
||||||
|
|
||||||
fetch_downloadable(formula.resource)
|
if (resource = formula.resource)
|
||||||
|
fetch_downloadable(resource)
|
||||||
|
end
|
||||||
|
|
||||||
formula.resources.each do |r|
|
formula.resources.each do |r|
|
||||||
fetch_downloadable(r)
|
fetch_downloadable(r)
|
||||||
@ -231,7 +235,7 @@ module Homebrew
|
|||||||
end
|
end
|
||||||
else
|
else
|
||||||
spinner = Spinner.new
|
spinner = Spinner.new
|
||||||
remaining_downloads = downloads.dup
|
remaining_downloads = downloads.dup.to_a
|
||||||
previous_pending_line_count = 0
|
previous_pending_line_count = 0
|
||||||
|
|
||||||
begin
|
begin
|
||||||
@ -332,10 +336,13 @@ module Homebrew
|
|||||||
|
|
||||||
private
|
private
|
||||||
|
|
||||||
|
sig { returns(T::Hash[T.any(Resource, Bottle, Cask::Download), Concurrent::Promises::Future]) }
|
||||||
def downloads
|
def downloads
|
||||||
@downloads ||= {}
|
@downloads ||= T.let({}, T.nilable(T::Hash[T.any(Resource, Bottle, Cask::Download),
|
||||||
|
Concurrent::Promises::Future]))
|
||||||
end
|
end
|
||||||
|
|
||||||
|
sig { params(downloadable: T.any(Resource, Bottle, Cask::Download)).void }
|
||||||
def fetch_downloadable(downloadable)
|
def fetch_downloadable(downloadable)
|
||||||
downloads[downloadable] ||= begin
|
downloads[downloadable] ||= begin
|
||||||
tries = args.retry? ? {} : { tries: 1 }
|
tries = args.retry? ? {} : { tries: 1 }
|
||||||
|
@ -1,4 +1,4 @@
|
|||||||
# typed: true # rubocop:todo Sorbet/StrictSigil
|
# typed: strict
|
||||||
# frozen_string_literal: true
|
# frozen_string_literal: true
|
||||||
|
|
||||||
require "abstract_command"
|
require "abstract_command"
|
||||||
@ -18,7 +18,7 @@ module Homebrew
|
|||||||
class Info < AbstractCommand
|
class Info < AbstractCommand
|
||||||
VALID_DAYS = %w[30 90 365].freeze
|
VALID_DAYS = %w[30 90 365].freeze
|
||||||
VALID_FORMULA_CATEGORIES = %w[install install-on-request build-error].freeze
|
VALID_FORMULA_CATEGORIES = %w[install install-on-request build-error].freeze
|
||||||
VALID_CATEGORIES = (VALID_FORMULA_CATEGORIES + %w[cask-install os-version]).freeze
|
VALID_CATEGORIES = T.let((VALID_FORMULA_CATEGORIES + %w[cask-install os-version]).freeze, T::Array[String])
|
||||||
|
|
||||||
cmd_args do
|
cmd_args do
|
||||||
description <<~EOS
|
description <<~EOS
|
||||||
@ -96,14 +96,17 @@ module Homebrew
|
|||||||
end
|
end
|
||||||
|
|
||||||
print_analytics
|
print_analytics
|
||||||
elsif args.json
|
elsif (json = args.json)
|
||||||
all = args.eval_all?
|
all = args.eval_all?
|
||||||
|
|
||||||
print_json(all)
|
print_json(json, all)
|
||||||
elsif args.github?
|
elsif args.github?
|
||||||
raise FormulaOrCaskUnspecifiedError if args.no_named?
|
raise FormulaOrCaskUnspecifiedError if args.no_named?
|
||||||
|
|
||||||
exec_browser(*args.named.to_formulae_and_casks.map { |f| github_info(f) })
|
exec_browser(*args.named.to_formulae_and_casks.map do |formula_keg_or_cask|
|
||||||
|
formula_or_cask = T.cast(formula_keg_or_cask, T.any(Formula, Cask::Cask))
|
||||||
|
github_info(formula_or_cask)
|
||||||
|
end)
|
||||||
elsif args.no_named?
|
elsif args.no_named?
|
||||||
print_statistics
|
print_statistics
|
||||||
else
|
else
|
||||||
@ -111,6 +114,7 @@ module Homebrew
|
|||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
sig { params(remote: String, path: String).returns(String) }
|
||||||
def github_remote_path(remote, path)
|
def github_remote_path(remote, path)
|
||||||
if remote =~ %r{^(?:https?://|git(?:@|://))github\.com[:/](.+)/(.+?)(?:\.git)?$}
|
if remote =~ %r{^(?:https?://|git(?:@|://))github\.com[:/](.+)/(.+?)(?:\.git)?$}
|
||||||
"https://github.com/#{Regexp.last_match(1)}/#{Regexp.last_match(2)}/blob/HEAD/#{path}"
|
"https://github.com/#{Regexp.last_match(1)}/#{Regexp.last_match(2)}/blob/HEAD/#{path}"
|
||||||
@ -175,6 +179,7 @@ module Homebrew
|
|||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
sig { params(version: T.any(T::Boolean, String)).returns(Symbol) }
|
||||||
def json_version(version)
|
def json_version(version)
|
||||||
version_hash = {
|
version_hash = {
|
||||||
true => :default,
|
true => :default,
|
||||||
@ -187,11 +192,11 @@ module Homebrew
|
|||||||
version_hash[version]
|
version_hash[version]
|
||||||
end
|
end
|
||||||
|
|
||||||
sig { params(all: T::Boolean).void }
|
sig { params(json: T.any(T::Boolean, String), all: T::Boolean).void }
|
||||||
def print_json(all)
|
def print_json(json, all)
|
||||||
raise FormulaOrCaskUnspecifiedError if !(all || args.installed?) && args.no_named?
|
raise FormulaOrCaskUnspecifiedError if !(all || args.installed?) && args.no_named?
|
||||||
|
|
||||||
json = case json_version(args.json)
|
json = case json_version(json)
|
||||||
when :v1, :default
|
when :v1, :default
|
||||||
raise UsageError, "Cannot specify `--cask` when using `--json=v1`!" if args.cask?
|
raise UsageError, "Cannot specify `--cask` when using `--json=v1`!" if args.cask?
|
||||||
|
|
||||||
@ -240,25 +245,31 @@ module Homebrew
|
|||||||
puts JSON.pretty_generate(json)
|
puts JSON.pretty_generate(json)
|
||||||
end
|
end
|
||||||
|
|
||||||
|
sig { params(formula_or_cask: T.any(Formula, Cask::Cask)).returns(String) }
|
||||||
def github_info(formula_or_cask)
|
def github_info(formula_or_cask)
|
||||||
return formula_or_cask.path if formula_or_cask.tap.blank? || formula_or_cask.tap.remote.blank?
|
|
||||||
|
|
||||||
path = case formula_or_cask
|
path = case formula_or_cask
|
||||||
when Formula
|
when Formula
|
||||||
formula = formula_or_cask
|
formula = formula_or_cask
|
||||||
formula.path.relative_path_from(T.must(formula.tap).path)
|
tap = formula.tap
|
||||||
|
return formula.path.to_s if tap.blank? || tap.remote.blank?
|
||||||
|
|
||||||
|
formula.path.relative_path_from(tap.path)
|
||||||
when Cask::Cask
|
when Cask::Cask
|
||||||
cask = formula_or_cask
|
cask = formula_or_cask
|
||||||
|
tap = cask.tap
|
||||||
|
return cask.sourcefile_path.to_s if tap.blank? || tap.remote.blank?
|
||||||
|
|
||||||
if cask.sourcefile_path.blank? || cask.sourcefile_path.extname != ".rb"
|
if cask.sourcefile_path.blank? || cask.sourcefile_path.extname != ".rb"
|
||||||
return "#{cask.tap.default_remote}/blob/HEAD/#{cask.tap.relative_cask_path(cask.token)}"
|
return "#{tap.default_remote}/blob/HEAD/#{tap.relative_cask_path(cask.token)}"
|
||||||
end
|
end
|
||||||
|
|
||||||
cask.sourcefile_path.relative_path_from(cask.tap.path)
|
cask.sourcefile_path.relative_path_from(tap.path)
|
||||||
end
|
end
|
||||||
|
|
||||||
github_remote_path(formula_or_cask.tap.remote, path)
|
github_remote_path(tap.remote, path)
|
||||||
end
|
end
|
||||||
|
|
||||||
|
sig { params(formula: Formula).void }
|
||||||
def info_formula(formula)
|
def info_formula(formula)
|
||||||
specs = []
|
specs = []
|
||||||
|
|
||||||
@ -356,6 +367,7 @@ module Homebrew
|
|||||||
Utils::Analytics.formula_output(formula, args:)
|
Utils::Analytics.formula_output(formula, args:)
|
||||||
end
|
end
|
||||||
|
|
||||||
|
sig { params(dependencies: T::Array[Dependency]).returns(String) }
|
||||||
def decorate_dependencies(dependencies)
|
def decorate_dependencies(dependencies)
|
||||||
deps_status = dependencies.map do |dep|
|
deps_status = dependencies.map do |dep|
|
||||||
if dep.satisfied?([])
|
if dep.satisfied?([])
|
||||||
@ -367,6 +379,7 @@ module Homebrew
|
|||||||
deps_status.join(", ")
|
deps_status.join(", ")
|
||||||
end
|
end
|
||||||
|
|
||||||
|
sig { params(requirements: T::Array[Requirement]).returns(String) }
|
||||||
def decorate_requirements(requirements)
|
def decorate_requirements(requirements)
|
||||||
req_status = requirements.map do |req|
|
req_status = requirements.map do |req|
|
||||||
req_s = req.display_s
|
req_s = req.display_s
|
||||||
@ -375,12 +388,14 @@ module Homebrew
|
|||||||
req_status.join(", ")
|
req_status.join(", ")
|
||||||
end
|
end
|
||||||
|
|
||||||
|
sig { params(dep: Dependency).returns(String) }
|
||||||
def dep_display_s(dep)
|
def dep_display_s(dep)
|
||||||
return dep.name if dep.option_tags.empty?
|
return dep.name if dep.option_tags.empty?
|
||||||
|
|
||||||
"#{dep.name} #{dep.option_tags.map { |o| "--#{o}" }.join(" ")}"
|
"#{dep.name} #{dep.option_tags.map { |o| "--#{o}" }.join(" ")}"
|
||||||
end
|
end
|
||||||
|
|
||||||
|
sig { params(cask: Cask::Cask).void }
|
||||||
def info_cask(cask)
|
def info_cask(cask)
|
||||||
require "cask/info"
|
require "cask/info"
|
||||||
|
|
||||||
|
@ -1,4 +1,4 @@
|
|||||||
# typed: true # rubocop:todo Sorbet/StrictSigil
|
# typed: strict
|
||||||
# frozen_string_literal: true
|
# frozen_string_literal: true
|
||||||
|
|
||||||
require "abstract_command"
|
require "abstract_command"
|
||||||
@ -39,13 +39,15 @@ module Homebrew
|
|||||||
|
|
||||||
private
|
private
|
||||||
|
|
||||||
|
sig { void }
|
||||||
def auto_update_header
|
def auto_update_header
|
||||||
@auto_update_header ||= begin
|
@auto_update_header ||= T.let(begin
|
||||||
ohai "Auto-updated Homebrew!" if args.auto_update?
|
ohai "Auto-updated Homebrew!" if args.auto_update?
|
||||||
true
|
true
|
||||||
end
|
end, T.nilable(T::Boolean))
|
||||||
end
|
end
|
||||||
|
|
||||||
|
sig { void }
|
||||||
def output_update_report
|
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? &&
|
||||||
@ -293,14 +295,17 @@ module Homebrew
|
|||||||
EOS
|
EOS
|
||||||
end
|
end
|
||||||
|
|
||||||
|
sig { returns(String) }
|
||||||
def no_changes_message
|
def no_changes_message
|
||||||
"No changes to formulae or casks."
|
"No changes to formulae or casks."
|
||||||
end
|
end
|
||||||
|
|
||||||
|
sig { params(revision: String).returns(String) }
|
||||||
def shorten_revision(revision)
|
def shorten_revision(revision)
|
||||||
Utils.popen_read("git", "-C", HOMEBREW_REPOSITORY, "rev-parse", "--short", revision).chomp
|
Utils.popen_read("git", "-C", HOMEBREW_REPOSITORY, "rev-parse", "--short", revision).chomp
|
||||||
end
|
end
|
||||||
|
|
||||||
|
sig { void }
|
||||||
def tap_or_untap_core_taps_if_necessary
|
def tap_or_untap_core_taps_if_necessary
|
||||||
return if ENV["HOMEBREW_UPDATE_TEST"]
|
return if ENV["HOMEBREW_UPDATE_TEST"]
|
||||||
|
|
||||||
@ -340,6 +345,7 @@ module Homebrew
|
|||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
sig { params(repository: Pathname).void }
|
||||||
def link_completions_manpages_and_docs(repository = HOMEBREW_REPOSITORY)
|
def link_completions_manpages_and_docs(repository = HOMEBREW_REPOSITORY)
|
||||||
command = "brew update"
|
command = "brew update"
|
||||||
Utils::Link.link_completions(repository, command)
|
Utils::Link.link_completions(repository, command)
|
||||||
@ -352,10 +358,12 @@ module Homebrew
|
|||||||
EOS
|
EOS
|
||||||
end
|
end
|
||||||
|
|
||||||
|
sig { void }
|
||||||
def migrate_gcc_dependents_if_needed
|
def migrate_gcc_dependents_if_needed
|
||||||
# do nothing
|
# do nothing
|
||||||
end
|
end
|
||||||
|
|
||||||
|
sig { void }
|
||||||
def analytics_message
|
def analytics_message
|
||||||
return if Utils::Analytics.messages_displayed?
|
return if Utils::Analytics.messages_displayed?
|
||||||
return if Utils::Analytics.no_message_output?
|
return if Utils::Analytics.no_message_output?
|
||||||
@ -385,6 +393,7 @@ module Homebrew
|
|||||||
Utils::Analytics.messages_displayed! if $stdout.tty?
|
Utils::Analytics.messages_displayed! if $stdout.tty?
|
||||||
end
|
end
|
||||||
|
|
||||||
|
sig { void }
|
||||||
def donation_message
|
def donation_message
|
||||||
return if Settings.read("donationmessage") == "true"
|
return if Settings.read("donationmessage") == "true"
|
||||||
|
|
||||||
@ -395,6 +404,7 @@ module Homebrew
|
|||||||
Settings.write "donationmessage", true if $stdout.tty?
|
Settings.write "donationmessage", true if $stdout.tty?
|
||||||
end
|
end
|
||||||
|
|
||||||
|
sig { void }
|
||||||
def install_from_api_message
|
def install_from_api_message
|
||||||
return if Settings.read("installfromapimessage") == "true"
|
return if Settings.read("installfromapimessage") == "true"
|
||||||
|
|
||||||
@ -419,30 +429,38 @@ require "extend/os/cmd/update-report"
|
|||||||
|
|
||||||
class Reporter
|
class Reporter
|
||||||
class ReporterRevisionUnsetError < RuntimeError
|
class ReporterRevisionUnsetError < RuntimeError
|
||||||
|
sig { params(var_name: String).void }
|
||||||
def initialize(var_name)
|
def initialize(var_name)
|
||||||
super "#{var_name} is unset!"
|
super "#{var_name} is unset!"
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
sig {
|
||||||
|
params(tap: Tap, api_names_txt: T.nilable(Pathname), api_names_before_txt: T.nilable(Pathname),
|
||||||
|
api_dir_prefix: T.nilable(Pathname)).void
|
||||||
|
}
|
||||||
def initialize(tap, api_names_txt: nil, api_names_before_txt: nil, api_dir_prefix: nil)
|
def initialize(tap, api_names_txt: nil, api_names_before_txt: nil, api_dir_prefix: nil)
|
||||||
@tap = tap
|
@tap = tap
|
||||||
|
|
||||||
# This is slightly involved/weird but all the #report logic is shared so it's worth it.
|
# This is slightly involved/weird but all the #report logic is shared so it's worth it.
|
||||||
if installed_from_api?(api_names_txt, api_names_before_txt, api_dir_prefix)
|
if installed_from_api?(api_names_txt, api_names_before_txt, api_dir_prefix)
|
||||||
@api_names_txt = api_names_txt
|
@api_names_txt = T.let(api_names_txt, T.nilable(Pathname))
|
||||||
@api_names_before_txt = api_names_before_txt
|
@api_names_before_txt = T.let(api_names_before_txt, T.nilable(Pathname))
|
||||||
@api_dir_prefix = api_dir_prefix
|
@api_dir_prefix = T.let(api_dir_prefix, T.nilable(Pathname))
|
||||||
else
|
else
|
||||||
initial_revision_var = "HOMEBREW_UPDATE_BEFORE#{tap.repository_var_suffix}"
|
initial_revision_var = "HOMEBREW_UPDATE_BEFORE#{tap.repository_var_suffix}"
|
||||||
@initial_revision = ENV[initial_revision_var].to_s
|
@initial_revision = T.let(ENV[initial_revision_var].to_s, String)
|
||||||
raise ReporterRevisionUnsetError, initial_revision_var if @initial_revision.empty?
|
raise ReporterRevisionUnsetError, initial_revision_var if @initial_revision.empty?
|
||||||
|
|
||||||
current_revision_var = "HOMEBREW_UPDATE_AFTER#{tap.repository_var_suffix}"
|
current_revision_var = "HOMEBREW_UPDATE_AFTER#{tap.repository_var_suffix}"
|
||||||
@current_revision = ENV[current_revision_var].to_s
|
@current_revision = T.let(ENV[current_revision_var].to_s, String)
|
||||||
raise ReporterRevisionUnsetError, current_revision_var if @current_revision.empty?
|
raise ReporterRevisionUnsetError, current_revision_var if @current_revision.empty?
|
||||||
end
|
end
|
||||||
|
|
||||||
|
@report = T.let(nil, T.nilable(T::Hash[Symbol, T::Array[String]]))
|
||||||
end
|
end
|
||||||
|
|
||||||
|
sig { params(auto_update: T::Boolean).returns(T::Hash[Symbol, T::Array[String]]) }
|
||||||
def report(auto_update: false)
|
def report(auto_update: false)
|
||||||
return @report if @report
|
return @report if @report
|
||||||
|
|
||||||
@ -483,9 +501,9 @@ class Reporter
|
|||||||
case status
|
case status
|
||||||
when "A", "D"
|
when "A", "D"
|
||||||
full_name = tap.formula_file_to_name(src)
|
full_name = tap.formula_file_to_name(src)
|
||||||
name = full_name.split("/").last
|
name = T.must(full_name.split("/").last)
|
||||||
new_tap = tap.tap_migrations[name]
|
new_tap = tap.tap_migrations[name]
|
||||||
@report[status.to_sym] << full_name unless new_tap
|
@report[T.must(status).to_sym] << full_name unless new_tap
|
||||||
when "M"
|
when "M"
|
||||||
name = tap.formula_file_to_name(src)
|
name = tap.formula_file_to_name(src)
|
||||||
|
|
||||||
@ -585,6 +603,7 @@ class Reporter
|
|||||||
@report
|
@report
|
||||||
end
|
end
|
||||||
|
|
||||||
|
sig { returns(T::Boolean) }
|
||||||
def updated?
|
def updated?
|
||||||
if installed_from_api?
|
if installed_from_api?
|
||||||
diff.present?
|
diff.present?
|
||||||
@ -593,9 +612,10 @@ class Reporter
|
|||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
sig { void }
|
||||||
def migrate_tap_migration
|
def migrate_tap_migration
|
||||||
(report[:D] + report[:DC]).each do |full_name|
|
(Array(report[:D]) + Array(report[:DC])).each do |full_name|
|
||||||
name = full_name.split("/").last
|
name = T.must(full_name.split("/").last)
|
||||||
new_tap_name = tap.tap_migrations[name]
|
new_tap_name = tap.tap_migrations[name]
|
||||||
next if new_tap_name.nil? # skip if not in tap_migrations list.
|
next if new_tap_name.nil? # skip if not in tap_migrations list.
|
||||||
|
|
||||||
@ -610,7 +630,7 @@ class Reporter
|
|||||||
end
|
end
|
||||||
|
|
||||||
# This means it is a cask
|
# This means it is a cask
|
||||||
if report[:DC].include? full_name
|
if Array(report[:DC]).include? full_name
|
||||||
next unless (HOMEBREW_PREFIX/"Caskroom"/new_name).exist?
|
next unless (HOMEBREW_PREFIX/"Caskroom"/new_name).exist?
|
||||||
|
|
||||||
new_tap = Tap.fetch(new_tap_name)
|
new_tap = Tap.fetch(new_tap_name)
|
||||||
@ -676,12 +696,14 @@ class Reporter
|
|||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
sig { void }
|
||||||
def migrate_cask_rename
|
def migrate_cask_rename
|
||||||
Cask::Caskroom.casks.each do |cask|
|
Cask::Caskroom.casks.each do |cask|
|
||||||
Cask::Migrator.migrate_if_needed(cask)
|
Cask::Migrator.migrate_if_needed(cask)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
sig { params(force: T::Boolean, verbose: T::Boolean).void }
|
||||||
def migrate_formula_rename(force:, verbose:)
|
def migrate_formula_rename(force:, verbose:)
|
||||||
Formula.installed.each do |formula|
|
Formula.installed.each do |formula|
|
||||||
next unless Migrator.needs_migration?(formula)
|
next unless Migrator.needs_migration?(formula)
|
||||||
@ -705,14 +727,36 @@ class Reporter
|
|||||||
|
|
||||||
private
|
private
|
||||||
|
|
||||||
attr_reader :tap, :initial_revision, :current_revision, :api_names_txt, :api_names_before_txt, :api_dir_prefix
|
sig { returns(Tap) }
|
||||||
|
attr_reader :tap
|
||||||
|
|
||||||
|
sig { returns(String) }
|
||||||
|
attr_reader :initial_revision
|
||||||
|
|
||||||
|
sig { returns(String) }
|
||||||
|
attr_reader :current_revision
|
||||||
|
|
||||||
|
sig { returns(T.nilable(Pathname)) }
|
||||||
|
attr_reader :api_names_txt
|
||||||
|
|
||||||
|
sig { returns(T.nilable(Pathname)) }
|
||||||
|
attr_reader :api_names_before_txt
|
||||||
|
|
||||||
|
sig { returns(T.nilable(Pathname)) }
|
||||||
|
attr_reader :api_dir_prefix
|
||||||
|
|
||||||
|
sig {
|
||||||
|
params(api_names_txt: T.nilable(Pathname), api_names_before_txt: T.nilable(Pathname),
|
||||||
|
api_dir_prefix: T.nilable(Pathname)).returns(T::Boolean)
|
||||||
|
}
|
||||||
def installed_from_api?(api_names_txt = @api_names_txt, api_names_before_txt = @api_names_before_txt,
|
def installed_from_api?(api_names_txt = @api_names_txt, api_names_before_txt = @api_names_before_txt,
|
||||||
api_dir_prefix = @api_dir_prefix)
|
api_dir_prefix = @api_dir_prefix)
|
||||||
!api_names_txt.nil? && !api_names_before_txt.nil? && !api_dir_prefix.nil?
|
!api_names_txt.nil? && !api_names_before_txt.nil? && !api_dir_prefix.nil?
|
||||||
end
|
end
|
||||||
|
|
||||||
|
sig { returns(String) }
|
||||||
def diff
|
def diff
|
||||||
|
@diff ||= T.let(nil, T.nilable(String))
|
||||||
@diff ||= if installed_from_api?
|
@diff ||= if installed_from_api?
|
||||||
# Hack `git diff` output with regexes to look like `git diff-tree` output.
|
# Hack `git diff` output with regexes to look like `git diff-tree` output.
|
||||||
# Yes, I know this is a bit filthy but it saves duplicating the #report logic.
|
# Yes, I know this is a bit filthy but it saves duplicating the #report logic.
|
||||||
@ -720,12 +764,14 @@ class Reporter
|
|||||||
header_regex = /^(---|\+\+\+) /
|
header_regex = /^(---|\+\+\+) /
|
||||||
add_delete_characters = ["+", "-"].freeze
|
add_delete_characters = ["+", "-"].freeze
|
||||||
|
|
||||||
|
api_dir_prefix_basename = T.must(api_dir_prefix).basename
|
||||||
|
|
||||||
diff_output.lines.filter_map do |line|
|
diff_output.lines.filter_map do |line|
|
||||||
next if line.match?(header_regex)
|
next if line.match?(header_regex)
|
||||||
next unless add_delete_characters.include?(line[0])
|
next unless add_delete_characters.include?(line[0])
|
||||||
|
|
||||||
line.sub(/^\+/, "A #{api_dir_prefix.basename}/")
|
line.sub(/^\+/, "A #{api_dir_prefix_basename}/")
|
||||||
.sub(/^-/, "D #{api_dir_prefix.basename}/")
|
.sub(/^-/, "D #{api_dir_prefix_basename}/")
|
||||||
.sub(/$/, ".rb")
|
.sub(/$/, ".rb")
|
||||||
.chomp
|
.chomp
|
||||||
end.join("\n")
|
end.join("\n")
|
||||||
@ -739,28 +785,33 @@ class Reporter
|
|||||||
end
|
end
|
||||||
|
|
||||||
class ReporterHub
|
class ReporterHub
|
||||||
|
sig { returns(T::Array[Reporter]) }
|
||||||
attr_reader :reporters
|
attr_reader :reporters
|
||||||
|
|
||||||
sig { void }
|
sig { void }
|
||||||
def initialize
|
def initialize
|
||||||
@hash = {}
|
@hash = T.let({}, T::Hash[Symbol, T::Array[String]])
|
||||||
@reporters = []
|
@reporters = T.let([], T::Array[Reporter])
|
||||||
end
|
end
|
||||||
|
|
||||||
|
sig { params(key: Symbol).returns(T::Array[String]) }
|
||||||
def select_formula_or_cask(key)
|
def select_formula_or_cask(key)
|
||||||
@hash.fetch(key, [])
|
@hash.fetch(key, [])
|
||||||
end
|
end
|
||||||
|
|
||||||
|
sig { params(reporter: Reporter, auto_update: T::Boolean).void }
|
||||||
def add(reporter, auto_update: false)
|
def add(reporter, auto_update: false)
|
||||||
@reporters << reporter
|
@reporters << reporter
|
||||||
report = reporter.report(auto_update:).delete_if { |_k, v| v.empty? }
|
report = reporter.report(auto_update:).delete_if { |_k, v| v.empty? }
|
||||||
@hash.update(report) { |_key, oldval, newval| oldval.concat(newval) }
|
@hash.update(report) { |_key, oldval, newval| oldval.concat(newval) }
|
||||||
end
|
end
|
||||||
|
|
||||||
|
sig { returns(T::Boolean) }
|
||||||
def empty?
|
def empty?
|
||||||
@hash.empty?
|
@hash.empty?
|
||||||
end
|
end
|
||||||
|
|
||||||
|
sig { params(auto_update: T::Boolean).void }
|
||||||
def dump(auto_update: false)
|
def dump(auto_update: false)
|
||||||
unless Homebrew::EnvConfig.no_update_report_new?
|
unless Homebrew::EnvConfig.no_update_report_new?
|
||||||
dump_new_formula_report
|
dump_new_formula_report
|
||||||
@ -815,12 +866,14 @@ class ReporterHub
|
|||||||
|
|
||||||
private
|
private
|
||||||
|
|
||||||
|
sig { void }
|
||||||
def dump_new_formula_report
|
def dump_new_formula_report
|
||||||
formulae = select_formula_or_cask(:A).sort.reject { |name| installed?(name) }
|
formulae = select_formula_or_cask(:A).sort.reject { |name| installed?(name) }
|
||||||
|
|
||||||
output_dump_formula_or_cask_report "New Formulae", formulae
|
output_dump_formula_or_cask_report "New Formulae", formulae
|
||||||
end
|
end
|
||||||
|
|
||||||
|
sig { void }
|
||||||
def dump_new_cask_report
|
def dump_new_cask_report
|
||||||
return if Homebrew::SimulateSystem.simulating_or_running_on_linux?
|
return if Homebrew::SimulateSystem.simulating_or_running_on_linux?
|
||||||
|
|
||||||
@ -831,6 +884,7 @@ class ReporterHub
|
|||||||
output_dump_formula_or_cask_report "New Casks", casks
|
output_dump_formula_or_cask_report "New Casks", casks
|
||||||
end
|
end
|
||||||
|
|
||||||
|
sig { void }
|
||||||
def dump_deleted_formula_report
|
def dump_deleted_formula_report
|
||||||
formulae = select_formula_or_cask(:D).sort.filter_map do |name|
|
formulae = select_formula_or_cask(:D).sort.filter_map do |name|
|
||||||
pretty_uninstalled(name) if installed?(name)
|
pretty_uninstalled(name) if installed?(name)
|
||||||
@ -839,37 +893,43 @@ class ReporterHub
|
|||||||
output_dump_formula_or_cask_report "Deleted Installed Formulae", formulae
|
output_dump_formula_or_cask_report "Deleted Installed Formulae", formulae
|
||||||
end
|
end
|
||||||
|
|
||||||
|
sig { void }
|
||||||
def dump_deleted_cask_report
|
def dump_deleted_cask_report
|
||||||
return if Homebrew::SimulateSystem.simulating_or_running_on_linux?
|
return if Homebrew::SimulateSystem.simulating_or_running_on_linux?
|
||||||
|
|
||||||
casks = select_formula_or_cask(:DC).sort.filter_map do |name|
|
casks = select_formula_or_cask(:DC).sort.filter_map do |name|
|
||||||
name = name.split("/").last
|
name = T.must(name.split("/").last)
|
||||||
pretty_uninstalled(name) if cask_installed?(name)
|
pretty_uninstalled(name) if cask_installed?(name)
|
||||||
end
|
end
|
||||||
|
|
||||||
output_dump_formula_or_cask_report "Deleted Installed Casks", casks
|
output_dump_formula_or_cask_report "Deleted Installed Casks", casks
|
||||||
end
|
end
|
||||||
|
|
||||||
|
sig { params(title: String, formulae_or_casks: T::Array[String]).void }
|
||||||
def output_dump_formula_or_cask_report(title, formulae_or_casks)
|
def output_dump_formula_or_cask_report(title, formulae_or_casks)
|
||||||
return if formulae_or_casks.blank?
|
return if formulae_or_casks.blank?
|
||||||
|
|
||||||
ohai title, Formatter.columns(formulae_or_casks.sort)
|
ohai title, Formatter.columns(formulae_or_casks.sort)
|
||||||
end
|
end
|
||||||
|
|
||||||
|
sig { params(formula: String).returns(T::Boolean) }
|
||||||
def installed?(formula)
|
def installed?(formula)
|
||||||
(HOMEBREW_CELLAR/formula.split("/").last).directory?
|
(HOMEBREW_CELLAR/formula.split("/").last).directory?
|
||||||
end
|
end
|
||||||
|
|
||||||
|
sig { params(formula: String).returns(T::Boolean) }
|
||||||
def outdated?(formula)
|
def outdated?(formula)
|
||||||
Formula[formula].outdated?
|
Formula[formula].outdated?
|
||||||
rescue FormulaUnavailableError
|
rescue FormulaUnavailableError
|
||||||
false
|
false
|
||||||
end
|
end
|
||||||
|
|
||||||
|
sig { params(cask: String).returns(T::Boolean) }
|
||||||
def cask_installed?(cask)
|
def cask_installed?(cask)
|
||||||
(Cask::Caskroom.path/cask).directory?
|
(Cask::Caskroom.path/cask).directory?
|
||||||
end
|
end
|
||||||
|
|
||||||
|
sig { params(cask: String).returns(T::Boolean) }
|
||||||
def cask_outdated?(cask)
|
def cask_outdated?(cask)
|
||||||
Cask::CaskLoader.load(cask).outdated?
|
Cask::CaskLoader.load(cask).outdated?
|
||||||
rescue Cask::CaskError
|
rescue Cask::CaskError
|
||||||
|
Loading…
x
Reference in New Issue
Block a user