2024-03-10 13:21:40 -07:00
|
|
|
# typed: true
|
|
|
|
# frozen_string_literal: true
|
|
|
|
|
2024-03-12 21:07:33 -07:00
|
|
|
require "extend/cachable"
|
|
|
|
|
2024-03-10 13:21:40 -07:00
|
|
|
module Homebrew
|
|
|
|
# Helpers for the `brew untap` command.
|
|
|
|
# @api private
|
|
|
|
module Untap
|
2024-03-12 21:07:33 -07:00
|
|
|
extend Cachable
|
|
|
|
|
2024-03-10 13:21:40 -07:00
|
|
|
# All installed formulae currently available in a tap by formula full name.
|
|
|
|
sig { params(tap: Tap).returns(T::Array[Formula]) }
|
|
|
|
def self.installed_formulae_for(tap:)
|
|
|
|
tap.formula_names.filter_map do |formula_name|
|
|
|
|
next unless installed_formulae_names.include?(T.must(formula_name.split("/").last))
|
|
|
|
|
|
|
|
formula = begin
|
|
|
|
Formulary.factory(formula_name)
|
2024-03-12 21:08:58 -07:00
|
|
|
rescue FormulaUnavailableError
|
2024-03-10 13:21:40 -07:00
|
|
|
# Don't blow up because of a single unavailable formula.
|
|
|
|
next
|
|
|
|
end
|
|
|
|
|
|
|
|
# Can't use Formula#any_version_installed? because it doesn't consider
|
|
|
|
# taps correctly.
|
|
|
|
formula if formula.installed_kegs.any? { |keg| keg.tab.tap == tap }
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
sig { returns(T::Set[String]) }
|
|
|
|
def self.installed_formulae_names
|
2024-03-12 21:07:33 -07:00
|
|
|
cache[:installed_formulae_names] ||= Formula.installed_formula_names.to_set.freeze
|
2024-03-10 13:21:40 -07:00
|
|
|
end
|
|
|
|
private_class_method :installed_formulae_names
|
|
|
|
|
|
|
|
# All installed casks currently available in a tap by cask full name.
|
|
|
|
sig { params(tap: Tap).returns(T::Array[Cask::Cask]) }
|
|
|
|
def self.installed_casks_for(tap:)
|
|
|
|
tap.cask_tokens.filter_map do |cask_token|
|
|
|
|
next unless installed_cask_tokens.include?(T.must(cask_token.split("/").last))
|
|
|
|
|
|
|
|
cask = begin
|
|
|
|
Cask::CaskLoader.load(cask_token)
|
2024-03-12 21:08:58 -07:00
|
|
|
rescue Cask::CaskUnavailableError
|
2024-03-10 13:21:40 -07:00
|
|
|
# Don't blow up because of a single unavailable cask.
|
|
|
|
next
|
|
|
|
end
|
|
|
|
|
|
|
|
cask if cask.installed?
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
sig { returns(T::Set[String]) }
|
|
|
|
def self.installed_cask_tokens
|
2024-03-12 21:07:33 -07:00
|
|
|
cache[:installed_cask_tokens] ||= Cask::Caskroom.tokens.to_set.freeze
|
2024-03-10 13:21:40 -07:00
|
|
|
end
|
|
|
|
private_class_method :installed_cask_tokens
|
|
|
|
end
|
|
|
|
end
|