Class: Cask::Cmd::Info

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

Instance Attribute Summary

Attributes inherited from AbstractCommand

#args

Class Method Summary collapse

Instance Method Summary collapse

Methods inherited from AbstractCommand

abstract?, command_name, 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

#initializeInfo

Returns a new instance of Info



11
12
13
14
# File 'brew/Library/Homebrew/cask/cmd/info.rb', line 11

def initialize(*)
  super
  raise CaskUnspecifiedError if args.empty?
end

Class Method Details

.artifact_info(cask) ⇒ Object



109
110
111
112
113
114
115
116
117
118
# File 'brew/Library/Homebrew/cask/cmd/info.rb', line 109

def self.artifact_info(cask)
  artifact_output = ohai_title("Artifacts").dup
  cask.artifacts.each do |artifact|
    next unless artifact.respond_to?(:install_phase)
    next unless DSL::ORDINARY_ARTIFACT_CLASSES.include?(artifact.class)

    artifact_output << "\n" << artifact.to_s
  end
  artifact_output.freeze
end

.formatted_url(url) ⇒ Object



57
58
59
# File 'brew/Library/Homebrew/cask/cmd/info.rb', line 57

def self.formatted_url(url)
  "#{Tty.underline}#{url}#{Tty.reset}"
end

.get_info(cask) ⇒ Object



32
33
34
35
36
37
38
39
40
41
42
43
44
45
# File 'brew/Library/Homebrew/cask/cmd/info.rb', line 32

def self.get_info(cask)
  output = title_info(cask) + "\n"
  output << Formatter.url(cask.homepage) + "\n" if cask.homepage
  output << installation_info(cask)
  repo = repo_info(cask)
  output << repo + "\n" if repo
  output << name_info(cask)
  language = language_info(cask)
  output << language if language
  output << artifact_info(cask) + "\n"
  caveats = Installer.caveats(cask)
  output << caveats if caveats
  output
end

.helpObject



28
29
30
# File 'brew/Library/Homebrew/cask/cmd/info.rb', line 28

def self.help
  "displays information about the given Cask"
end

.info(cask) ⇒ Object



47
48
49
# File 'brew/Library/Homebrew/cask/cmd/info.rb', line 47

def self.info(cask)
  puts get_info(cask)
end

.installation_info(cask) ⇒ Object



61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
# File 'brew/Library/Homebrew/cask/cmd/info.rb', line 61

def self.installation_info(cask)
  install_info = +""
  if cask.installed?
    cask.versions.each do |version|
      versioned_staged_path = cask.caskroom_path.join(version)
      install_info << versioned_staged_path.to_s
                      .concat(" (")
                      .concat(
                        if versioned_staged_path.exist?
                        then versioned_staged_path.abv
                        else Formatter.error("does not exist")
                        end,
                      ).concat(")\n")
    end
    install_info.freeze
  else
    "Not installed\n"
  end
end

.language_info(cask) ⇒ Object



88
89
90
91
92
93
94
95
# File 'brew/Library/Homebrew/cask/cmd/info.rb', line 88

def self.language_info(cask)
  return if cask.languages.empty?

  <<~EOS
    #{ohai_title("Languages")}
    #{cask.languages.join(", ")}
  EOS
end

.name_info(cask) ⇒ Object



81
82
83
84
85
86
# File 'brew/Library/Homebrew/cask/cmd/info.rb', line 81

def self.name_info(cask)
  <<~EOS
    #{ohai_title((cask.name.size > 1) ? "Names" : "Name")}
    #{cask.name.empty? ? Formatter.error("None") : cask.name.join("\n")}
  EOS
end

.repo_info(cask) ⇒ Object



97
98
99
100
101
102
103
104
105
106
107
# File 'brew/Library/Homebrew/cask/cmd/info.rb', line 97

def self.repo_info(cask)
  return if cask.tap.nil?

  url = if cask.tap.custom_remote? && !cask.tap.remote.nil?
    cask.tap.remote
  else
    "#{cask.tap.default_remote}/blob/master/Casks/#{cask.token}.rb"
  end

  "From: #{Formatter.url(url)}"
end

.title_info(cask) ⇒ Object



51
52
53
54
55
# File 'brew/Library/Homebrew/cask/cmd/info.rb', line 51

def self.title_info(cask)
  title = "#{cask.token}: #{cask.version}"
  title += " (auto_updates)" if cask.auto_updates
  title
end

Instance Method Details

#runObject



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

def run
  if json == "v1"
    puts JSON.generate(casks.map(&:to_h))
  else
    casks.each_with_index do |cask, i|
      puts unless i.zero?
      odebug "Getting info for Cask #{cask}"
      self.class.info(cask)
    end
  end
end