- search_for_cask in missing_formula renamed to is_a_cask_reason
- is_a_cask calls new getInfo method in cask/cmd/info.rb to return info
string
- self.info in info.rb now calls getInfo and puts return value
- added ohai_title to return the ohai printout for only titles, so that
ohai printout could be added to the getInfo return string without
calling puts.
- refactored ohai to use ohai_title
- updated info_spec.rb cask info test to be more specific when
matching stderr.
- is_a_cask_reason will respect 'silent'
- refactored print_caveats to return instead of print
107 lines
2.7 KiB
Ruby
107 lines
2.7 KiB
Ruby
require "json"
|
|
|
|
module Cask
|
|
class Cmd
|
|
class Info < AbstractCommand
|
|
option "--json=VERSION", :json
|
|
|
|
def initialize(*)
|
|
super
|
|
raise CaskUnspecifiedError if args.empty?
|
|
end
|
|
|
|
def run
|
|
if json == "v1"
|
|
puts JSON.generate(casks.map(&:to_h))
|
|
else
|
|
casks.each do |cask|
|
|
odebug "Getting info for Cask #{cask}"
|
|
self.class.info(cask)
|
|
end
|
|
end
|
|
end
|
|
|
|
def self.help
|
|
"displays information about the given Cask"
|
|
end
|
|
|
|
def self.get_info(cask)
|
|
"#{title_info(cask)}\n"\
|
|
"#{Formatter.url(cask.homepage) if cask.homepage}\n"\
|
|
"#{installation_info(cask)}\n"\
|
|
"#{repo_info(cask)}"\
|
|
"#{name_info(cask)}"\
|
|
"#{language_info(cask)}"\
|
|
"#{artifact_info(cask)}"\
|
|
"#{Installer.print_caveats(cask)}"\
|
|
end
|
|
|
|
def self.info(cask)
|
|
puts get_info(cask)
|
|
end
|
|
|
|
def self.title_info(cask)
|
|
title = "#{cask.token}: #{cask.version}"
|
|
title += " (auto_updates)" if cask.auto_updates
|
|
title
|
|
end
|
|
|
|
def self.formatted_url(url)
|
|
"#{Tty.underline}#{url}#{Tty.reset}"
|
|
end
|
|
|
|
def self.installation_info(cask)
|
|
if cask.installed?
|
|
cask.versions.each do |version|
|
|
versioned_staged_path = cask.caskroom_path.join(version)
|
|
message = versioned_staged_path.exist? ? versioned_staged_path.abv : Formatter.error("does not exist")
|
|
versioned_staged_path.to_s.concat(" (").concat(message).concat(")")
|
|
end
|
|
else
|
|
"Not installed"
|
|
end
|
|
end
|
|
|
|
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
|
|
|
|
def self.language_info(cask)
|
|
return if cask.languages.empty?
|
|
|
|
<<~EOS
|
|
#{ohai_title("Languages")}
|
|
#{cask.languages.join(", ")}
|
|
EOS
|
|
end
|
|
|
|
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)}\n"
|
|
end
|
|
|
|
def self.artifact_info(cask)
|
|
cask.artifacts.each do |artifact|
|
|
next unless artifact.respond_to?(:install_phase)
|
|
next unless DSL::ORDINARY_ARTIFACT_CLASSES.include?(artifact.class)
|
|
|
|
return <<~EOS
|
|
#{ohai_title("Artifacts")}
|
|
#{artifact}
|
|
EOS
|
|
end
|
|
end
|
|
end
|
|
end
|
|
end
|