Class: Homebrew::Cmd::UninstallCmd Private

Inherits:
AbstractCommand show all
Defined in:
cmd/uninstall.rb,
sorbet/rbi/dsl/homebrew/cmd/uninstall_cmd.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_outside_github_actions, #opoo_without_github_actions_annotation, #pretty_deprecated, #pretty_disabled, #pretty_duration, #pretty_install_status, #pretty_installed, #pretty_outdated, #pretty_uninstalled, #pretty_upgradable

Constructor Details

This class inherits a constructor from Homebrew::AbstractCommand

Instance Method Details

#argsHomebrew::Cmd::UninstallCmd::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/uninstall_cmd.rbi', line 10

def args; end

#runvoid

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.



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
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
# File 'cmd/uninstall.rb', line 44

def run
  method = args.force? ? :kegs : :default_kegs
  results = args.named.to_formulae_and_casks_and_unavailable(method:)

  unavailable_errors = T.let([], T::Array[T.any(FormulaOrCaskUnavailableError, NoSuchKegError)])
  all_kegs = T.let([], T::Array[Keg])
  casks = T.let([], T::Array[Cask::Cask])
  trusted_items_to_remove = T.let([], T::Array[[Symbol, String]])

  results.each do |item|
    case item
    when FormulaOrCaskUnavailableError, NoSuchKegError
      unavailable_errors << item
    when Cask::Cask
      casks << item
      trusted_items_to_remove << [:cask, item.full_name]
    when Keg
      all_kegs << item
      single_keg_tap = item.tab.tap
      trusted_items_to_remove << [:formula, "#{single_keg_tap.name}/#{item.name}"] if single_keg_tap
    when Array
      all_kegs += item
      item.each do |keg|
        array_keg_tap = keg.tab.tap
        trusted_items_to_remove << [:formula, "#{array_keg_tap.name}/#{keg.name}"] if array_keg_tap
      end
    end
  end

  return if all_kegs.blank? && casks.blank? && unavailable_errors.blank?

  kegs_by_rack = all_kegs.group_by(&:rack)

  Uninstall.uninstall_kegs(
    kegs_by_rack,
    casks:,
    force:               args.force?,
    ignore_dependencies: args.ignore_dependencies?,
    named_args:          args.named,
  )

  Cask::Uninstall.check_dependent_casks(*casks, named_args: args.named) unless args.ignore_dependencies?

  return if Homebrew.failed?

  begin
    if args.zap?
      caught_exceptions = []

      casks.each do |cask|
        odebug "Zapping Cask #{cask}"

        raise Cask::CaskNotInstalledError, cask if !cask.installed? && !args.force?

        next unless Cask::Uninstall.unpin_for_removal?(cask, force: args.force?)

        Cask::Installer.new(cask, verbose: args.verbose?, force: args.force?).zap
      rescue => e
        caught_exceptions << e
        next
      end

      if caught_exceptions.count > 1
        raise Cask::MultipleCaskErrors, caught_exceptions
      elsif caught_exceptions.one?
        raise caught_exceptions.fetch(0)
      end
    else
      Cask::Uninstall.uninstall_casks(
        *casks,
        verbose: args.verbose?,
        force:   args.force?,
      )
    end
  rescue => e
    ofail e
  end

  trusted_items_to_remove.uniq.each do |type, name|
    next unless (tap_name = Utils.tap_from_full_name(name))
    next if Homebrew::Trust.trusted?(:tap, tap_name)

    Homebrew::Trust.untrust!(type, name)
  end

  if ENV["HOMEBREW_AUTOREMOVE"].present?
    opoo "`$HOMEBREW_AUTOREMOVE` is now a no-op as it is the default behaviour. " \
         "Set `HOMEBREW_NO_AUTOREMOVE=1` to disable it."
  end
  Cleanup.autoremove unless Homebrew::EnvConfig.no_autoremove?

  unavailable_errors.each { |e| ofail e } unless args.force?
end