Class: Cask::Cmd::List Private

Inherits:
AbstractCommand show all
Extended by:
T::Sig
Defined in:
cask/cmd/list.rb

Overview

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.

Cask implementation of the brew 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?, command_name, help, #initialize, run, short_description, visible?

Methods included from Homebrew::Search

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

Methods included from Homebrew::Search::Extension

#search_casks, #search_descriptions

Constructor Details

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

Class Method Details

.format_versioned(cask) ⇒ Object

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.



76
77
78
# File 'cask/cmd/list.rb', line 76

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. 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.



62
63
64
65
66
67
68
69
70
71
72
73
74
# File 'cask/cmd/list.rb', line 62

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, json: false, one: false, full_name: false, versions: false) ⇒ Object

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.



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

def self.list_casks(*casks, 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
  end

  if json
    puts JSON.pretty_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. 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.



14
15
16
17
18
19
20
21
22
23
24
25
# File 'cask/cmd/list.rb', line 14

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

#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.



28
29
30
31
32
33
34
35
36
# File 'cask/cmd/list.rb', line 28

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