Class: Homebrew::Cmd::Untap Private

Inherits:
AbstractCommand show all
Defined in:
cmd/untap.rb,
sorbet/rbi/dsl/homebrew/cmd/untap.rbi

This class is part of a private API. This class may only be used in the Homebrew/brew repository. Third parties should avoid using this class if possible, as it may be removed or changed without warning.

Defined Under Namespace

Classes: Args

Instance Method Summary collapse

Methods inherited from AbstractCommand

command, command_name, dev_cmd?, #initialize, parser, ruby_cmd?

Methods included from Utils::Output::Mixin

#issue_reporting_message, #odebug, #odeprecated, #odie, #odisabled, #ofail, #oh1, #oh1_title, #ohai, #ohai_title, #onoe, #opoo, #opoo_once, #opoo_outside_github_actions, #opoo_without_github_actions_annotation, #pretty_cannot_install, #pretty_deprecated, #pretty_disabled, #pretty_duration, #pretty_incompatible, #pretty_install_status, #pretty_installed, #pretty_removed, #pretty_uninstalled, #pretty_unmarked, #pretty_upgradable, #pretty_warning

Constructor Details

This class inherits a constructor from Homebrew::AbstractCommand

Instance Method Details

#args ⇒ Homebrew::Cmd::Untap::Args

This method is part of a private API. This method may only be used in the Homebrew/brew repository. Third parties should avoid using this method if possible, as it may be removed or changed without warning.



10
# File 'sorbet/rbi/dsl/homebrew/cmd/untap.rbi', line 10

def args; end

#installed_casks_for(tap:) ⇒ Array<Cask::Cask>

This method is part of a private API. This method may only be used in the Homebrew/brew repository. Third parties should avoid using this method if possible, as it may be removed or changed without warning.

All installed casks currently available in a tap by cask full name.

Parameters:

Returns:



130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
# File 'cmd/untap.rb', line 130

def installed_casks_for(tap:)
  require "cask/cask_loader"
  tap.cask_tokens.filter_map do |cask_token|
    token = Utils.name_from_full_name(cask_token)
    next unless installed_cask_tokens.include?(token)

    installed_tap = Cask::CaskLoader.load_installed_tab(token).tap
    next if installed_tap && installed_tap != tap

    cask = begin
      Cask::CaskLoader.load(cask_token)
    rescue Homebrew::UntrustedTapError
      next unless (installed_version = Cask::Caskroom.cask_installed_version(token))
      raise if installed_tap != tap

      # The uninstaller reads the recorded artifacts after confirmation.
      Cask::Cask.new(token, tap:) { version installed_version }
    rescue Cask::CaskUnavailableError, MethodDeprecatedError
      # Don't blow up because of a single unavailable cask or a deprecated method.
      next
    end

    cask if cask.installed? && cask.tab.tap == tap
  end
end

#installed_formulae_for(tap:) ⇒ Hash{String => Array<Keg>}

This method is part of a private API. This method may only be used in the Homebrew/brew repository. Third parties should avoid using this method if possible, as it may be removed or changed without warning.

Installed kegs for formulae currently available in a tap, keyed by formula full name.

Parameters:

Returns:



113
114
115
116
117
118
119
120
121
122
123
124
125
126
# File 'cmd/untap.rb', line 113

def installed_formulae_for(tap:)
  tap.formula_names.filter_map do |formula_name|
    name = Utils.name_from_full_name(formula_name)
    possible_names = [name, *tap.formula_reverse_renames.fetch(name, [])]
    next unless possible_names.any? { |possible_name| installed_formulae_names.include?(possible_name) }

    possible_names.concat(tap.alias_reverse_table.fetch(formula_name, []),
                          Tap.tap_migration_oldnames(tap, name))
    kegs = Utils::Path.formula_installed_prefixes(possible_names).filter_map do |path|
      Keg.new(path) if Tab.for_keg(path).tap == tap
    end
    [formula_name, kegs] if kegs.present?
  end.to_h
end

#run ⇒ void

This method is part of a private API. This method may only be used in the Homebrew/brew repository. Third parties should avoid using this method if possible, as it may be removed or changed without warning.

This method returns an undefined value.



25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
# File 'cmd/untap.rb', line 25

def run
  taps = begin
    args.named.to_installed_taps
  rescue Tap::InvalidNameError => e
    odie e.message
  end

  taps.each do |tap|
    if tap.core_tap? && Homebrew::EnvConfig.no_install_from_api?
      ofail "Untapping #{tap} is not allowed"
      next
    end

    installed_tap_formulae, installed_tap_casks = if Homebrew::EnvConfig.no_install_from_api? ||
                                                     (!tap.core_tap? && !tap.core_cask_tap?)
      [installed_formulae_for(tap:), installed_casks_for(tap:)]
    else
      [{}, []]
    end

    if installed_tap_formulae.blank? && installed_tap_casks.blank?
      tap.uninstall manual: true
      next
    end

    installed_formulae_names = installed_tap_formulae.keys
    installed_cask_names = installed_tap_casks.map(&:full_name)
    installed_package_types = if installed_formulae_names.empty?
      "casks"
    elsif installed_cask_names.empty?
      "formulae"
    else
      "formulae and casks"
    end
    installed_names = (installed_formulae_names + installed_cask_names).join("\n")
    if Homebrew::EnvConfig.developer? && !args.force?
      opoo <<~EOS
        Untapping #{tap} even though it contains the following installed #{installed_package_types}:
        #{installed_names}
      EOS
    else
      unless args.force?
        ohai "Would untap #{tap} after uninstalling the following #{installed_package_types}:"
        puts installed_names
        confirmed = begin
          Homebrew::Ask.confirm?(action: "changes")
        rescue SystemExit
          false
        end
        unless confirmed
          ofail <<~EOS
            Refusing to untap #{tap} because it contains the following installed #{installed_package_types}:
            #{installed_names}
          EOS
          next
        end
      end

      named_args = installed_formulae_names + installed_cask_names
      kegs_by_rack = installed_tap_formulae.values.flatten(1).group_by(&:rack)

      Cask::Uninstall.check_dependent_casks(*installed_tap_casks, named_args:)
      next if Homebrew.failed?

      Formulary.with_context(tolerate_formula_load_errors: true) do
        Uninstall.uninstall_kegs(kegs_by_rack, casks: installed_tap_casks, force: args.force?, named_args:)
      end
      next if Homebrew.failed?

      begin
        Cask::Uninstall.uninstall_casks(*installed_tap_casks, force: args.force?)
      rescue
        ofail $ERROR_INFO
        next
      end

      if installed_formulae_for(tap:).present? || installed_casks_for(tap:).present?
        ofail "Failed to fully uninstall #{installed_package_types} from #{tap}"
        next
      end
    end

    tap.uninstall manual: true
  end
end