Class: Cask::Cmd::List

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

Instance Attribute Summary

Attributes inherited from AbstractCommand

#args

Class Method Summary collapse

Instance Method Summary collapse

Methods inherited from AbstractCommand

abstract?, command_name, #initialize, run, visible

Methods included from Homebrew::Search

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

Methods included from Options

#process_arguments

Constructor Details

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

Class Method Details

.format_versioned(cask) ⇒ Object



56
57
58
# File 'brew/Library/Homebrew/cask/cmd/list.rb', line 56

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

.helpObject



60
61
62
# File 'brew/Library/Homebrew/cask/cmd/list.rb', line 60

def self.help
  "with no args, lists installed Casks; given installed Casks, lists staged files"
end

.list_artifacts(cask) ⇒ Object



34
35
36
37
38
39
40
# File 'brew/Library/Homebrew/cask/cmd/list.rb', line 34

def self.list_artifacts(cask)
  cask.artifacts.group_by(&:class).each do |klass, artifacts|
    next unless klass.respond_to?(:english_description)

    ohai klass.english_description, artifacts.map(&:summarize_installed)
  end
end

Instance Method Details

#listObject



19
20
21
22
23
24
25
26
27
28
29
30
31
32
# File 'brew/Library/Homebrew/cask/cmd/list.rb', line 19

def list
  casks.each do |cask|
    raise CaskNotInstalledError, cask unless cask.installed?

    if one?
      puts cask.token
    elsif versions?
      puts self.class.format_versioned(cask)
    else
      cask = CaskLoader.load(cask.installed_caskfile)
      self.class.list_artifacts(cask)
    end
  end
end

#list_installedObject



42
43
44
45
46
47
48
49
50
51
52
53
54
# File 'brew/Library/Homebrew/cask/cmd/list.rb', line 42

def list_installed
  installed_casks = Caskroom.casks

  if one?
    puts installed_casks.map(&:to_s)
  elsif versions?
    puts installed_casks.map(&self.class.method(:format_versioned))
  elsif full_name?
    puts installed_casks.map(&:full_name).sort &tap_and_name_comparison
  elsif !installed_casks.empty?
    puts Formatter.columns(installed_casks.map(&:to_s))
  end
end

#runObject



15
16
17
# File 'brew/Library/Homebrew/cask/cmd/list.rb', line 15

def run
  args.any? ? list : list_installed
end