From 468496b5ffc1dfc6c3080432cfe4893ca74fdeda Mon Sep 17 00:00:00 2001 From: Zach Auten Date: Fri, 4 Jan 2019 21:47:37 -0500 Subject: [PATCH 01/12] brew 'info' will show info for cask if formula with same name does not exist --- Library/Homebrew/cmd/info.rb | 9 +++++++++ Library/Homebrew/test/cmd/info_spec.rb | 18 ++++++++++++++++++ 2 files changed, 27 insertions(+) diff --git a/Library/Homebrew/cmd/info.rb b/Library/Homebrew/cmd/info.rb index ce72549531..5beab2f30a 100644 --- a/Library/Homebrew/cmd/info.rb +++ b/Library/Homebrew/cmd/info.rb @@ -42,6 +42,10 @@ require "formula" require "keg" require "tab" require "json" +require_relative "../cask/cmd/abstract_command" +require_relative "../cask/cmd/info" +require_relative "../cask/cask_loader" +require_relative "../cask/installer" module Homebrew module_function @@ -126,6 +130,11 @@ module Homebrew if (reason = MissingFormula.reason(f)) $stderr.puts reason end + begin + ohai "Searching for a cask with the name \"#{f}\"" + cask = Cask::CaskLoader.load(f) + Cask::Cmd::Info.info(cask) + end end end end diff --git a/Library/Homebrew/test/cmd/info_spec.rb b/Library/Homebrew/test/cmd/info_spec.rb index b318576e63..2cc5339cf9 100644 --- a/Library/Homebrew/test/cmd/info_spec.rb +++ b/Library/Homebrew/test/cmd/info_spec.rb @@ -18,6 +18,24 @@ describe "brew info", :integration_test do .and not_to_output.to_stderr .and be_a_success end + + it "looks for a Cask with the same name if a given Formula does not exist" do + expect { brew "info", "basic-cask" } + .to output(/Searching for a cask with the name "basic-cask"/).to_stdout + .and output(/No available formula with the name "basic-cask"/).to_stderr + end + + it "does not look for a Cask if a given Formula exists" do + RSpec::Matchers.define_negated_matcher :not_output, :output + expect { brew "info", "testball" } + .to not_output(/Searching for a cask with the name "testball"/).to_stdout + .and not_to_output.to_stderr + end + + it "prints an error message if a given Cask does not exist" do + expect { brew "info", "non_existant_cask" } + .to output(/No Cask with this name exists./).to_stderr + end end describe Homebrew do From abb81a52e604d9f76b2c586866801ad2ec26db9f Mon Sep 17 00:00:00 2001 From: Zach Auten Date: Wed, 16 Jan 2019 20:50:44 -0500 Subject: [PATCH 02/12] Updated PR in response to suggestions - changed require_relative to require - removed useless begin - removed unnecessary test - updated brew info positive test case to verify a cask was found - moved cask search logic to missing_formula.rb --- Library/Homebrew/cmd/info.rb | 9 --------- Library/Homebrew/missing_formula.rb | 15 +++++++++++++-- Library/Homebrew/test/cmd/info_spec.rb | 20 +++++--------------- 3 files changed, 18 insertions(+), 26 deletions(-) diff --git a/Library/Homebrew/cmd/info.rb b/Library/Homebrew/cmd/info.rb index 5beab2f30a..ce72549531 100644 --- a/Library/Homebrew/cmd/info.rb +++ b/Library/Homebrew/cmd/info.rb @@ -42,10 +42,6 @@ require "formula" require "keg" require "tab" require "json" -require_relative "../cask/cmd/abstract_command" -require_relative "../cask/cmd/info" -require_relative "../cask/cask_loader" -require_relative "../cask/installer" module Homebrew module_function @@ -130,11 +126,6 @@ module Homebrew if (reason = MissingFormula.reason(f)) $stderr.puts reason end - begin - ohai "Searching for a cask with the name \"#{f}\"" - cask = Cask::CaskLoader.load(f) - Cask::Cmd::Info.info(cask) - end end end end diff --git a/Library/Homebrew/missing_formula.rb b/Library/Homebrew/missing_formula.rb index 4cf229b125..f1008d0de6 100644 --- a/Library/Homebrew/missing_formula.rb +++ b/Library/Homebrew/missing_formula.rb @@ -1,11 +1,17 @@ require "formulary" +require "cask/cmd/abstract_command" +require "cask/cmd/info" +require "cask/cask_loader" +require "cask/installer" module Homebrew module MissingFormula class << self def reason(name, silent: false) - blacklisted_reason(name) || tap_migration_reason(name) || - deleted_reason(name, silent: silent) + search_for_cask(name) + rescue + blacklisted_reason(name) || tap_migration_reason(name) || + deleted_reason(name, silent: silent) end def blacklisted_reason(name) @@ -167,6 +173,11 @@ module Homebrew end end + def search_for_cask(name) + cask = Cask::CaskLoader.load(name) + Cask::Cmd::Info.info(cask) + end + require "extend/os/missing_formula" end end diff --git a/Library/Homebrew/test/cmd/info_spec.rb b/Library/Homebrew/test/cmd/info_spec.rb index 2cc5339cf9..f646fc4f23 100644 --- a/Library/Homebrew/test/cmd/info_spec.rb +++ b/Library/Homebrew/test/cmd/info_spec.rb @@ -19,22 +19,12 @@ describe "brew info", :integration_test do .and be_a_success end - it "looks for a Cask with the same name if a given Formula does not exist" do - expect { brew "info", "basic-cask" } - .to output(/Searching for a cask with the name "basic-cask"/).to_stdout - .and output(/No available formula with the name "basic-cask"/).to_stderr - end + it "looks for a Cask with the same name if a given Formula does not exist", :needs_network do + setup_remote_tap "homebrew/cask" - it "does not look for a Cask if a given Formula exists" do - RSpec::Matchers.define_negated_matcher :not_output, :output - expect { brew "info", "testball" } - .to not_output(/Searching for a cask with the name "testball"/).to_stdout - .and not_to_output.to_stderr - end - - it "prints an error message if a given Cask does not exist" do - expect { brew "info", "non_existant_cask" } - .to output(/No Cask with this name exists./).to_stderr + expect { brew "info", "firefox" } + .to output(/No available formula with the name "firefox"/).to_stderr + .and output(/firefox/).to_stdout end end From 554106d2e06dff2dea44697af5c22112b901e9fa Mon Sep 17 00:00:00 2001 From: Zach Auten Date: Mon, 18 Feb 2019 03:33:57 -0500 Subject: [PATCH 03/12] Updated missing formula cask reason - search_for_cask in missing_formula renamed to is_a_cask_reason - is_a_cask calls new getInfo method in cask/cmd/info.rb to return info string - self.info in info.rb now calls getInfo and puts return value - added ohai_title to return the ohai printout for only titles, so that ohai printout could be added to the getInfo return string without calling puts. - refactored ohai to use ohai_title - updated info_spec.rb cask info test to be more specific when matching stderr. - is_a_cask_reason will respect 'silent' - refactored print_caveats to return instead of print --- Library/Homebrew/cask/cmd/fetch.rb | 2 +- Library/Homebrew/cask/cmd/info.rb | 51 +++++++++++++++----------- Library/Homebrew/cask/cmd/upgrade.rb | 2 +- Library/Homebrew/cask/installer.rb | 6 +-- Library/Homebrew/missing_formula.rb | 14 +++---- Library/Homebrew/test/cmd/info_spec.rb | 13 ++++++- Library/Homebrew/utils.rb | 8 +++- 7 files changed, 58 insertions(+), 38 deletions(-) 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 From 330ae8c6fa9932189634789f18c2e8279da456f8 Mon Sep 17 00:00:00 2001 From: Zach Auten Date: Sun, 24 Feb 2019 21:53:04 -0500 Subject: [PATCH 04/12] print_caveats and get_info return heredocs --- Library/Homebrew/cask/cmd/info.rb | 26 ++++++++++++++------------ Library/Homebrew/cask/installer.rb | 6 ++++-- 2 files changed, 18 insertions(+), 14 deletions(-) diff --git a/Library/Homebrew/cask/cmd/info.rb b/Library/Homebrew/cask/cmd/info.rb index ec160e6b4f..081245caeb 100644 --- a/Library/Homebrew/cask/cmd/info.rb +++ b/Library/Homebrew/cask/cmd/info.rb @@ -27,14 +27,12 @@ module 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)}"\ + <<~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 end def self.info(cask) @@ -57,12 +55,16 @@ module Cask cask.versions.each do |version| versioned_staged_path = cask.caskroom_path.join(version) install_info << versioned_staged_path.to_s - .concat(" (") - .concat(versioned_staged_path.exist? ? versioned_staged_path.abv : Formatter.error("does not exist")) - .concat(")") + .concat(" (") + .concat( + if versioned_staged_path.exist? + then versioned_staged_path.abv + else Formatter.error("does not exist") + end, + ).concat(")") install_info << "\n" end - return install_info.strip + return install_info.strip else "Not installed" end diff --git a/Library/Homebrew/cask/installer.rb b/Library/Homebrew/cask/installer.rb index c65a1395da..df1f747878 100644 --- a/Library/Homebrew/cask/installer.rb +++ b/Library/Homebrew/cask/installer.rb @@ -49,8 +49,10 @@ module Cask caveats = cask.caveats return if caveats.empty? - "#{ohai_title "Caveats"}\n"\ - "#{caveats}\n" + <<~EOS + #{ohai_title "Caveats"} + #{caveats} + EOS end def fetch From fe643758d72b0d31556451af84a0f9f28610f4f0 Mon Sep 17 00:00:00 2001 From: Zach Auten Date: Mon, 4 Mar 2019 19:38:31 -0500 Subject: [PATCH 05/12] 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 From 18a20986e706e92c8112831aeef6512cad65a240 Mon Sep 17 00:00:00 2001 From: Zach Auten Date: Wed, 6 Mar 2019 18:06:50 -0500 Subject: [PATCH 06/12] Addressed style issues --- Library/Homebrew/cask/cmd/info.rb | 2 +- Library/Homebrew/missing_formula.rb | 1 + 2 files changed, 2 insertions(+), 1 deletion(-) diff --git a/Library/Homebrew/cask/cmd/info.rb b/Library/Homebrew/cask/cmd/info.rb index 3ee9cddf5e..8daa9ae1a4 100644 --- a/Library/Homebrew/cask/cmd/info.rb +++ b/Library/Homebrew/cask/cmd/info.rb @@ -28,7 +28,7 @@ module Cask def self.get_info(cask) output = title_info(cask) + "\n" - if cask.homepage then output << Formatter.url(cask.homepage) + "\n" end + output << Formatter.url(cask.homepage) + "\n" if cask.homepage output << installation_info(cask) repo = repo_info(cask) output << repo unless repo.nil? diff --git a/Library/Homebrew/missing_formula.rb b/Library/Homebrew/missing_formula.rb index 40dd44488c..82a8c7ec70 100644 --- a/Library/Homebrew/missing_formula.rb +++ b/Library/Homebrew/missing_formula.rb @@ -192,6 +192,7 @@ module Homebrew def cask_reason(name, silent: false) return if silent + cask = Cask::CaskLoader.load(name) reason = "Found the following cask named \"#{name}\" instead:\n" reason << Cask::Cmd::Info.get_info(cask) unless silent From 75b9eec7ef5d06a0928af63bb30a7548253afd4a Mon Sep 17 00:00:00 2001 From: Zach Auten Date: Mon, 11 Mar 2019 21:20:02 -0400 Subject: [PATCH 07/12] Renamed print_caveats, updated an info_spec test to macos only --- Library/Homebrew/cask/cmd/fetch.rb | 2 +- Library/Homebrew/cask/cmd/info.rb | 13 ++++++------- Library/Homebrew/cask/cmd/upgrade.rb | 2 +- Library/Homebrew/cask/installer.rb | 8 ++++---- Library/Homebrew/test/cmd/info_spec.rb | 2 +- 5 files changed, 13 insertions(+), 14 deletions(-) diff --git a/Library/Homebrew/cask/cmd/fetch.rb b/Library/Homebrew/cask/cmd/fetch.rb index 3ff51c6139..4b3d6d82c7 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| - puts 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) diff --git a/Library/Homebrew/cask/cmd/info.rb b/Library/Homebrew/cask/cmd/info.rb index 8daa9ae1a4..9f855b595b 100644 --- a/Library/Homebrew/cask/cmd/info.rb +++ b/Library/Homebrew/cask/cmd/info.rb @@ -31,12 +31,12 @@ module Cask output << Formatter.url(cask.homepage) + "\n" if cask.homepage output << installation_info(cask) repo = repo_info(cask) - output << repo unless repo.nil? + output << repo + "\n" 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 << artifact_info(cask) + "\n" + caveats = Installer.caveats(cask) output << caveats unless caveats.nil? output end @@ -67,8 +67,7 @@ module Cask then versioned_staged_path.abv else Formatter.error("does not exist") end, - ).concat(")") - install_info << "\n" + ).concat(")\n") end install_info else @@ -101,7 +100,7 @@ module Cask "#{cask.tap.default_remote}/blob/master/Casks/#{cask.token}.rb" end - "From: #{Formatter.url(url)}\n" + "From: #{Formatter.url(url)}" end def self.artifact_info(cask) @@ -112,7 +111,7 @@ module Cask artifact_output << "\n" << artifact.to_s end - artifact_output << "\n" + artifact_output end end end diff --git a/Library/Homebrew/cask/cmd/upgrade.rb b/Library/Homebrew/cask/cmd/upgrade.rb index 92b611f5bd..408d8dc545 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 - puts new_cask_installer.print_caveats + puts new_cask_installer.caveats new_cask_installer.fetch diff --git a/Library/Homebrew/cask/installer.rb b/Library/Homebrew/cask/installer.rb index 1f138d79e6..2631717a2c 100644 --- a/Library/Homebrew/cask/installer.rb +++ b/Library/Homebrew/cask/installer.rb @@ -43,7 +43,7 @@ module Cask :reinstall?, :upgrade?, :verbose?, :installed_as_dependency?, :quarantine? - def self.print_caveats(cask) + def self.caveats(cask) odebug "Printing caveats" caveats = cask.caveats @@ -88,7 +88,7 @@ module Cask check_conflicts - print print_caveats + print caveats fetch uninstall_existing_cask if reinstall? @@ -372,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 diff --git a/Library/Homebrew/test/cmd/info_spec.rb b/Library/Homebrew/test/cmd/info_spec.rb index 855237a268..50dd05fd11 100644 --- a/Library/Homebrew/test/cmd/info_spec.rb +++ b/Library/Homebrew/test/cmd/info_spec.rb @@ -19,7 +19,7 @@ describe "brew info", :integration_test do .and be_a_success end - it "looks for a Cask with the same name if a given Formula does not exist", :needs_network do + it "looks for a Cask with the same name if a given Formula does not exist", :needs_macos, :needs_network do setup_remote_tap "homebrew/cask" expect { brew "info", "firefox" } From 9eadee94084713f39a82f17eb7ff34fe955ba351 Mon Sep 17 00:00:00 2001 From: Zach Auten Date: Fri, 15 Mar 2019 22:19:12 -0400 Subject: [PATCH 08/12] moved info_spec cask test to its own describe block to fix error --- Library/Homebrew/test/cmd/info_spec.rb | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/Library/Homebrew/test/cmd/info_spec.rb b/Library/Homebrew/test/cmd/info_spec.rb index 50dd05fd11..1f43aff8cb 100644 --- a/Library/Homebrew/test/cmd/info_spec.rb +++ b/Library/Homebrew/test/cmd/info_spec.rb @@ -18,12 +18,12 @@ describe "brew info", :integration_test do .and not_to_output.to_stderr .and be_a_success end +end - it "looks for a Cask with the same name if a given Formula does not exist", :needs_macos, :needs_network do - setup_remote_tap "homebrew/cask" - - expect { brew "info", "firefox" } - .to output(/Found the following cask named "firefox" instead:\nfirefox: .+ \(auto_updates\)\n/).to_stderr +describe "brew info", :integration_test, :needs_macos do + it "looks for a Cask with the same name if a given Formula does not exist" do + expect { brew "info", "basic-cask" } + .to output(/Found the following cask named "basic-cask" instead:\nbasic-cask: .+\n/).to_stderr end end From e9b17b859398111db8530d64952e54b6c8e6cb72 Mon Sep 17 00:00:00 2001 From: Zach Auten Date: Sat, 16 Mar 2019 12:59:15 -0400 Subject: [PATCH 09/12] Replaced 'unless nil' with 'if' --- Library/Homebrew/cask/cmd/info.rb | 6 +++--- Library/Homebrew/missing_formula.rb | 2 +- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/Library/Homebrew/cask/cmd/info.rb b/Library/Homebrew/cask/cmd/info.rb index 9f855b595b..29b5c541b6 100644 --- a/Library/Homebrew/cask/cmd/info.rb +++ b/Library/Homebrew/cask/cmd/info.rb @@ -31,13 +31,13 @@ module Cask output << Formatter.url(cask.homepage) + "\n" if cask.homepage output << installation_info(cask) repo = repo_info(cask) - output << repo + "\n" unless repo.nil? + output << repo + "\n" if repo output << name_info(cask) language = language_info(cask) - output << language unless language.nil? + output << language if language output << artifact_info(cask) + "\n" caveats = Installer.caveats(cask) - output << caveats unless caveats.nil? + output << caveats if caveats output end diff --git a/Library/Homebrew/missing_formula.rb b/Library/Homebrew/missing_formula.rb index 82a8c7ec70..b5af36b02d 100644 --- a/Library/Homebrew/missing_formula.rb +++ b/Library/Homebrew/missing_formula.rb @@ -195,7 +195,7 @@ module Homebrew cask = Cask::CaskLoader.load(name) reason = "Found the following cask named \"#{name}\" instead:\n" - reason << Cask::Cmd::Info.get_info(cask) unless silent + reason << Cask::Cmd::Info.get_info(cask) rescue Cask::CaskUnavailableError nil end From 63a0aa92d1121f5a5288fd645a0a5838f007a991 Mon Sep 17 00:00:00 2001 From: Zach Auten Date: Thu, 21 Mar 2019 17:18:21 -0400 Subject: [PATCH 10/12] Removed info_spec integration test and replaced with unit test in missing_formula_spec --- Library/Homebrew/test/cmd/info_spec.rb | 7 ------- Library/Homebrew/test/missing_formula_spec.rb | 16 ++++++++++++++++ 2 files changed, 16 insertions(+), 7 deletions(-) diff --git a/Library/Homebrew/test/cmd/info_spec.rb b/Library/Homebrew/test/cmd/info_spec.rb index 1f43aff8cb..b318576e63 100644 --- a/Library/Homebrew/test/cmd/info_spec.rb +++ b/Library/Homebrew/test/cmd/info_spec.rb @@ -20,13 +20,6 @@ describe "brew info", :integration_test do end end -describe "brew info", :integration_test, :needs_macos do - it "looks for a Cask with the same name if a given Formula does not exist" do - expect { brew "info", "basic-cask" } - .to output(/Found the following cask named "basic-cask" instead:\nbasic-cask: .+\n/).to_stderr - end -end - describe Homebrew do let(:remote) { "https://github.com/Homebrew/homebrew-core" } diff --git a/Library/Homebrew/test/missing_formula_spec.rb b/Library/Homebrew/test/missing_formula_spec.rb index 0abec2aaed..1600e01e96 100644 --- a/Library/Homebrew/test/missing_formula_spec.rb +++ b/Library/Homebrew/test/missing_formula_spec.rb @@ -136,4 +136,20 @@ describe Homebrew::MissingFormula do it { is_expected.to be_nil } end end + + describe "::cask_reason", :cask do + subject { described_class.cask_reason(formula) } + + context "with a missing formula that exists as a cask" do + let(:formula) { "local-caffeine" } + + it { is_expected.to match(/Found the following cask named "local-caffeine" instead:\nlocal-caffeine: 1.2.3\n/) } + end + + context "with a missing formula that does not share a name with a cask" do + let(:formula) { "missing-formula" } + + it { is_expected.to be_nil } + end + end end From 517083474ae22fa8d58a28e74d8b1b98a7e6fd50 Mon Sep 17 00:00:00 2001 From: Zach Auten Date: Thu, 21 Mar 2019 17:35:38 -0400 Subject: [PATCH 11/12] Removed cask_reason from missing_formula.reason - It won't output anything during a failed 'brew install' - There's a seperate call to MissingFormula.cask_reason when 'brew info' is executed on a cask. --- Library/Homebrew/cmd/info.rb | 2 +- Library/Homebrew/missing_formula.rb | 3 +-- 2 files changed, 2 insertions(+), 3 deletions(-) diff --git a/Library/Homebrew/cmd/info.rb b/Library/Homebrew/cmd/info.rb index b2cd428977..edd8b7d2a6 100644 --- a/Library/Homebrew/cmd/info.rb +++ b/Library/Homebrew/cmd/info.rb @@ -89,7 +89,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) || MissingFormula.cask_reason(f)) $stderr.puts reason end end diff --git a/Library/Homebrew/missing_formula.rb b/Library/Homebrew/missing_formula.rb index b5af36b02d..74c90c457f 100644 --- a/Library/Homebrew/missing_formula.rb +++ b/Library/Homebrew/missing_formula.rb @@ -7,8 +7,7 @@ module Homebrew module MissingFormula class << self def reason(name, silent: false) - cask_reason(name, silent: silent) || blacklisted_reason(name) || - tap_migration_reason(name) || deleted_reason(name, silent: silent) + blacklisted_reason(name) || tap_migration_reason(name) || deleted_reason(name, silent: silent) end def blacklisted_reason(name) From 999c4743d03c2c99a5938305f9541b819e06c070 Mon Sep 17 00:00:00 2001 From: Zach Auten Date: Sun, 24 Mar 2019 15:28:34 -0400 Subject: [PATCH 12/12] Added flag for cask_reason to output cask info or just message with cask name --- Library/Homebrew/cmd/info.rb | 2 +- Library/Homebrew/missing_formula.rb | 12 +++++++----- Library/Homebrew/test/missing_formula_spec.rb | 17 +++++++++++++---- 3 files changed, 21 insertions(+), 10 deletions(-) diff --git a/Library/Homebrew/cmd/info.rb b/Library/Homebrew/cmd/info.rb index edd8b7d2a6..5ea7fb3d05 100644 --- a/Library/Homebrew/cmd/info.rb +++ b/Library/Homebrew/cmd/info.rb @@ -89,7 +89,7 @@ module Homebrew end ofail e.message # No formula with this name, try a missing formula lookup - if (reason = MissingFormula.reason(f) || MissingFormula.cask_reason(f)) + if (reason = MissingFormula.reason(f, show_info: true)) $stderr.puts reason end end diff --git a/Library/Homebrew/missing_formula.rb b/Library/Homebrew/missing_formula.rb index 74c90c457f..3ddfa9346b 100644 --- a/Library/Homebrew/missing_formula.rb +++ b/Library/Homebrew/missing_formula.rb @@ -6,8 +6,9 @@ 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) @@ -189,12 +190,13 @@ module Homebrew end end - def cask_reason(name, silent: false) + def cask_reason(name, silent: false, show_info: false) return if silent cask = Cask::CaskLoader.load(name) - reason = "Found the following cask named \"#{name}\" instead:\n" - reason << Cask::Cmd::Info.get_info(cask) + reason = "Found a cask named \"#{name}\" instead.\n" + reason << Cask::Cmd::Info.get_info(cask) if show_info + reason rescue Cask::CaskUnavailableError nil end diff --git a/Library/Homebrew/test/missing_formula_spec.rb b/Library/Homebrew/test/missing_formula_spec.rb index 1600e01e96..47f2b7667e 100644 --- a/Library/Homebrew/test/missing_formula_spec.rb +++ b/Library/Homebrew/test/missing_formula_spec.rb @@ -138,16 +138,25 @@ describe Homebrew::MissingFormula do end describe "::cask_reason", :cask do - subject { described_class.cask_reason(formula) } + subject { described_class.cask_reason(formula, show_info: show_info) } - context "with a missing formula that exists as a cask" do + 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 the following cask named "local-caffeine" instead:\nlocal-caffeine: 1.2.3\n/) } + it { is_expected.to match(/Found a cask named "local-caffeine" instead./) } end - context "with a missing formula that does not share a name with a cask" do + 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