Merge pull request #5538 from zachauten/brew-info-display-casks
Make brew info output cask if no formula exists
This commit is contained in:
commit
cf4511f72a
@ -12,7 +12,7 @@ module Cask
|
||||
|
||||
def run
|
||||
casks.each do |cask|
|
||||
Installer.print_caveats(cask)
|
||||
puts Installer.caveats(cask)
|
||||
ohai "Downloading external files for Cask #{cask}"
|
||||
downloaded_path = Download.new(cask, force: force?, quarantine: quarantine?).perform
|
||||
Verify.all(cask, downloaded_path)
|
||||
|
@ -1,4 +1,5 @@
|
||||
require "json"
|
||||
require "cask/installer"
|
||||
|
||||
module Cask
|
||||
class Cmd
|
||||
@ -25,21 +26,29 @@ module Cask
|
||||
"displays information about the given Cask"
|
||||
end
|
||||
|
||||
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
|
||||
|
||||
def self.info(cask)
|
||||
title_info(cask)
|
||||
puts Formatter.url(cask.homepage) if cask.homepage
|
||||
installation_info(cask)
|
||||
repo_info(cask)
|
||||
name_info(cask)
|
||||
language_info(cask)
|
||||
artifact_info(cask)
|
||||
Installer.print_caveats(cask)
|
||||
puts get_info(cask)
|
||||
end
|
||||
|
||||
def self.title_info(cask)
|
||||
title = "#{cask.token}: #{cask.version}"
|
||||
title += " (auto_updates)" if cask.auto_updates
|
||||
puts title
|
||||
title
|
||||
end
|
||||
|
||||
def self.formatted_url(url)
|
||||
@ -47,30 +56,39 @@ module Cask
|
||||
end
|
||||
|
||||
def self.installation_info(cask)
|
||||
install_info = ""
|
||||
if cask.installed?
|
||||
cask.versions.each do |version|
|
||||
versioned_staged_path = cask.caskroom_path.join(version)
|
||||
|
||||
puts versioned_staged_path.to_s
|
||||
.concat(" (")
|
||||
.concat(versioned_staged_path.exist? ? versioned_staged_path.abv : Formatter.error("does not exist"))
|
||||
.concat(")")
|
||||
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
|
||||
else
|
||||
puts "Not installed"
|
||||
"Not installed\n"
|
||||
end
|
||||
end
|
||||
|
||||
def self.name_info(cask)
|
||||
ohai((cask.name.size > 1) ? "Names" : "Name")
|
||||
puts cask.name.empty? ? Formatter.error("None") : cask.name
|
||||
<<~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?
|
||||
|
||||
ohai "Languages"
|
||||
puts cask.languages.join(", ")
|
||||
<<~EOS
|
||||
#{ohai_title("Languages")}
|
||||
#{cask.languages.join(", ")}
|
||||
EOS
|
||||
end
|
||||
|
||||
def self.repo_info(cask)
|
||||
@ -82,17 +100,18 @@ module Cask
|
||||
"#{cask.tap.default_remote}/blob/master/Casks/#{cask.token}.rb"
|
||||
end
|
||||
|
||||
puts "From: #{Formatter.url(url)}"
|
||||
"From: #{Formatter.url(url)}"
|
||||
end
|
||||
|
||||
def self.artifact_info(cask)
|
||||
ohai "Artifacts"
|
||||
artifact_output = ohai_title("Artifacts")
|
||||
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
|
||||
artifact_output << "\n" << artifact.to_s
|
||||
end
|
||||
artifact_output
|
||||
end
|
||||
end
|
||||
end
|
||||
|
@ -74,7 +74,7 @@ module Cask
|
||||
# Start new Cask's installation steps
|
||||
new_cask_installer.check_conflicts
|
||||
|
||||
new_cask_installer.print_caveats
|
||||
puts new_cask_installer.caveats
|
||||
|
||||
new_cask_installer.fetch
|
||||
|
||||
|
@ -43,14 +43,16 @@ module Cask
|
||||
:reinstall?, :upgrade?, :verbose?, :installed_as_dependency?,
|
||||
:quarantine?
|
||||
|
||||
def self.print_caveats(cask)
|
||||
def self.caveats(cask)
|
||||
odebug "Printing caveats"
|
||||
|
||||
caveats = cask.caveats
|
||||
return if caveats.empty?
|
||||
|
||||
ohai "Caveats"
|
||||
puts caveats + "\n"
|
||||
<<~EOS
|
||||
#{ohai_title "Caveats"}
|
||||
#{caveats}
|
||||
EOS
|
||||
end
|
||||
|
||||
def fetch
|
||||
@ -86,7 +88,7 @@ module Cask
|
||||
|
||||
check_conflicts
|
||||
|
||||
print_caveats
|
||||
print caveats
|
||||
fetch
|
||||
uninstall_existing_cask if reinstall?
|
||||
|
||||
@ -370,8 +372,8 @@ module Cask
|
||||
end
|
||||
end
|
||||
|
||||
def print_caveats
|
||||
self.class.print_caveats(@cask)
|
||||
def caveats
|
||||
self.class.caveats(@cask)
|
||||
end
|
||||
|
||||
def save_caskfile
|
||||
|
@ -94,7 +94,7 @@ module Homebrew
|
||||
end
|
||||
ofail e.message
|
||||
# No formula with this name, try a missing formula lookup
|
||||
if (reason = MissingFormula.reason(f))
|
||||
if (reason = MissingFormula.reason(f, show_info: true))
|
||||
$stderr.puts reason
|
||||
end
|
||||
end
|
||||
|
@ -1,11 +1,14 @@
|
||||
require "formulary"
|
||||
require "cask/cmd/abstract_command"
|
||||
require "cask/cmd/info"
|
||||
require "cask/cask_loader"
|
||||
|
||||
module Homebrew
|
||||
module MissingFormula
|
||||
class << self
|
||||
def reason(name, silent: false)
|
||||
blacklisted_reason(name) || tap_migration_reason(name) ||
|
||||
deleted_reason(name, silent: silent)
|
||||
def reason(name, silent: false, show_info: false)
|
||||
cask_reason(name, silent: silent, show_info: show_info) || blacklisted_reason(name) ||
|
||||
tap_migration_reason(name) || deleted_reason(name, silent: silent)
|
||||
end
|
||||
|
||||
def blacklisted_reason(name)
|
||||
@ -191,6 +194,17 @@ module Homebrew
|
||||
end
|
||||
end
|
||||
|
||||
def cask_reason(name, silent: false, show_info: false)
|
||||
return if silent
|
||||
|
||||
cask = Cask::CaskLoader.load(name)
|
||||
reason = "Found a cask named \"#{name}\" instead.\n"
|
||||
reason << Cask::Cmd::Info.get_info(cask) if show_info
|
||||
reason
|
||||
rescue Cask::CaskUnavailableError
|
||||
nil
|
||||
end
|
||||
|
||||
require "extend/os/missing_formula"
|
||||
end
|
||||
end
|
||||
|
@ -136,4 +136,29 @@ describe Homebrew::MissingFormula do
|
||||
it { is_expected.to be_nil }
|
||||
end
|
||||
end
|
||||
|
||||
describe "::cask_reason", :cask do
|
||||
subject { described_class.cask_reason(formula, show_info: show_info) }
|
||||
|
||||
context "with a formula name that is a cask and show_info: false" do
|
||||
let(:formula) { "local-caffeine" }
|
||||
let(:show_info) { false }
|
||||
|
||||
it { is_expected.to match(/Found a cask named "local-caffeine" instead./) }
|
||||
end
|
||||
|
||||
context "with a formula name that is a cask and show_info: true" do
|
||||
let(:formula) { "local-caffeine" }
|
||||
let(:show_info) { true }
|
||||
|
||||
it { is_expected.to match(/Found a cask named "local-caffeine" instead.\nlocal-caffeine: 1.2.3\n/) }
|
||||
end
|
||||
|
||||
context "with a formula name that is not a cask" do
|
||||
let(:formula) { "missing-formula" }
|
||||
let(:show_info) { false }
|
||||
|
||||
it { is_expected.to be_nil }
|
||||
end
|
||||
end
|
||||
end
|
||||
|
@ -24,9 +24,13 @@ rescue LoadError => e
|
||||
raise unless e.message.include?(path)
|
||||
end
|
||||
|
||||
def ohai(title, *sput)
|
||||
def ohai_title(title)
|
||||
title = Tty.truncate(title) if $stdout.tty? && !ARGV.verbose?
|
||||
puts Formatter.headline(title, color: :blue)
|
||||
Formatter.headline(title, color: :blue)
|
||||
end
|
||||
|
||||
def ohai(title, *sput)
|
||||
puts ohai_title(title)
|
||||
puts sput
|
||||
end
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user