Class: Cask::Cmd::Uninstall Private

Inherits:
AbstractCommand show all
Defined in:
Library/Homebrew/cask/cmd/uninstall.rb

Overview

This class is part of a private API. You should avoid using this class if possible, as it may be removed or be changed in the future.

Implementation of the brew cask uninstall command.

Constant Summary

Constants inherited from AbstractCommand

AbstractCommand::OPTIONS

Instance Attribute Summary

Attributes inherited from AbstractCommand

#args

Class Method Summary collapse

Instance Method Summary collapse

Methods inherited from AbstractCommand

abstract?, banner_args, banner_headline, command_name, help, #initialize, max_named, run, short_description, visible?

Methods included from Homebrew::Search

#query_regexp, #search_casks, #search_descriptions, #search_formulae, #search_taps

Constructor Details

This class inherits a constructor from Cask::Cmd::AbstractCommand

Class Method Details

.descriptionObject

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.


14
15
16
# File 'Library/Homebrew/cask/cmd/uninstall.rb', line 14

def self.description
  "Uninstalls the given <cask>."
end

.min_namedObject

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.


10
11
12
# File 'Library/Homebrew/cask/cmd/uninstall.rb', line 10

def self.min_named
  :cask
end

.parserObject

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.


18
19
20
21
22
23
24
# File 'Library/Homebrew/cask/cmd/uninstall.rb', line 18

def self.parser
  super do
    switch "--force",
           description: "Uninstall even if the <cask> is not installed, overwrite " \
                        "existing files and ignore errors when removing files."
  end
end

.uninstall_casks(*casks, binaries: nil, force: false, verbose: false) ⇒ Object

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.


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
# File 'Library/Homebrew/cask/cmd/uninstall.rb', line 35

def self.uninstall_casks(*casks, binaries: nil, force: false, verbose: false)
  require "cask/installer"

  options = {
    binaries: binaries,
    force:    force,
    verbose:  verbose,
  }.compact

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

    if cask.installed?
      if (installed_caskfile = cask.installed_caskfile) && installed_caskfile.exist?
        # Use the same cask file that was used for installation, if possible.
        cask = CaskLoader.load(installed_caskfile)
      end
    else
      raise CaskNotInstalledError, cask unless force
    end

    Installer.new(cask, **options).uninstall

    next if (versions = cask.versions).empty?

    puts <<~EOS
      #{cask} #{versions.to_sentence} #{"is".pluralize(versions.count)} still installed.
      Remove #{(versions.count == 1) ? "it" : "them all"} with `brew cask uninstall --force #{cask}`.
    EOS
  end
end

Instance Method Details

#runObject

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.


26
27
28
29
30
31
32
33
# File 'Library/Homebrew/cask/cmd/uninstall.rb', line 26

def run
  self.class.uninstall_casks(
    *casks,
    binaries: args.binaries?,
    verbose:  args.verbose?,
    force:    args.force?,
  )
end