Class: Cask::Cmd::Info Private

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

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


147
148
149
150
151
152
153
154
155
156
# File 'Library/Homebrew/cask/cmd/info.rb', line 147

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

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


119
120
121
122
123
124
# File 'Library/Homebrew/cask/cmd/info.rb', line 119

def self.desc_info(cask)
  <<~EOS
    #{ohai_title("Description")}
    #{cask.desc.nil? ? Formatter.error("None") : cask.desc}
  EOS
end

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


16
17
18
# File 'Library/Homebrew/cask/cmd/info.rb', line 16

def self.description
  "Displays information about the given <cask>."
end

.formatted_url(url) ⇒ 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.


92
93
94
# File 'Library/Homebrew/cask/cmd/info.rb', line 92

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

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


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

def self.get_info(cask)
  require "cask/installer"

  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)
  output << desc_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

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


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

def self.info(cask)
  puts get_info(cask)
  ::Utils::Analytics.cask_output(cask, args: Homebrew::CLI::Args.new)
end

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


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

def self.installation_info(cask)
  return "Not installed\n" unless cask.installed?

  install_info = +""
  cask.versions.each do |version|
    versioned_staged_path = cask.caskroom_path.join(version)
    path_details = if versioned_staged_path.exist?
      versioned_staged_path.abv
    else
      Formatter.error("does not exist")
    end
    install_info << "#{versioned_staged_path} (#{path_details})\n"
  end
  install_info.freeze
end

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


126
127
128
129
130
131
132
133
# File 'Library/Homebrew/cask/cmd/info.rb', line 126

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

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

.min_namedObject

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/info.rb', line 12

def self.min_named
  :cask
end

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


112
113
114
115
116
117
# File 'Library/Homebrew/cask/cmd/info.rb', line 112

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

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


20
21
22
23
24
25
26
27
# File 'Library/Homebrew/cask/cmd/info.rb', line 20

def self.parser
  super do
    flag   "--json=",
           description: "Output information in JSON format."
    switch "--github",
           description: "Open the GitHub source page for <Cask> in a browser. "
  end
end

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


135
136
137
138
139
140
141
142
143
144
145
# File 'Library/Homebrew/cask/cmd/info.rb', line 135

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/HEAD/Casks/#{cask.token}.rb"
  end

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

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


86
87
88
89
90
# File 'Library/Homebrew/cask/cmd/info.rb', line 86

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

Instance Method Details

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


29
30
31
32
33
34
35
# File 'Library/Homebrew/cask/cmd/info.rb', line 29

def github_info(cask)
  sourcefile_path = cask.sourcefile_path
  dir = cask.tap.path
  path = sourcefile_path.relative_path_from(dir)
  remote = cask.tap.remote
  github_remote_path(remote, path)
end

#github_remote_path(remote, path) ⇒ 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.


37
38
39
40
41
42
43
# File 'Library/Homebrew/cask/cmd/info.rb', line 37

def github_remote_path(remote, path)
  if remote =~ %r{^(?:https?://|git(?:@|://))github\.com[:/](.+)/(.+?)(?:\.git)?$}
    "https://github.com/#{Regexp.last_match(1)}/#{Regexp.last_match(2)}/blob/HEAD/#{path}"
  else
    "#{remote}/#{path}"
  end
end

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


45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
# File 'Library/Homebrew/cask/cmd/info.rb', line 45

def run
  if args.json == "v1"
    puts JSON.generate(args.named.to_casks.map(&:to_h))
  elsif args.github?
    raise CaskUnspecifiedError if args.no_named?

    args.named.to_casks.map do |cask|
      exec_browser(github_info(cask))
    end
  else
    args.named.to_casks.each_with_index do |cask, i|
      puts unless i.zero?
      odebug "Getting info for Cask #{cask}"
      self.class.info(cask)
    end
  end
end