Class: Cask::Cmd::List Private

Inherits:
AbstractCommand show all
Defined in:
Library/Homebrew/cask/cmd/list.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 list 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, min_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.


12
13
14
# File 'Library/Homebrew/cask/cmd/list.rb', line 12

def self.description
  "Lists installed casks or the casks provided in the arguments."
end

.format_versioned(cask) ⇒ 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.


78
79
80
# File 'Library/Homebrew/cask/cmd/list.rb', line 78

def self.format_versioned(cask)
  cask.to_s.concat(cask.versions.map(&:to_s).join(" ").prepend(" "))
end

.list_artifacts(cask) ⇒ 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.


64
65
66
67
68
69
70
71
72
73
74
75
76
# File 'Library/Homebrew/cask/cmd/list.rb', line 64

def self.list_artifacts(cask)
  cask.artifacts.group_by(&:class).sort_by { |klass, _| klass.english_name }.each do |klass, artifacts|
    next if [Artifact::Uninstall, Artifact::Zap].include? klass

    ohai klass.english_name
    artifacts.each do |artifact|
      puts artifact.summarize_installed if artifact.respond_to?(:summarize_installed)
      next if artifact.respond_to?(:summarize_installed)

      puts artifact
    end
  end
end

.list_casks(*casks, args:, json: false, one: false, full_name: false, versions: 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.


40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
# File 'Library/Homebrew/cask/cmd/list.rb', line 40

def self.list_casks(*casks, args:, json: false, one: false, full_name: false, versions: false)
  output = if casks.any?
    casks.each do |cask|
      raise CaskNotInstalledError, cask unless cask.installed?
    end
  else
    Caskroom.casks(config: Config.from_args(args))
  end

  if json
    puts JSON.generate(output.map(&:to_h))
  elsif one
    puts output.map(&:to_s)
  elsif full_name
    puts output.map(&:full_name).sort(&tap_and_name_comparison)
  elsif versions
    puts output.map(&method(:format_versioned))
  elsif !output.empty? && casks.any?
    output.map(&method(:list_artifacts))
  elsif !output.empty?
    puts Formatter.columns(output.map(&:to_s))
  end
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.


16
17
18
19
20
21
22
23
24
25
26
27
# File 'Library/Homebrew/cask/cmd/list.rb', line 16

def self.parser
  super do
    switch "-1",
           description: "Force output to be one entry per line."
    switch "--versions",
           description: "Show the version number the listed casks."
    switch "--full-name",
           description: "Print casks with fully-qualified names."
    switch "--json",
           description: "Print a JSON representation of the listed casks. "
  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.


29
30
31
32
33
34
35
36
37
38
# File 'Library/Homebrew/cask/cmd/list.rb', line 29

def run
  self.class.list_casks(
    *casks,
    json:      args.json?,
    one:       args.public_send(:'1?'),
    full_name: args.full_name?,
    versions:  args.versions?,
    args:      args,
  )
end