Class: Hbc::CLI::List

Inherits:
AbstractCommand show all
Defined in:
Library/Homebrew/cask/lib/hbc/cli/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 Options

included, #process_arguments

Constructor Details

This class inherits a constructor from Hbc::CLI::AbstractCommand

Class Method Details

.format_versioned(cask) ⇒ Object



53
54
55
# File 'Library/Homebrew/cask/lib/hbc/cli/list.rb', line 53

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

.helpObject



57
58
59
# File 'Library/Homebrew/cask/lib/hbc/cli/list.rb', line 57

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

.list_artifacts(cask) ⇒ Object



32
33
34
35
36
37
# File 'Library/Homebrew/cask/lib/hbc/cli/list.rb', line 32

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

.needs_init?Boolean

Returns:

  • (Boolean)


61
62
63
# File 'Library/Homebrew/cask/lib/hbc/cli/list.rb', line 61

def self.needs_init?
  true
end

Instance Method Details

#listObject



17
18
19
20
21
22
23
24
25
26
27
28
29
30
# File 'Library/Homebrew/cask/lib/hbc/cli/list.rb', line 17

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



39
40
41
42
43
44
45
46
47
48
49
50
51
# File 'Library/Homebrew/cask/lib/hbc/cli/list.rb', line 39

def list_installed
  installed_casks = Hbc.installed

  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



13
14
15
# File 'Library/Homebrew/cask/lib/hbc/cli/list.rb', line 13

def run
  args.any? ? list : list_installed
end