From fe643758d72b0d31556451af84a0f9f28610f4f0 Mon Sep 17 00:00:00 2001 From: Zach Auten Date: Mon, 4 Mar 2019 19:38:31 -0500 Subject: [PATCH] Updated get_info - get_info builds info string by appending helper functions - removed unnecessary returns - fixed indentation in missing_formula - reduced size of regex in info_spec - missing_formula will indicate when it finds a cask with same name --- Library/Homebrew/cask/cmd/info.rb | 29 +++++++++++++++----------- Library/Homebrew/missing_formula.rb | 10 +++++---- Library/Homebrew/test/cmd/info_spec.rb | 12 +---------- 3 files changed, 24 insertions(+), 27 deletions(-) diff --git a/Library/Homebrew/cask/cmd/info.rb b/Library/Homebrew/cask/cmd/info.rb index 081245caeb..3ee9cddf5e 100644 --- a/Library/Homebrew/cask/cmd/info.rb +++ b/Library/Homebrew/cask/cmd/info.rb @@ -27,12 +27,18 @@ module Cask end def self.get_info(cask) - <<~EOS.chomp - #{title_info(cask)} - #{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)} - EOS + output = title_info(cask) + "\n" + if cask.homepage then output << Formatter.url(cask.homepage) + "\n" end + output << installation_info(cask) + repo = repo_info(cask) + output << repo unless repo.nil? + output << name_info(cask) + language = language_info(cask) + output << language unless language.nil? + output << artifact_info(cask) + caveats = Installer.print_caveats(cask) + output << caveats unless caveats.nil? + output end def self.info(cask) @@ -64,9 +70,9 @@ module Cask ).concat(")") install_info << "\n" end - return install_info.strip + install_info else - "Not installed" + "Not installed\n" end end @@ -99,15 +105,14 @@ module Cask end def self.artifact_info(cask) + 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) - return <<~EOS - #{ohai_title("Artifacts")} - #{artifact} - EOS + artifact_output << "\n" << artifact.to_s end + artifact_output << "\n" end end end diff --git a/Library/Homebrew/missing_formula.rb b/Library/Homebrew/missing_formula.rb index 22a0c4678f..40dd44488c 100644 --- a/Library/Homebrew/missing_formula.rb +++ b/Library/Homebrew/missing_formula.rb @@ -7,7 +7,7 @@ module Homebrew module MissingFormula class << self def reason(name, silent: false) - cask_reason(name, silent: false) || blacklisted_reason(name) || + cask_reason(name, silent: silent) || blacklisted_reason(name) || tap_migration_reason(name) || deleted_reason(name, silent: silent) end @@ -191,10 +191,12 @@ module Homebrew end def cask_reason(name, silent: false) + return if silent cask = Cask::CaskLoader.load(name) - return Cask::Cmd::Info.get_info(cask) unless silent - rescue Cask::CaskUnavailableError - nil + reason = "Found the following cask named \"#{name}\" instead:\n" + reason << Cask::Cmd::Info.get_info(cask) unless silent + rescue Cask::CaskUnavailableError + nil end require "extend/os/missing_formula" diff --git a/Library/Homebrew/test/cmd/info_spec.rb b/Library/Homebrew/test/cmd/info_spec.rb index ac1ff22900..855237a268 100644 --- a/Library/Homebrew/test/cmd/info_spec.rb +++ b/Library/Homebrew/test/cmd/info_spec.rb @@ -23,17 +23,7 @@ describe "brew info", :integration_test do setup_remote_tap "homebrew/cask" expect { brew "info", "firefox" } - .to output(%r{Error:\sNo\savailable\sformula\swith\sthe\sname\s"firefox"\s\n - firefox:\s\d+.?\d*\s\(auto_updates\)\n - https:\/\/www.mozilla.org\/firefox\/\n - Not\sinstalled\n - .*\n - ==>\sName\n - Mozilla\sFirefox\n - ==>\sLanguages\n - .*\n - ==>\sArtifacts\n - Firefox.app\s\(App\)\n}x).to_stderr + .to output(/Found the following cask named "firefox" instead:\nfirefox: .+ \(auto_updates\)\n/).to_stderr end end