diff --git a/Library/Homebrew/cask/cmd/fetch.rb b/Library/Homebrew/cask/cmd/fetch.rb index ac7f9c6365..3ff51c6139 100644 --- a/Library/Homebrew/cask/cmd/fetch.rb +++ b/Library/Homebrew/cask/cmd/fetch.rb @@ -12,7 +12,7 @@ module Cask def run casks.each do |cask| - Installer.print_caveats(cask) + puts Installer.print_caveats(cask) ohai "Downloading external files for Cask #{cask}" downloaded_path = Download.new(cask, force: force?, quarantine: quarantine?).perform Verify.all(cask, downloaded_path) diff --git a/Library/Homebrew/cask/cmd/info.rb b/Library/Homebrew/cask/cmd/info.rb index 109162bec8..d81b5f44a6 100644 --- a/Library/Homebrew/cask/cmd/info.rb +++ b/Library/Homebrew/cask/cmd/info.rb @@ -25,21 +25,25 @@ module Cask "displays information about the given Cask" end + def self.get_info(cask) + "#{title_info(cask)}\n"\ + "#{Formatter.url(cask.homepage) if cask.homepage}\n"\ + "#{installation_info(cask)}\n"\ + "#{repo_info(cask)}"\ + "#{name_info(cask)}"\ + "#{language_info(cask)}"\ + "#{artifact_info(cask)}"\ + "#{Installer.print_caveats(cask)}"\ + 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) @@ -50,27 +54,28 @@ module Cask 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(")") + message = versioned_staged_path.exist? ? versioned_staged_path.abv : Formatter.error("does not exist") + versioned_staged_path.to_s.concat(" (").concat(message).concat(")") end else - puts "Not installed" + "Not installed" 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,16 +87,18 @@ module Cask "#{cask.tap.default_remote}/blob/master/Casks/#{cask.token}.rb" end - puts "From: #{Formatter.url(url)}" + "From: #{Formatter.url(url)}\n" end def self.artifact_info(cask) - ohai "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 + return <<~EOS + #{ohai_title("Artifacts")} + #{artifact} + EOS end end end diff --git a/Library/Homebrew/cask/cmd/upgrade.rb b/Library/Homebrew/cask/cmd/upgrade.rb index 06e880bd12..92b611f5bd 100644 --- a/Library/Homebrew/cask/cmd/upgrade.rb +++ b/Library/Homebrew/cask/cmd/upgrade.rb @@ -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.print_caveats new_cask_installer.fetch diff --git a/Library/Homebrew/cask/installer.rb b/Library/Homebrew/cask/installer.rb index 88b8e83193..c65a1395da 100644 --- a/Library/Homebrew/cask/installer.rb +++ b/Library/Homebrew/cask/installer.rb @@ -49,8 +49,8 @@ module Cask caveats = cask.caveats return if caveats.empty? - ohai "Caveats" - puts caveats + "\n" + "#{ohai_title "Caveats"}\n"\ + "#{caveats}\n" end def fetch @@ -88,7 +88,7 @@ module Cask check_conflicts - print_caveats + print print_caveats fetch uninstall_existing_cask if reinstall? diff --git a/Library/Homebrew/missing_formula.rb b/Library/Homebrew/missing_formula.rb index 36fea37062..b066659512 100644 --- a/Library/Homebrew/missing_formula.rb +++ b/Library/Homebrew/missing_formula.rb @@ -1,6 +1,6 @@ require "formulary" require "cask/cmd/abstract_command" -require "cask/cmd/info" +require "cask/cmd" require "cask/cask_loader" require "cask/installer" @@ -8,10 +8,8 @@ module Homebrew module MissingFormula class << self def reason(name, silent: false) - search_for_cask(name) - rescue - blacklisted_reason(name) || tap_migration_reason(name) || - deleted_reason(name, silent: silent) + cask_reason(name, silent: false) || blacklisted_reason(name) || + tap_migration_reason(name) || deleted_reason(name, silent: silent) end def blacklisted_reason(name) @@ -180,9 +178,11 @@ module Homebrew end end - def search_for_cask(name) + def cask_reason(name, silent: false) cask = Cask::CaskLoader.load(name) - Cask::Cmd::Info.info(cask) + return 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 f646fc4f23..ac1ff22900 100644 --- a/Library/Homebrew/test/cmd/info_spec.rb +++ b/Library/Homebrew/test/cmd/info_spec.rb @@ -23,8 +23,17 @@ describe "brew info", :integration_test do setup_remote_tap "homebrew/cask" expect { brew "info", "firefox" } - .to output(/No available formula with the name "firefox"/).to_stderr - .and output(/firefox/).to_stdout + .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 end end diff --git a/Library/Homebrew/utils.rb b/Library/Homebrew/utils.rb index d6ea652c8a..61e741c5b9 100644 --- a/Library/Homebrew/utils.rb +++ b/Library/Homebrew/utils.rb @@ -23,9 +23,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