home: Print info for each formula/cask opened

This commit is contained in:
William Ma 2020-06-23 09:44:17 -04:00
parent 11fbf9d035
commit 27abc8c50b
3 changed files with 12 additions and 14 deletions

View File

@ -25,19 +25,17 @@ module Homebrew
if args.no_named? if args.no_named?
exec_browser HOMEBREW_WWW exec_browser HOMEBREW_WWW
else else
homepages = args.named.map do |ref| homepages = args.named.map do |name|
Formulary.factory(ref).homepage f = Formulary.factory(name)
rescue FormulaUnavailableError => e puts "Opening homepage for formula #{name}"
formula_error_message = e.message f.homepage
rescue FormulaUnavailableError
begin begin
cask = Cask::CaskLoader.load(ref) c = Cask::CaskLoader.load(name)
puts "Formula \"#{ref}\" not found. Found a cask instead." puts "Opening homepage for cask #{name}"
cask.homepage c.homepage
rescue Cask::CaskUnavailableError => e rescue Cask::CaskUnavailableError => e
cask_error_message = e.message odie "No available formula or cask with the name \"#{name}\""
odie "No available formula or cask with the name \"#{name}\"\n" \
"#{formula_error_message}\n" \
"#{cask_error_message}\n"
end end
end end
exec_browser(*homepages) exec_browser(*homepages)

View File

@ -16,7 +16,7 @@ describe "brew --cache", :integration_test do
it "prints the cache files for a given Cask" do it "prints the cache files for a given Cask" do
expect { brew "--cache", cask_path("local-caffeine") } expect { brew "--cache", cask_path("local-caffeine") }
.to output(%r{cask: #{HOMEBREW_CACHE}/downloads/[\da-f]{64}--caffeine\.zip}).to_stdout .to output(%r{#{HOMEBREW_CACHE}/downloads/[\da-f]{64}--caffeine\.zip}).to_stdout
.and not_to_output.to_stderr .and not_to_output.to_stderr
.and be_a_success .and be_a_success
end end
@ -26,7 +26,7 @@ describe "brew --cache", :integration_test do
.to output( .to output(
%r{ %r{
#{HOMEBREW_CACHE}/downloads/[\da-f]{64}--testball-.*\n #{HOMEBREW_CACHE}/downloads/[\da-f]{64}--testball-.*\n
cask:\s#{HOMEBREW_CACHE}/downloads/[\da-f]{64}--caffeine\.zip #{HOMEBREW_CACHE}/downloads/[\da-f]{64}--caffeine\.zip
}x, }x,
).to_stdout ).to_stdout
.and not_to_output.to_stderr .and not_to_output.to_stderr

View File

@ -24,7 +24,7 @@ describe "brew home", :integration_test do
setup_test_formula "testballhome" setup_test_formula "testballhome"
expect { brew "home", "testballhome", "HOMEBREW_BROWSER" => "echo" } expect { brew "home", "testballhome", "HOMEBREW_BROWSER" => "echo" }
.to output("#{testballhome_homepage}\n").to_stdout .to output(/#{testballhome_homepage}/).to_stdout
.and not_to_output.to_stderr .and not_to_output.to_stderr
.and be_a_success .and be_a_success
end end