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