85 lines
2.2 KiB
Ruby
Raw Normal View History

2016-09-24 13:52:43 +02:00
module Hbc
class CLI
2017-05-20 19:08:03 +02:00
class Info < AbstractCommand
2017-05-21 00:15:56 +02:00
def initialize(*)
super
raise CaskUnspecifiedError if args.empty?
2017-05-20 18:31:07 +02:00
end
def run
casks.each do |cask|
odebug "Getting info for Cask #{cask}"
2017-05-20 18:31:07 +02:00
self.class.info(cask)
2016-09-24 13:52:43 +02:00
end
end
2016-08-18 22:11:42 +03:00
2016-09-24 13:52:43 +02:00
def self.help
"displays information about the given Cask"
end
2016-08-18 22:11:42 +03:00
2016-09-24 13:52:43 +02:00
def self.info(cask)
puts "#{cask.token}: #{cask.version}"
2016-08-30 21:38:13 +02:00
puts Formatter.url(cask.homepage) if cask.homepage
2016-09-24 13:52:43 +02:00
installation_info(cask)
repo_info(cask)
2016-09-24 13:52:43 +02:00
name_info(cask)
language_info(cask)
2016-09-24 13:52:43 +02:00
artifact_info(cask)
Installer.print_caveats(cask)
end
2016-08-18 22:11:42 +03:00
2016-09-24 13:52:43 +02:00
def self.formatted_url(url)
2016-08-26 16:04:47 +02:00
"#{Tty.underline}#{url}#{Tty.reset}"
2016-09-24 13:52:43 +02:00
end
2016-08-18 22:11:42 +03:00
2016-09-24 13:52:43 +02:00
def self.installation_info(cask)
if cask.installed?
cask.versions.each do |version|
versioned_staged_path = cask.caskroom_path.join(version)
2016-08-18 22:11:42 +03:00
2016-09-24 13:52:43 +02:00
puts versioned_staged_path.to_s
.concat(" (")
2016-08-30 21:38:13 +02:00
.concat(versioned_staged_path.exist? ? versioned_staged_path.abv : Formatter.error("does not exist"))
2017-05-29 18:24:52 +01:00
.concat(")")
2016-09-24 13:52:43 +02:00
end
else
puts "Not installed"
end
2016-08-18 22:11:42 +03:00
end
2016-09-24 13:52:43 +02:00
def self.name_info(cask)
2017-05-29 18:24:52 +01:00
ohai((cask.name.size > 1) ? "Names" : "Name")
2016-08-30 21:38:13 +02:00
puts cask.name.empty? ? Formatter.error("None") : cask.name
2016-09-24 13:52:43 +02:00
end
2016-08-18 22:11:42 +03:00
def self.language_info(cask)
return if cask.languages.empty?
ohai "Languages"
puts cask.languages.join(", ")
end
def self.repo_info(cask)
2018-04-14 10:35:21 +02:00
return if cask.tap.nil?
2018-04-14 10:35:21 +02:00
url = if cask.tap.custom_remote? && !cask.tap.remote.nil?
cask.tap.remote
else
2018-04-14 10:35:21 +02:00
"#{cask.tap.default_remote}/blob/master/Casks/#{cask.token}.rb"
end
puts "From: #{Formatter.url(url)}"
2016-09-24 13:52:43 +02:00
end
2016-08-18 22:11:42 +03:00
2016-09-24 13:52:43 +02:00
def self.artifact_info(cask)
ohai "Artifacts"
2017-10-04 17:08:35 +02:00
cask.artifacts.each do |artifact|
next unless artifact.respond_to?(:install_phase)
next unless DSL::ORDINARY_ARTIFACT_CLASSES.include?(artifact.class)
puts artifact.to_s
end
2016-08-18 22:11:42 +03:00
end
end
end
end