From 6794a78087991f84efc8f0a959a85c411733f3a3 Mon Sep 17 00:00:00 2001 From: Seeker Date: Wed, 2 Sep 2020 12:24:21 -0700 Subject: [PATCH 01/27] livecheck: add support for casks --- Library/Homebrew/cask/dsl.rb | 17 ++ Library/Homebrew/dev-cmd/livecheck.rb | 26 +-- Library/Homebrew/livecheck.rb | 45 ++++- Library/Homebrew/livecheck/livecheck.rb | 191 ++++++++++++------ .../Homebrew/test/livecheck/livecheck_spec.rb | 35 ++++ Library/Homebrew/test/livecheck_spec.rb | 21 ++ 6 files changed, 246 insertions(+), 89 deletions(-) diff --git a/Library/Homebrew/cask/dsl.rb b/Library/Homebrew/cask/dsl.rb index 8a529036b1..7af922f50d 100644 --- a/Library/Homebrew/cask/dsl.rb +++ b/Library/Homebrew/cask/dsl.rb @@ -3,6 +3,7 @@ require "locale" require "lazy_object" +require "livecheck" require "cask/artifact" @@ -81,6 +82,8 @@ module Cask :version, :appdir, :discontinued?, + :livecheck, + :livecheckable?, *ORDINARY_ARTIFACT_CLASSES.map(&:dsl_key), *ACTIVATABLE_ARTIFACT_CLASSES.map(&:dsl_key), *ARTIFACT_BLOCK_CLASSES.flat_map { |klass| [klass.dsl_key, klass.uninstall_dsl_key] }, @@ -273,6 +276,20 @@ module Cask set_unique_stanza(:auto_updates, auto_updates.nil?) { auto_updates } end + def livecheck(&block) + @livecheck ||= Livecheck.new(self) + return @livecheck unless block_given? + + raise CaskInvalidError.new(cask, "'livecheck' stanza may only appear once.") if @livecheckable + + @livecheckable = true + @livecheck.instance_eval(&block) + end + + def livecheckable? + @livecheckable == true + end + ORDINARY_ARTIFACT_CLASSES.each do |klass| define_method(klass.dsl_key) do |*args| if [*artifacts.map(&:class), klass].include?(Artifact::StageOnly) && diff --git a/Library/Homebrew/dev-cmd/livecheck.rb b/Library/Homebrew/dev-cmd/livecheck.rb index 26af2ffb88..e2ca9e1d8b 100644 --- a/Library/Homebrew/dev-cmd/livecheck.rb +++ b/Library/Homebrew/dev-cmd/livecheck.rb @@ -54,28 +54,28 @@ module Homebrew puts ENV["HOMEBREW_LIVECHECK_WATCHLIST"] if ENV["HOMEBREW_LIVECHECK_WATCHLIST"].present? end - formulae_to_check = if args.tap - Tap.fetch(args.tap).formula_names.map { |name| Formula[name] } + formulae_and_casks_to_check = if args.tap + tap = Tap.fetch(args.tap) + formulae = tap.formula_names.map { |name| Formula[name] } + casks = tap.cask_tokens.map { |token| Cask::CaskLoader.load(token) } + formulae + casks elsif args.installed? - Formula.installed + Formula.installed + Cask::Caskroom.casks elsif args.all? - Formula - elsif (formulae_args = args.named.to_formulae) && formulae_args.present? - formulae_args + Formula.to_a + Cask::Cask.to_a + elsif args.named.present? + args.named.to_formulae_and_casks elsif File.exist?(WATCHLIST_PATH) begin - Pathname.new(WATCHLIST_PATH).read.lines.map do |line| - next if line.start_with?("#") - - Formula[line.strip] - end.compact + names = Pathname.new(WATCHLIST_PATH).read.lines.reject { |line| line.start_with?("#") }.map(&:strip) + CLI::NamedArgs.new(*names).to_formulae_and_casks rescue Errno::ENOENT => e onoe e end end - raise UsageError, "No formulae to check." if formulae_to_check.blank? + raise UsageError, "No formulae or casks to check." if formulae_and_casks_to_check.blank? - Livecheck.livecheck_formulae(formulae_to_check, args) + Livecheck.livecheck_formulae_and_casks(formulae_and_casks_to_check, args) end end diff --git a/Library/Homebrew/livecheck.rb b/Library/Homebrew/livecheck.rb index 651d758946..4900726ff1 100644 --- a/Library/Homebrew/livecheck.rb +++ b/Library/Homebrew/livecheck.rb @@ -1,20 +1,20 @@ # typed: true # frozen_string_literal: true -# The {Livecheck} class implements the DSL methods used in a formula's +# The {Livecheck} class implements the DSL methods used in a formula's or cask's # `livecheck` block and stores related instance variables. Most of these methods # also return the related instance variable when no argument is provided. # # This information is used by the `brew livecheck` command to control its # behavior. class Livecheck - # A very brief description of why the formula is skipped (e.g. `No longer + # A very brief description of why the formula/cask is skipped (e.g. `No longer # developed or maintained`). # @return [String, nil] attr_reader :skip_msg - def initialize(formula) - @formula = formula + def initialize(formula_or_cask) + @formula_or_cask = formula_or_cask @regex = nil @skip = false @skip_msg = nil @@ -40,10 +40,10 @@ class Livecheck # Sets the `@skip` instance variable to `true` and sets the `@skip_msg` # instance variable if a `String` is provided. `@skip` is used to indicate - # that the formula should be skipped and the `skip_msg` very briefly describes - # why the formula is skipped (e.g. "No longer developed or maintained"). + # that the formula/cask should be skipped and the `skip_msg` very briefly + # describes why it is skipped (e.g. "No longer developed or maintained"). # - # @param skip_msg [String] string describing why the formula is skipped + # @param skip_msg [String] string describing why the formula/cask is skipped # @return [Boolean] def skip(skip_msg = nil) if skip_msg.is_a?(String) @@ -55,7 +55,7 @@ class Livecheck @skip = true end - # Should `livecheck` skip this formula? + # Should `livecheck` skip this formula/cask? def skip? @skip end @@ -81,7 +81,7 @@ class Livecheck # Sets the `@url` instance variable to the provided argument or returns the # `@url` instance variable when no argument is provided. The argument can be # a `String` (a URL) or a supported `Symbol` corresponding to a URL in the - # formula (e.g. `:stable`, `:homepage`, or `:head`). + # formula/cask (e.g. `:stable`, `:homepage`, or `:head`). # # @param val [String, Symbol] URL to check for version information # @return [String, nil] @@ -89,10 +89,12 @@ class Livecheck @url = case val when nil return @url + when :cask_url + @formula_or_cask.url when :head, :stable - @formula.send(val).url + @formula_or_cask.send(val).url when :homepage - @formula.homepage + @formula_or_cask.homepage when String val else @@ -100,6 +102,26 @@ class Livecheck end end + # TODO: documentation + def version(val = nil) + @version = case val + when nil + return @version + when :before_comma + [",", :first] + when :after_comma + [",", :second] + when :before_colon + [":", :first] + when :after_colon + [":", :second] + when String + val + else + raise TypeError, "Livecheck#version expects a String or valid Symbol" + end + end + # Returns a `Hash` of all instance variable values. # @return [Hash] def to_hash @@ -109,6 +131,7 @@ class Livecheck "skip_msg" => @skip_msg, "strategy" => @strategy, "url" => @url, + "version" => @version, } end end diff --git a/Library/Homebrew/livecheck/livecheck.rb b/Library/Homebrew/livecheck/livecheck.rb index d27c6b51e4..4a7e722481 100644 --- a/Library/Homebrew/livecheck/livecheck.rb +++ b/Library/Homebrew/livecheck/livecheck.rb @@ -41,18 +41,18 @@ module Homebrew rc ].freeze - # Executes the livecheck logic for each formula in the `formulae_to_check` array - # and prints the results. + # Executes the livecheck logic for each formula/cask in the + # `formulae_and_casks_to_check` array and prints the results. # @return [nil] - def livecheck_formulae(formulae_to_check, args) + def livecheck_formulae_and_casks(formulae_and_casks_to_check, args) # Identify any non-homebrew/core taps in use for current formulae non_core_taps = {} - formulae_to_check.each do |f| - next if f.tap.blank? - next if f.tap.name == CoreTap.instance.name - next if non_core_taps[f.tap.name] + formulae_and_casks_to_check.each do |fc| + next if fc.tap.blank? + next if fc.tap.name == CoreTap.instance.name + next if non_core_taps[fc.tap.name] - non_core_taps[f.tap.name] = f.tap + non_core_taps[fc.tap.name] = fc.tap end non_core_taps = non_core_taps.sort.to_h @@ -73,10 +73,10 @@ module Homebrew has_a_newer_upstream_version = false if args.json? && !args.quiet? && $stderr.tty? - total_formulae = if formulae_to_check == Formula - formulae_to_check.count + total_formulae = if formulae_and_casks_to_check == Formula + formulae_and_casks_to_check.count else - formulae_to_check.length + formulae_and_casks_to_check.length end Tty.with($stderr) do |stderr| @@ -92,7 +92,10 @@ module Homebrew ) end - formulae_checked = formulae_to_check.sort.map.with_index do |formula, i| + formulae_checked = formulae_and_casks_to_check.sort_by(&:name).map.with_index do |formula_or_cask, i| + formula = formula_or_cask if formula_or_cask.is_a?(Formula) + cask = formula_or_cask if formula_or_cask.is_a?(Cask::Cask) + if args.debug? && i.positive? puts <<~EOS @@ -101,7 +104,7 @@ module Homebrew EOS end - skip_result = skip_conditions(formula, args: args) + skip_result = skip_conditions(formula_or_cask, args: args) next skip_result if skip_result != false formula.head&.downloader&.shutup! @@ -110,17 +113,32 @@ module Homebrew # head-only formulae. A formula with `stable` and `head` that's # installed using `--head` will still use the `stable` version for # comparison. - current = if formula.head_only? - formula.any_installed_version.version.commit + livecheck_version = formula_or_cask.livecheck.version + current = if livecheck_version.is_a?(String) + livecheck_version else - formula.stable.version + version = if formula + if formula.head_only? + formula.any_installed_version.version.commit + else + formula.stable.version + end + else + Version.new(formula_or_cask.version) + end + if livecheck_version.is_a?(Array) + separator, method = livecheck_version + Version.new(version.to_s.split(separator, 2).try(method)) + else + version + end end - latest = if formula.head_only? - formula.head.downloader.fetch_last_commit - else - version_info = latest_version(formula, args: args) + latest = if formula&.stable? || cask + version_info = latest_version(formula_or_cask, args: args) version_info[:latest] if version_info.present? + else + formula.head.downloader.fetch_last_commit end if latest.blank? @@ -129,14 +147,14 @@ module Homebrew next version_info if version_info.is_a?(Hash) && version_info[:status] && version_info[:messages] - next status_hash(formula, "error", [no_versions_msg], args: args) + next status_hash(formula_or_cask, "error", [no_versions_msg], args: args) end if (m = latest.to_s.match(/(.*)-release$/)) && !current.to_s.match(/.*-release$/) latest = Version.new(m[1]) end - is_outdated = if formula.head_only? + is_outdated = if formula&.head_only? # A HEAD-only formula is considered outdated if the latest upstream # commit hash is different than the installed version's commit hash (current != latest) @@ -144,10 +162,9 @@ module Homebrew (current < latest) end - is_newer_than_upstream = formula.stable? && (current > latest) + is_newer_than_upstream = (formula&.stable? || cask) && (current > latest) info = { - formula: formula_name(formula, args: args), version: { current: current.to_s, latest: latest.to_s, @@ -155,10 +172,12 @@ module Homebrew newer_than_upstream: is_newer_than_upstream, }, meta: { - livecheckable: formula.livecheckable?, + livecheckable: formula_or_cask.livecheckable?, }, } - info[:meta][:head_only] = true if formula.head_only? + info[:formula] = formula_name(formula, args: args) if formula + info[:cask] = cask_name(cask, args: args) if cask + info[:meta][:head_only] = true if formula&.head_only? info[:meta].merge!(version_info[:meta]) if version_info.present? && version_info.key?(:meta) next if args.newer_only? && !info[:version][:outdated] @@ -178,9 +197,9 @@ module Homebrew if args.json? progress&.increment - status_hash(formula, "error", [e.to_s], args: args) + status_hash(formula_or_cask, "error", [e.to_s], args: args) elsif !args.quiet? - onoe "#{Tty.blue}#{formula_name(formula, args: args)}#{Tty.reset}: #{e}" + onoe "#{Tty.blue}#{formula_or_cask_name(formula_or_cask, args: args)}#{Tty.reset}: #{e}" nil end end @@ -201,6 +220,18 @@ module Homebrew puts JSON.generate(formulae_checked.compact) end + def formula_or_cask_name(formula_or_cask, args:) + if formula_or_cask.is_a?(Formula) + formula_name(formula_or_cask, args: args) + else + cask_name(formula_or_cask, args: args) + end + end + + def cask_name(cask, args:) + args.full_name? ? cask.full_name : cask.token + end + # Returns the fully-qualified name of a formula if the `full_name` argument is # provided; returns the name otherwise. # @return [String] @@ -208,18 +239,25 @@ module Homebrew args.full_name? ? formula.full_name : formula.name end - def status_hash(formula, status_str, messages = nil, args:) + def status_hash(formula_or_cask, status_str, messages = nil, args:) + formula = formula_or_cask if formula_or_cask.is_a?(Formula) + status_hash = { - formula: formula_name(formula, args: args), - status: status_str, + status: status_str, } status_hash[:messages] = messages if messages.is_a?(Array) + if formula + status_hash[:formula] = formula_name(formula, args: args) + else + status_hash[:cask] = formula_name(formula_or_cask, args: args) + end + if args.verbose? status_hash[:meta] = { - livecheckable: formula.livecheckable?, + livecheckable: formula_or_cask.livecheckable?, } - status_hash[:meta][:head_only] = true if formula.head_only? + status_hash[:meta][:head_only] = true if formula&.head_only? end status_hash @@ -228,54 +266,56 @@ module Homebrew # If a formula has to be skipped, it prints or returns a Hash contaning the reason # for doing so; returns false otherwise. # @return [Hash, nil, Boolean] - def skip_conditions(formula, args:) - if formula.deprecated? && !formula.livecheckable? + def skip_conditions(formula_or_cask, args:) + formula = formula_or_cask if formula_or_cask.is_a?(Formula) + + if formula&.deprecated? && !formula.livecheckable? return status_hash(formula, "deprecated", args: args) if args.json? - puts "#{Tty.red}#{formula_name(formula, args: args)}#{Tty.reset} : deprecated" unless args.quiet? - return - end + puts "#{Tty.red}#{formula_name(formula, args: args)}#{Tty.reset} : deprecated" unless args.quiet? + return + end - if formula.disabled? && !formula.livecheckable? + if formula&.disabled? && !formula.livecheckable? return status_hash(formula, "disabled", args: args) if args.json? puts "#{Tty.red}#{formula_name(formula, args: args)}#{Tty.reset} : disabled" unless args.quiet? return end - if formula.versioned_formula? && !formula.livecheckable? + if formula&.versioned_formula? && !formula.livecheckable? return status_hash(formula, "versioned", args: args) if args.json? - puts "#{Tty.red}#{formula_name(formula, args: args)}#{Tty.reset} : versioned" unless args.quiet? - return - end + puts "#{Tty.red}#{formula_name(formula, args: args)}#{Tty.reset} : versioned" unless args.quiet? + return + end - if formula.head_only? && !formula.any_version_installed? + if formula&.head_only? && !formula.any_version_installed? head_only_msg = "HEAD only formula must be installed to be livecheckable" return status_hash(formula, "error", [head_only_msg], args: args) if args.json? - puts "#{Tty.red}#{formula_name(formula, args: args)}#{Tty.reset} : #{head_only_msg}" unless args.quiet? - return - end + puts "#{Tty.red}#{formula_name(formula, args: args)}#{Tty.reset} : #{head_only_msg}" unless args.quiet? + return + end - is_gist = formula.stable&.url&.include?("gist.github.com") - if formula.livecheck.skip? || is_gist - skip_msg = if formula.livecheck.skip_msg.is_a?(String) && - formula.livecheck.skip_msg.present? - formula.livecheck.skip_msg.to_s + is_gist = formula&.stable&.url&.include?("gist.github.com") + if formula_or_cask.livecheck.skip? || is_gist + skip_msg = if formula_or_cask.livecheck.skip_msg.is_a?(String) && + formula_or_cask.livecheck.skip_msg.present? + formula_or_cask.livecheck.skip_msg.to_s elsif is_gist "Stable URL is a GitHub Gist" else "" end - return status_hash(formula, "skipped", (skip_msg.blank? ? nil : [skip_msg]), args: args) if args.json? + return status_hash(formula_or_cask, "skipped", (skip_msg.blank? ? nil : [skip_msg]), args: args) if args.json? unless args.quiet? - puts "#{Tty.red}#{formula_name(formula, args: args)}#{Tty.reset} : skipped" \ + puts "#{Tty.red}#{formula_or_cask_name(formula_or_cask, args: args)}#{Tty.reset} : skipped" \ "#{" - #{skip_msg}" if skip_msg.present?}" end - return + return end false @@ -284,8 +324,8 @@ module Homebrew # Formats and prints the livecheck result for a formula. # @return [nil] def print_latest_version(info, args:) - formula_s = "#{Tty.blue}#{info[:formula]}#{Tty.reset}" - formula_s += " (guessed)" if !info[:meta][:livecheckable] && args.verbose? + formula_or_cask_s = "#{Tty.blue}#{info[:formula] || info[:cask]}#{Tty.reset}" + formula_or_cask_s += " (guessed)" if !info[:meta][:livecheckable] && args.verbose? current_s = if info[:version][:newer_than_upstream] "#{Tty.red}#{info[:version][:current]}#{Tty.reset}" @@ -299,12 +339,12 @@ module Homebrew info[:version][:latest] end - puts "#{formula_s} : #{current_s} ==> #{latest_s}" + puts "#{formula_or_cask_s} : #{current_s} ==> #{latest_s}" end # Returns an Array containing the formula URLs that can be used by livecheck. # @return [Array] - def checkable_urls(formula) + def checkable_formula_urls(formula) urls = [] urls << formula.head.url if formula.head if formula.stable @@ -316,6 +356,21 @@ module Homebrew urls.compact end + def checkable_cask_urls(cask) + urls = [] + urls << cask.url.to_s + urls << cask.homepage if cask.homepage + urls.compact + end + + def checkable_urls(formula_or_cask) + if formula_or_cask.is_a?(Formula) + checkable_formula_urls(formula_or_cask) + else + checkable_cask_urls(formula_or_cask) + end + end + # Preprocesses and returns the URL used by livecheck. # @return [String] def preprocess_url(url) @@ -357,20 +412,26 @@ module Homebrew # Identifies the latest version of the formula and returns a Hash containing # the version information. Returns nil if a latest version couldn't be found. # @return [Hash, nil] - def latest_version(formula, args:) - has_livecheckable = formula.livecheckable? - livecheck = formula.livecheck + def latest_version(formula_or_cask, args:) + formula = formula_or_cask if formula_or_cask.is_a?(Formula) + + has_livecheckable = formula_or_cask.livecheckable? + livecheck = formula_or_cask.livecheck livecheck_regex = livecheck.regex livecheck_strategy = livecheck.strategy livecheck_url = livecheck.url urls = [livecheck_url] if livecheck_url.present? - urls ||= checkable_urls(formula) + urls ||= checkable_urls(formula_or_cask) if args.debug? puts - puts "Formula: #{formula_name(formula, args: args)}" - puts "Head only?: true" if formula.head_only? + if formula + puts "Formula: #{formula_name(formula, args: args)}" + puts "Head only?: true" if formula.head_only? + else + puts "Cask: #{cask_name(formula_or_cask, args: args)}" + end puts "Livecheckable?: #{has_livecheckable ? "Yes" : "No"}" end diff --git a/Library/Homebrew/test/livecheck/livecheck_spec.rb b/Library/Homebrew/test/livecheck/livecheck_spec.rb index 261896abd9..0323c1e1a8 100644 --- a/Library/Homebrew/test/livecheck/livecheck_spec.rb +++ b/Library/Homebrew/test/livecheck/livecheck_spec.rb @@ -74,6 +74,24 @@ describe Homebrew::Livecheck do end end + let(:c) do + Cask::CaskLoader.load(+<<-RUBY) + cask "test" do + version "0.0.1,2" + + url "https://brew.sh/test-0.0.1.tgz" + name "Test" + homepage "https://brew.sh" + + livecheck do + url "https://formulae.brew.sh/api/formula/ruby.json" + version :before_comma + regex(/"stable":"(\d+(?:\.\d+)+)"/i) + end + end + RUBY + end + let(:args) { double("livecheck_args", full_name?: false, json?: false, quiet?: false, verbose?: true) } describe "::formula_name" do @@ -88,6 +106,18 @@ describe Homebrew::Livecheck do end end + describe "::cask_name" do + it "returns the token of the cask" do + expect(livecheck.cask_name(c, args: args)).to eq("test") + end + + it "returns the full name of the cask" do + allow(args).to receive(:full_name?).and_return(true) + + expect(livecheck.cask_name(c, args: args)).to eq("test") + end + end + describe "::status_hash" do it "returns a hash containing the livecheck status" do expect(livecheck.status_hash(f, "error", ["Unable to get versions"], args: args)) @@ -142,6 +172,10 @@ describe Homebrew::Livecheck do it "returns false for a non-skippable formula" do expect(livecheck.skip_conditions(f, args: args)).to eq(false) end + + it "returns false for a non-skippable cask" do + expect(livecheck.skip_conditions(c, args: args)).to eq(false) + end end describe "::checkable_urls" do @@ -150,6 +184,7 @@ describe Homebrew::Livecheck do .to eq( ["https://github.com/Homebrew/brew.git", "https://brew.sh/test-0.0.1.tgz", "https://brew.sh"], ) + expect(livecheck.checkable_urls(c)).to eq(["https://brew.sh/test-0.0.1.tgz", "https://brew.sh"]) end end diff --git a/Library/Homebrew/test/livecheck_spec.rb b/Library/Homebrew/test/livecheck_spec.rb index 84ed8df539..2352d44b50 100644 --- a/Library/Homebrew/test/livecheck_spec.rb +++ b/Library/Homebrew/test/livecheck_spec.rb @@ -107,6 +107,26 @@ describe Livecheck do end end + describe "#version" do + it "returns nil if not set" do + expect(livecheckable.version).to be nil + end + + it "returns value if set" do + livecheckable.version("foo") + expect(livecheckable.version).to eq("foo") + + livecheckable.version(:before_comma) + expect(livecheckable.version).to eq([",", :first]) + end + + it "raises a TypeError if the argument isn't a String or Symbol" do + expect { + livecheckable.version(/foo/) + }.to raise_error(TypeError, "Livecheck#version expects a String or valid Symbol") + end + end + describe "#to_hash" do it "returns a Hash of all instance variables" do expect(livecheckable.to_hash).to eq( @@ -116,6 +136,7 @@ describe Livecheck do "skip_msg" => nil, "strategy" => nil, "url" => nil, + "version" => nil, }, ) end From 0a766350b5c11acda90a539ad0b242637f3791d9 Mon Sep 17 00:00:00 2001 From: Seeker Date: Wed, 2 Sep 2020 12:39:30 -0700 Subject: [PATCH 02/27] Fix :cask_url and allow :appcast --- Library/Homebrew/livecheck.rb | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/Library/Homebrew/livecheck.rb b/Library/Homebrew/livecheck.rb index 4900726ff1..52cd8a8dbb 100644 --- a/Library/Homebrew/livecheck.rb +++ b/Library/Homebrew/livecheck.rb @@ -81,8 +81,7 @@ class Livecheck # Sets the `@url` instance variable to the provided argument or returns the # `@url` instance variable when no argument is provided. The argument can be # a `String` (a URL) or a supported `Symbol` corresponding to a URL in the - # formula/cask (e.g. `:stable`, `:homepage`, or `:head`). - # + # formula/cask (e.g. `:stable`, `:homepage`, `:head`, `:cask_url`, `:appcast`). # @param val [String, Symbol] URL to check for version information # @return [String, nil] def url(val = nil) @@ -90,7 +89,9 @@ class Livecheck when nil return @url when :cask_url - @formula_or_cask.url + @formula_or_cask.url.to_s + when :appcast + @formula_or_cask.appcast.to_s when :head, :stable @formula_or_cask.send(val).url when :homepage From 71ccd3ccaa640e7934266b6e4cb447e295731e7d Mon Sep 17 00:00:00 2001 From: Seeker Date: Thu, 3 Sep 2020 08:04:51 -0700 Subject: [PATCH 03/27] Fix typo --- Library/Homebrew/livecheck/livecheck.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Library/Homebrew/livecheck/livecheck.rb b/Library/Homebrew/livecheck/livecheck.rb index 4a7e722481..3aaa2ebcc9 100644 --- a/Library/Homebrew/livecheck/livecheck.rb +++ b/Library/Homebrew/livecheck/livecheck.rb @@ -250,7 +250,7 @@ module Homebrew if formula status_hash[:formula] = formula_name(formula, args: args) else - status_hash[:cask] = formula_name(formula_or_cask, args: args) + status_hash[:cask] = cask_name(formula_or_cask, args: args) end if args.verbose? From bf03893227dd7602d14852ff4dd34325dd4840df Mon Sep 17 00:00:00 2001 From: Seeker Date: Thu, 3 Sep 2020 14:13:16 -0700 Subject: [PATCH 04/27] Add appcast to checkable cask urls --- Library/Homebrew/livecheck/livecheck.rb | 1 + 1 file changed, 1 insertion(+) diff --git a/Library/Homebrew/livecheck/livecheck.rb b/Library/Homebrew/livecheck/livecheck.rb index 3aaa2ebcc9..792af949ba 100644 --- a/Library/Homebrew/livecheck/livecheck.rb +++ b/Library/Homebrew/livecheck/livecheck.rb @@ -358,6 +358,7 @@ module Homebrew def checkable_cask_urls(cask) urls = [] + urls << cask.appcast.to_s if cask.appcast urls << cask.url.to_s urls << cask.homepage if cask.homepage urls.compact From 4b87da4da963470a134b8d10844d17ca9d4a5c15 Mon Sep 17 00:00:00 2001 From: Seeker Date: Thu, 3 Sep 2020 20:09:56 -0700 Subject: [PATCH 05/27] Initial small fixes - Skip blank lines in watchlist - Initialize Livecheck#version as nil - Simplify livecheck_version logic - Make test a bit more understandable --- Library/Homebrew/dev-cmd/livecheck.rb | 4 +++- Library/Homebrew/livecheck.rb | 5 +++-- Library/Homebrew/livecheck/livecheck.rb | 15 +++++---------- Library/Homebrew/test/livecheck_spec.rb | 4 ++-- 4 files changed, 13 insertions(+), 15 deletions(-) diff --git a/Library/Homebrew/dev-cmd/livecheck.rb b/Library/Homebrew/dev-cmd/livecheck.rb index e2ca9e1d8b..39c59fb77f 100644 --- a/Library/Homebrew/dev-cmd/livecheck.rb +++ b/Library/Homebrew/dev-cmd/livecheck.rb @@ -67,7 +67,9 @@ module Homebrew args.named.to_formulae_and_casks elsif File.exist?(WATCHLIST_PATH) begin - names = Pathname.new(WATCHLIST_PATH).read.lines.reject { |line| line.start_with?("#") }.map(&:strip) + names = Pathname.new(WATCHLIST_PATH).read.lines + .reject { |line| line.start_with?("#") || line.blank? } + .map(&:strip) CLI::NamedArgs.new(*names).to_formulae_and_casks rescue Errno::ENOENT => e onoe e diff --git a/Library/Homebrew/livecheck.rb b/Library/Homebrew/livecheck.rb index 52cd8a8dbb..7311cffe4c 100644 --- a/Library/Homebrew/livecheck.rb +++ b/Library/Homebrew/livecheck.rb @@ -20,6 +20,7 @@ class Livecheck @skip_msg = nil @strategy = nil @url = nil + @version = nil end # Sets the `@regex` instance variable to the provided `Regexp` or returns the @@ -88,10 +89,10 @@ class Livecheck @url = case val when nil return @url - when :cask_url - @formula_or_cask.url.to_s when :appcast @formula_or_cask.appcast.to_s + when :cask_url + @formula_or_cask.url.to_s when :head, :stable @formula_or_cask.send(val).url when :homepage diff --git a/Library/Homebrew/livecheck/livecheck.rb b/Library/Homebrew/livecheck/livecheck.rb index 792af949ba..66af0adb32 100644 --- a/Library/Homebrew/livecheck/livecheck.rb +++ b/Library/Homebrew/livecheck/livecheck.rb @@ -115,9 +115,11 @@ module Homebrew # comparison. livecheck_version = formula_or_cask.livecheck.version current = if livecheck_version.is_a?(String) - livecheck_version - else - version = if formula + Version.new(livecheck_version) + elsif livecheck_version.is_a?(Array) + separator, method = livecheck_version + Version.new(formula_or_cask.version.to_s.split(separator, 2).try(method)) + elsif formula if formula.head_only? formula.any_installed_version.version.commit else @@ -125,13 +127,6 @@ module Homebrew end else Version.new(formula_or_cask.version) - end - if livecheck_version.is_a?(Array) - separator, method = livecheck_version - Version.new(version.to_s.split(separator, 2).try(method)) - else - version - end end latest = if formula&.stable? || cask diff --git a/Library/Homebrew/test/livecheck_spec.rb b/Library/Homebrew/test/livecheck_spec.rb index 2352d44b50..e39af8afd1 100644 --- a/Library/Homebrew/test/livecheck_spec.rb +++ b/Library/Homebrew/test/livecheck_spec.rb @@ -113,8 +113,8 @@ describe Livecheck do end it "returns value if set" do - livecheckable.version("foo") - expect(livecheckable.version).to eq("foo") + livecheckable.version("1.2.3") + expect(livecheckable.version).to eq("1.2.3") livecheckable.version(:before_comma) expect(livecheckable.version).to eq([",", :first]) From 0e8cebbb5b31837a691a59397ab58be54af3740e Mon Sep 17 00:00:00 2001 From: Seeker Date: Thu, 3 Sep 2020 20:26:13 -0700 Subject: [PATCH 06/27] Store Livecheck#version as symbol or string --- Library/Homebrew/livecheck.rb | 18 ++++-------------- Library/Homebrew/livecheck/livecheck.rb | 2 ++ Library/Homebrew/test/livecheck_spec.rb | 2 +- 3 files changed, 7 insertions(+), 15 deletions(-) diff --git a/Library/Homebrew/livecheck.rb b/Library/Homebrew/livecheck.rb index 7311cffe4c..7f329e0996 100644 --- a/Library/Homebrew/livecheck.rb +++ b/Library/Homebrew/livecheck.rb @@ -106,22 +106,12 @@ class Livecheck # TODO: documentation def version(val = nil) - @version = case val - when nil - return @version - when :before_comma - [",", :first] - when :after_comma - [",", :second] - when :before_colon - [":", :first] - when :after_colon - [":", :second] - when String - val - else + return @version if val.nil? + unless val.is_a?(String) || (val.is_a?(Symbol) && Cask::DSL::Version.method_defined?(val)) raise TypeError, "Livecheck#version expects a String or valid Symbol" end + + @version = val end # Returns a `Hash` of all instance variable values. diff --git a/Library/Homebrew/livecheck/livecheck.rb b/Library/Homebrew/livecheck/livecheck.rb index 66af0adb32..ae8441eb5a 100644 --- a/Library/Homebrew/livecheck/livecheck.rb +++ b/Library/Homebrew/livecheck/livecheck.rb @@ -125,6 +125,8 @@ module Homebrew else formula.stable.version end + elsif livecheck_version.is_a?(Symbol) + Version.new(Cask::DSL::Version.new(formula_or_cask.version).try(livecheck_version)) else Version.new(formula_or_cask.version) end diff --git a/Library/Homebrew/test/livecheck_spec.rb b/Library/Homebrew/test/livecheck_spec.rb index e39af8afd1..0aa2905d81 100644 --- a/Library/Homebrew/test/livecheck_spec.rb +++ b/Library/Homebrew/test/livecheck_spec.rb @@ -117,7 +117,7 @@ describe Livecheck do expect(livecheckable.version).to eq("1.2.3") livecheckable.version(:before_comma) - expect(livecheckable.version).to eq([",", :first]) + expect(livecheckable.version).to eq(:before_comma) end it "raises a TypeError if the argument isn't a String or Symbol" do From e40bc65414e72dda83343d9dae6560ccb6e37950 Mon Sep 17 00:00:00 2001 From: Seeker Date: Thu, 3 Sep 2020 20:33:24 -0700 Subject: [PATCH 07/27] Sort formulae_and_casks_to_check in `Livecheck#livecheck` --- Library/Homebrew/dev-cmd/livecheck.rb | 2 ++ Library/Homebrew/livecheck/livecheck.rb | 2 +- 2 files changed, 3 insertions(+), 1 deletion(-) diff --git a/Library/Homebrew/dev-cmd/livecheck.rb b/Library/Homebrew/dev-cmd/livecheck.rb index 39c59fb77f..c1d2cfc206 100644 --- a/Library/Homebrew/dev-cmd/livecheck.rb +++ b/Library/Homebrew/dev-cmd/livecheck.rb @@ -74,6 +74,8 @@ module Homebrew rescue Errno::ENOENT => e onoe e end + end.sort_by do |formula_or_cask| + formula_or_cask.respond_to?("token") ? formula_or_cask.token : formula_or_cask.name end raise UsageError, "No formulae or casks to check." if formulae_and_casks_to_check.blank? diff --git a/Library/Homebrew/livecheck/livecheck.rb b/Library/Homebrew/livecheck/livecheck.rb index ae8441eb5a..bd7c88e50e 100644 --- a/Library/Homebrew/livecheck/livecheck.rb +++ b/Library/Homebrew/livecheck/livecheck.rb @@ -92,7 +92,7 @@ module Homebrew ) end - formulae_checked = formulae_and_casks_to_check.sort_by(&:name).map.with_index do |formula_or_cask, i| + formulae_checked = formulae_and_casks_to_check.map.with_index do |formula_or_cask, i| formula = formula_or_cask if formula_or_cask.is_a?(Formula) cask = formula_or_cask if formula_or_cask.is_a?(Cask::Cask) From 064e93df5b32c9914fcfaf9702cd32ba4d7b7ebb Mon Sep 17 00:00:00 2001 From: Seeker Date: Thu, 3 Sep 2020 20:43:21 -0700 Subject: [PATCH 08/27] Collapse checkable_urls methods into one method --- Library/Homebrew/livecheck/livecheck.rb | 42 ++++++++++--------------- 1 file changed, 17 insertions(+), 25 deletions(-) diff --git a/Library/Homebrew/livecheck/livecheck.rb b/Library/Homebrew/livecheck/livecheck.rb index bd7c88e50e..29b3a5c076 100644 --- a/Library/Homebrew/livecheck/livecheck.rb +++ b/Library/Homebrew/livecheck/livecheck.rb @@ -339,34 +339,26 @@ module Homebrew puts "#{formula_or_cask_s} : #{current_s} ==> #{latest_s}" end - # Returns an Array containing the formula URLs that can be used by livecheck. + # Returns an Array containing the formula/cask URLs that can be used by livecheck. # @return [Array] - def checkable_formula_urls(formula) - urls = [] - urls << formula.head.url if formula.head - if formula.stable - urls << formula.stable.url - urls.concat(formula.stable.mirrors) - end - urls << formula.homepage if formula.homepage - - urls.compact - end - - def checkable_cask_urls(cask) - urls = [] - urls << cask.appcast.to_s if cask.appcast - urls << cask.url.to_s - urls << cask.homepage if cask.homepage - urls.compact - end - def checkable_urls(formula_or_cask) - if formula_or_cask.is_a?(Formula) - checkable_formula_urls(formula_or_cask) - else - checkable_cask_urls(formula_or_cask) + urls = [] + + case formula_or_cask + when Formula + urls << formula_or_cask.head.url if formula_or_cask.head + if formula_or_cask.stable + urls << formula_or_cask.stable.url + urls.concat(formula_or_cask.stable.mirrors) + end + urls << formula_or_cask.homepage if formula_or_cask.homepage + when Cask::Cask + urls << formula_or_cask.appcast.to_s if formula_or_cask.appcast + urls << formula_or_cask.url.to_s if formula_or_cask.url + urls << formula_or_cask.homepage if formula_or_cask.homepage end + + urls.compact end # Preprocesses and returns the URL used by livecheck. From f06f83ca69f53a272daa1a3874201a34f2298f43 Mon Sep 17 00:00:00 2001 From: Seeker Date: Thu, 3 Sep 2020 20:55:33 -0700 Subject: [PATCH 09/27] Rename `livecheck_formulae_and_casks` to `run_checks` --- Library/Homebrew/dev-cmd/livecheck.rb | 2 +- Library/Homebrew/livecheck/livecheck.rb | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/Library/Homebrew/dev-cmd/livecheck.rb b/Library/Homebrew/dev-cmd/livecheck.rb index c1d2cfc206..47d03bf50e 100644 --- a/Library/Homebrew/dev-cmd/livecheck.rb +++ b/Library/Homebrew/dev-cmd/livecheck.rb @@ -80,6 +80,6 @@ module Homebrew raise UsageError, "No formulae or casks to check." if formulae_and_casks_to_check.blank? - Livecheck.livecheck_formulae_and_casks(formulae_and_casks_to_check, args) + Livecheck.run_checks(formulae_and_casks_to_check, args) end end diff --git a/Library/Homebrew/livecheck/livecheck.rb b/Library/Homebrew/livecheck/livecheck.rb index 29b3a5c076..737b139e4c 100644 --- a/Library/Homebrew/livecheck/livecheck.rb +++ b/Library/Homebrew/livecheck/livecheck.rb @@ -44,7 +44,7 @@ module Homebrew # Executes the livecheck logic for each formula/cask in the # `formulae_and_casks_to_check` array and prints the results. # @return [nil] - def livecheck_formulae_and_casks(formulae_and_casks_to_check, args) + def run_checks(formulae_and_casks_to_check, args) # Identify any non-homebrew/core taps in use for current formulae non_core_taps = {} formulae_and_casks_to_check.each do |fc| From a7b36ee9ea3de8a7b787cc192f7f540fc270c85e Mon Sep 17 00:00:00 2001 From: Seeker Date: Thu, 3 Sep 2020 21:18:04 -0700 Subject: [PATCH 10/27] Update help text --- Library/Homebrew/dev-cmd/livecheck.rb | 18 +++++++++--------- 1 file changed, 9 insertions(+), 9 deletions(-) diff --git a/Library/Homebrew/dev-cmd/livecheck.rb b/Library/Homebrew/dev-cmd/livecheck.rb index 47d03bf50e..d82119af19 100644 --- a/Library/Homebrew/dev-cmd/livecheck.rb +++ b/Library/Homebrew/dev-cmd/livecheck.rb @@ -20,23 +20,23 @@ module Homebrew def livecheck_args Homebrew::CLI::Parser.new do usage_banner <<~EOS - `livecheck` [] + `livecheck` [|] - Check for newer versions of formulae from upstream. + Check for newer versions of formulae and/or casks from upstream. - If no formula argument is passed, the list of formulae to check is taken from `HOMEBREW_LIVECHECK_WATCHLIST` - or `~/.brew_livecheck_watchlist`. + If no formula or cask argument is passed, the list of formulae and casks to check is taken from + `HOMEBREW_LIVECHECK_WATCHLIST` or `~/.brew_livecheck_watchlist`. EOS switch "--full-name", - description: "Print formulae with fully-qualified names." + description: "Print formulae/casks with fully-qualified names." flag "--tap=", - description: "Check formulae within the given tap, specified as `/`." + description: "Check formulae/casks within the given tap, specified as `/`." switch "--all", - description: "Check all available formulae." + description: "Check all available formulae/casks." switch "--installed", - description: "Check formulae that are currently installed." + description: "Check formulae/casks that are currently installed." switch "--newer-only", - description: "Show the latest version only if it's newer than the formula." + description: "Show the latest version only if it's newer than the formula/cask." switch "--json", description: "Output information in JSON format." switch "-q", "--quiet", From 90067ea8ed69de4aba6b4ff20173bd1cd711eb53 Mon Sep 17 00:00:00 2001 From: Seeker Date: Thu, 3 Sep 2020 21:33:08 -0700 Subject: [PATCH 11/27] Add `--formula/--formulae` and `--cask/--casks` --- Library/Homebrew/dev-cmd/livecheck.rb | 34 ++++++++++++++++++++++----- 1 file changed, 28 insertions(+), 6 deletions(-) diff --git a/Library/Homebrew/dev-cmd/livecheck.rb b/Library/Homebrew/dev-cmd/livecheck.rb index d82119af19..7049215da4 100644 --- a/Library/Homebrew/dev-cmd/livecheck.rb +++ b/Library/Homebrew/dev-cmd/livecheck.rb @@ -41,8 +41,13 @@ module Homebrew description: "Output information in JSON format." switch "-q", "--quiet", description: "Suppress warnings, don't print a progress bar for JSON output." + switch "--formula", "--formulae", + description: "Only check formulae." + switch "--cask", "--casks", + description: "Only check casks." conflicts "--debug", "--json" conflicts "--tap=", "--all", "--installed" + conflicts "--cask", "--formula" end end @@ -56,21 +61,38 @@ module Homebrew formulae_and_casks_to_check = if args.tap tap = Tap.fetch(args.tap) - formulae = tap.formula_names.map { |name| Formula[name] } - casks = tap.cask_tokens.map { |token| Cask::CaskLoader.load(token) } + formulae = !args.cask? ? tap.formula_names.map { |name| Formula[name] } : [] + casks = !args.formula? ? tap.cask_tokens.map { |token| Cask::CaskLoader.load(token) } : [] formulae + casks elsif args.installed? - Formula.installed + Cask::Caskroom.casks + formulae = !args.cask? ? Formula.installed : [] + casks = !args.formula? ? Cask::Caskroom.casks : [] + formulae + casks elsif args.all? - Formula.to_a + Cask::Cask.to_a + formulae = !args.cask? ? Formula.to_a : [] + casks = !args.formula? ? Cask::Cask.to_a : [] + formulae + casks elsif args.named.present? - args.named.to_formulae_and_casks + if args.formula? + args.named.to_formulae + elsif args.cask? + args.named.to_casks + else + args.named.to_formulae_and_casks + end elsif File.exist?(WATCHLIST_PATH) begin names = Pathname.new(WATCHLIST_PATH).read.lines .reject { |line| line.start_with?("#") || line.blank? } .map(&:strip) - CLI::NamedArgs.new(*names).to_formulae_and_casks + named_args = CLI::NamedArgs.new(*names) + if args.formula? + named_args.to_formulae + elsif args.cask? + named_args.to_casks + else + named_args.to_formulae_and_casks + end rescue Errno::ENOENT => e onoe e end From 3b366d05b9c8a29a89bbf773fd2557024ea977b1 Mon Sep 17 00:00:00 2001 From: Markus Reiter Date: Fri, 11 Dec 2020 16:24:49 +0100 Subject: [PATCH 12/27] Fix code style. --- Library/Homebrew/cask/dsl.rb | 2 +- Library/Homebrew/dev-cmd/livecheck.rb | 12 ++++----- Library/Homebrew/livecheck/livecheck.rb | 34 ++++++++++++------------- 3 files changed, 24 insertions(+), 24 deletions(-) diff --git a/Library/Homebrew/cask/dsl.rb b/Library/Homebrew/cask/dsl.rb index 7af922f50d..6255265ffa 100644 --- a/Library/Homebrew/cask/dsl.rb +++ b/Library/Homebrew/cask/dsl.rb @@ -278,7 +278,7 @@ module Cask def livecheck(&block) @livecheck ||= Livecheck.new(self) - return @livecheck unless block_given? + return @livecheck unless block raise CaskInvalidError.new(cask, "'livecheck' stanza may only appear once.") if @livecheckable diff --git a/Library/Homebrew/dev-cmd/livecheck.rb b/Library/Homebrew/dev-cmd/livecheck.rb index 7049215da4..ae2919a0df 100644 --- a/Library/Homebrew/dev-cmd/livecheck.rb +++ b/Library/Homebrew/dev-cmd/livecheck.rb @@ -61,16 +61,16 @@ module Homebrew formulae_and_casks_to_check = if args.tap tap = Tap.fetch(args.tap) - formulae = !args.cask? ? tap.formula_names.map { |name| Formula[name] } : [] - casks = !args.formula? ? tap.cask_tokens.map { |token| Cask::CaskLoader.load(token) } : [] + formulae = args.cask? ? [] : tap.formula_names.map { |name| Formula[name] } + casks = args.formula? ? [] : tap.cask_tokens.map { |token| Cask::CaskLoader.load(token) } formulae + casks elsif args.installed? - formulae = !args.cask? ? Formula.installed : [] - casks = !args.formula? ? Cask::Caskroom.casks : [] + formulae = args.cask? ? [] : Formula.installed + casks = args.formula? ? [] : Cask::Caskroom.casks formulae + casks elsif args.all? - formulae = !args.cask? ? Formula.to_a : [] - casks = !args.formula? ? Cask::Cask.to_a : [] + formulae = args.cask? ? [] : Formula.to_a + casks = args.formula? ? [] : Cask::Cask.to_a formulae + casks elsif args.named.present? if args.formula? diff --git a/Library/Homebrew/livecheck/livecheck.rb b/Library/Homebrew/livecheck/livecheck.rb index 737b139e4c..e96544215d 100644 --- a/Library/Homebrew/livecheck/livecheck.rb +++ b/Library/Homebrew/livecheck/livecheck.rb @@ -120,15 +120,15 @@ module Homebrew separator, method = livecheck_version Version.new(formula_or_cask.version.to_s.split(separator, 2).try(method)) elsif formula - if formula.head_only? - formula.any_installed_version.version.commit - else - formula.stable.version - end + if formula.head_only? + formula.any_installed_version.version.commit + else + formula.stable.version + end elsif livecheck_version.is_a?(Symbol) Version.new(Cask::DSL::Version.new(formula_or_cask.version).try(livecheck_version)) - else - Version.new(formula_or_cask.version) + else + Version.new(formula_or_cask.version) end latest = if formula&.stable? || cask @@ -269,9 +269,9 @@ module Homebrew if formula&.deprecated? && !formula.livecheckable? return status_hash(formula, "deprecated", args: args) if args.json? - puts "#{Tty.red}#{formula_name(formula, args: args)}#{Tty.reset} : deprecated" unless args.quiet? - return - end + puts "#{Tty.red}#{formula_name(formula, args: args)}#{Tty.reset} : deprecated" unless args.quiet? + return + end if formula&.disabled? && !formula.livecheckable? return status_hash(formula, "disabled", args: args) if args.json? @@ -283,17 +283,17 @@ module Homebrew if formula&.versioned_formula? && !formula.livecheckable? return status_hash(formula, "versioned", args: args) if args.json? - puts "#{Tty.red}#{formula_name(formula, args: args)}#{Tty.reset} : versioned" unless args.quiet? - return - end + puts "#{Tty.red}#{formula_name(formula, args: args)}#{Tty.reset} : versioned" unless args.quiet? + return + end if formula&.head_only? && !formula.any_version_installed? head_only_msg = "HEAD only formula must be installed to be livecheckable" return status_hash(formula, "error", [head_only_msg], args: args) if args.json? - puts "#{Tty.red}#{formula_name(formula, args: args)}#{Tty.reset} : #{head_only_msg}" unless args.quiet? - return - end + puts "#{Tty.red}#{formula_name(formula, args: args)}#{Tty.reset} : #{head_only_msg}" unless args.quiet? + return + end is_gist = formula&.stable&.url&.include?("gist.github.com") if formula_or_cask.livecheck.skip? || is_gist @@ -312,7 +312,7 @@ module Homebrew puts "#{Tty.red}#{formula_or_cask_name(formula_or_cask, args: args)}#{Tty.reset} : skipped" \ "#{" - #{skip_msg}" if skip_msg.present?}" end - return + return end false From fb3a1a408c6bdb53930db909654c348addf9e2f7 Mon Sep 17 00:00:00 2001 From: Markus Reiter Date: Fri, 11 Dec 2020 16:27:53 +0100 Subject: [PATCH 13/27] Fix method call on `nil`. --- Library/Homebrew/livecheck/livecheck.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Library/Homebrew/livecheck/livecheck.rb b/Library/Homebrew/livecheck/livecheck.rb index e96544215d..319bf6af56 100644 --- a/Library/Homebrew/livecheck/livecheck.rb +++ b/Library/Homebrew/livecheck/livecheck.rb @@ -107,7 +107,7 @@ module Homebrew skip_result = skip_conditions(formula_or_cask, args: args) next skip_result if skip_result != false - formula.head&.downloader&.shutup! + formula&.head&.downloader&.shutup! # Use the `stable` version for comparison except for installed # head-only formulae. A formula with `stable` and `head` that's From af56a99a37d93c252392129ab44ee18ea884c447 Mon Sep 17 00:00:00 2001 From: Markus Reiter Date: Fri, 11 Dec 2020 16:38:29 +0100 Subject: [PATCH 14/27] Use symbol for `respond_to?`. --- Library/Homebrew/dev-cmd/livecheck.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Library/Homebrew/dev-cmd/livecheck.rb b/Library/Homebrew/dev-cmd/livecheck.rb index ae2919a0df..3ebdeaef5c 100644 --- a/Library/Homebrew/dev-cmd/livecheck.rb +++ b/Library/Homebrew/dev-cmd/livecheck.rb @@ -97,7 +97,7 @@ module Homebrew onoe e end end.sort_by do |formula_or_cask| - formula_or_cask.respond_to?("token") ? formula_or_cask.token : formula_or_cask.name + formula_or_cask.respond_to?(:token) ? formula_or_cask.token : formula_or_cask.name end raise UsageError, "No formulae or casks to check." if formulae_and_casks_to_check.blank? From 00e219caf9cbb985740fa51a00f6ba04c2b9178a Mon Sep 17 00:00:00 2001 From: Markus Reiter Date: Fri, 11 Dec 2020 16:50:09 +0100 Subject: [PATCH 15/27] Fix type error. --- Library/Homebrew/dev-cmd/livecheck.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Library/Homebrew/dev-cmd/livecheck.rb b/Library/Homebrew/dev-cmd/livecheck.rb index 3ebdeaef5c..7444420ae7 100644 --- a/Library/Homebrew/dev-cmd/livecheck.rb +++ b/Library/Homebrew/dev-cmd/livecheck.rb @@ -85,7 +85,7 @@ module Homebrew names = Pathname.new(WATCHLIST_PATH).read.lines .reject { |line| line.start_with?("#") || line.blank? } .map(&:strip) - named_args = CLI::NamedArgs.new(*names) + named_args = T.unsafe(CLI::NamedArgs).new(*names) if args.formula? named_args.to_formulae elsif args.cask? From f35829dd37f2b6008b662e1ea57e4cff2eb46399 Mon Sep 17 00:00:00 2001 From: Markus Reiter Date: Fri, 11 Dec 2020 17:08:19 +0100 Subject: [PATCH 16/27] Load formulae/casks from tap files. --- Library/Homebrew/dev-cmd/livecheck.rb | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/Library/Homebrew/dev-cmd/livecheck.rb b/Library/Homebrew/dev-cmd/livecheck.rb index 7444420ae7..692cc061de 100644 --- a/Library/Homebrew/dev-cmd/livecheck.rb +++ b/Library/Homebrew/dev-cmd/livecheck.rb @@ -61,8 +61,8 @@ module Homebrew formulae_and_casks_to_check = if args.tap tap = Tap.fetch(args.tap) - formulae = args.cask? ? [] : tap.formula_names.map { |name| Formula[name] } - casks = args.formula? ? [] : tap.cask_tokens.map { |token| Cask::CaskLoader.load(token) } + formulae = args.cask? ? [] : tap.formula_files.map { |path| Formulary.factory(path) } + casks = args.formula? ? [] : tap.cask_files.map { |path| Cask::CaskLoader.load(path) } formulae + casks elsif args.installed? formulae = args.cask? ? [] : Formula.installed From fa64a17ae9d5c09c3dac84accaa76eb8e3478ea3 Mon Sep 17 00:00:00 2001 From: Markus Reiter Date: Fri, 11 Dec 2020 18:40:54 +0100 Subject: [PATCH 17/27] Remove superfluous branch. --- Library/Homebrew/livecheck/livecheck.rb | 3 --- 1 file changed, 3 deletions(-) diff --git a/Library/Homebrew/livecheck/livecheck.rb b/Library/Homebrew/livecheck/livecheck.rb index 319bf6af56..6b4b2273b6 100644 --- a/Library/Homebrew/livecheck/livecheck.rb +++ b/Library/Homebrew/livecheck/livecheck.rb @@ -116,9 +116,6 @@ module Homebrew livecheck_version = formula_or_cask.livecheck.version current = if livecheck_version.is_a?(String) Version.new(livecheck_version) - elsif livecheck_version.is_a?(Array) - separator, method = livecheck_version - Version.new(formula_or_cask.version.to_s.split(separator, 2).try(method)) elsif formula if formula.head_only? formula.any_installed_version.version.commit From 3bde9d34a97e39d61fe6b4d5db6784cf4f55ab65 Mon Sep 17 00:00:00 2001 From: Markus Reiter Date: Fri, 11 Dec 2020 18:58:01 +0100 Subject: [PATCH 18/27] Remove `version` from `Livecheck`. --- Library/Homebrew/livecheck.rb | 12 ----------- Library/Homebrew/livecheck/livecheck.rb | 7 +------ .../Homebrew/test/livecheck/livecheck_spec.rb | 1 - Library/Homebrew/test/livecheck_spec.rb | 21 ------------------- 4 files changed, 1 insertion(+), 40 deletions(-) diff --git a/Library/Homebrew/livecheck.rb b/Library/Homebrew/livecheck.rb index 7f329e0996..7fb6c3bb2b 100644 --- a/Library/Homebrew/livecheck.rb +++ b/Library/Homebrew/livecheck.rb @@ -20,7 +20,6 @@ class Livecheck @skip_msg = nil @strategy = nil @url = nil - @version = nil end # Sets the `@regex` instance variable to the provided `Regexp` or returns the @@ -104,16 +103,6 @@ class Livecheck end end - # TODO: documentation - def version(val = nil) - return @version if val.nil? - unless val.is_a?(String) || (val.is_a?(Symbol) && Cask::DSL::Version.method_defined?(val)) - raise TypeError, "Livecheck#version expects a String or valid Symbol" - end - - @version = val - end - # Returns a `Hash` of all instance variable values. # @return [Hash] def to_hash @@ -123,7 +112,6 @@ class Livecheck "skip_msg" => @skip_msg, "strategy" => @strategy, "url" => @url, - "version" => @version, } end end diff --git a/Library/Homebrew/livecheck/livecheck.rb b/Library/Homebrew/livecheck/livecheck.rb index 6b4b2273b6..fdd387ff50 100644 --- a/Library/Homebrew/livecheck/livecheck.rb +++ b/Library/Homebrew/livecheck/livecheck.rb @@ -113,17 +113,12 @@ module Homebrew # head-only formulae. A formula with `stable` and `head` that's # installed using `--head` will still use the `stable` version for # comparison. - livecheck_version = formula_or_cask.livecheck.version - current = if livecheck_version.is_a?(String) - Version.new(livecheck_version) - elsif formula + current = if formula if formula.head_only? formula.any_installed_version.version.commit else formula.stable.version end - elsif livecheck_version.is_a?(Symbol) - Version.new(Cask::DSL::Version.new(formula_or_cask.version).try(livecheck_version)) else Version.new(formula_or_cask.version) end diff --git a/Library/Homebrew/test/livecheck/livecheck_spec.rb b/Library/Homebrew/test/livecheck/livecheck_spec.rb index 0323c1e1a8..635b829196 100644 --- a/Library/Homebrew/test/livecheck/livecheck_spec.rb +++ b/Library/Homebrew/test/livecheck/livecheck_spec.rb @@ -85,7 +85,6 @@ describe Homebrew::Livecheck do livecheck do url "https://formulae.brew.sh/api/formula/ruby.json" - version :before_comma regex(/"stable":"(\d+(?:\.\d+)+)"/i) end end diff --git a/Library/Homebrew/test/livecheck_spec.rb b/Library/Homebrew/test/livecheck_spec.rb index 0aa2905d81..84ed8df539 100644 --- a/Library/Homebrew/test/livecheck_spec.rb +++ b/Library/Homebrew/test/livecheck_spec.rb @@ -107,26 +107,6 @@ describe Livecheck do end end - describe "#version" do - it "returns nil if not set" do - expect(livecheckable.version).to be nil - end - - it "returns value if set" do - livecheckable.version("1.2.3") - expect(livecheckable.version).to eq("1.2.3") - - livecheckable.version(:before_comma) - expect(livecheckable.version).to eq(:before_comma) - end - - it "raises a TypeError if the argument isn't a String or Symbol" do - expect { - livecheckable.version(/foo/) - }.to raise_error(TypeError, "Livecheck#version expects a String or valid Symbol") - end - end - describe "#to_hash" do it "returns a Hash of all instance variables" do expect(livecheckable.to_hash).to eq( @@ -136,7 +116,6 @@ describe Livecheck do "skip_msg" => nil, "strategy" => nil, "url" => nil, - "version" => nil, }, ) end From b8e10a47ddeb9222392fb168c57d5a7c0013e851 Mon Sep 17 00:00:00 2001 From: Markus Reiter Date: Fri, 11 Dec 2020 19:13:03 +0100 Subject: [PATCH 19/27] Update man page. --- docs/Manpage.md | 22 +++++++++++++--------- manpages/brew.1 | 24 ++++++++++++++++-------- 2 files changed, 29 insertions(+), 17 deletions(-) diff --git a/docs/Manpage.md b/docs/Manpage.md index 0b998725d6..3fa05c6f15 100644 --- a/docs/Manpage.md +++ b/docs/Manpage.md @@ -1044,27 +1044,31 @@ provided, check all kegs. Raises an error if run on uninstalled formulae. * `--cached`: Print the cached linkage values stored in `HOMEBREW_CACHE`, set by a previous `brew linkage` run. -### `livecheck` [*`formulae`*] +### `livecheck` [*`formulae`*|*`casks`*] -Check for newer versions of formulae from upstream. +Check for newer versions of formulae and/or casks from upstream. -If no formula argument is passed, the list of formulae to check is taken from `HOMEBREW_LIVECHECK_WATCHLIST` -or `~/.brew_livecheck_watchlist`. +If no formula or cask argument is passed, the list of formulae and casks to check is taken from +`HOMEBREW_LIVECHECK_WATCHLIST` or `~/.brew_livecheck_watchlist`. * `--full-name`: - Print formulae with fully-qualified names. + Print formulae/casks with fully-qualified names. * `--tap`: - Check formulae within the given tap, specified as *`user`*`/`*`repo`*. + Check formulae/casks within the given tap, specified as *`user`*`/`*`repo`*. * `--all`: - Check all available formulae. + Check all available formulae/casks. * `--installed`: - Check formulae that are currently installed. + Check formulae/casks that are currently installed. * `--newer-only`: - Show the latest version only if it's newer than the formula. + Show the latest version only if it's newer than the formula/cask. * `--json`: Output information in JSON format. * `-q`, `--quiet`: Suppress warnings, don't print a progress bar for JSON output. +* `--formula`: + Only check formulae. +* `--cask`: + Only check casks. ### `man` [*`options`*] diff --git a/manpages/brew.1 b/manpages/brew.1 index 31a05c1726..006860ffd5 100644 --- a/manpages/brew.1 +++ b/manpages/brew.1 @@ -1442,31 +1442,31 @@ For every library that a keg references, print its dylib path followed by the bi \fB\-\-cached\fR Print the cached linkage values stored in \fBHOMEBREW_CACHE\fR, set by a previous \fBbrew linkage\fR run\. . -.SS "\fBlivecheck\fR [\fIformulae\fR]" -Check for newer versions of formulae from upstream\. +.SS "\fBlivecheck\fR [\fIformulae\fR|\fIcasks\fR]" +Check for newer versions of formulae and/or casks from upstream\. . .P -If no formula argument is passed, the list of formulae to check is taken from \fBHOMEBREW_LIVECHECK_WATCHLIST\fR or \fB~/\.brew_livecheck_watchlist\fR\. +If no formula or cask argument is passed, the list of formulae and casks to check is taken from \fBHOMEBREW_LIVECHECK_WATCHLIST\fR or \fB~/\.brew_livecheck_watchlist\fR\. . .TP \fB\-\-full\-name\fR -Print formulae with fully\-qualified names\. +Print formulae/casks with fully\-qualified names\. . .TP \fB\-\-tap\fR -Check formulae within the given tap, specified as \fIuser\fR\fB/\fR\fIrepo\fR\. +Check formulae/casks within the given tap, specified as \fIuser\fR\fB/\fR\fIrepo\fR\. . .TP \fB\-\-all\fR -Check all available formulae\. +Check all available formulae/casks\. . .TP \fB\-\-installed\fR -Check formulae that are currently installed\. +Check formulae/casks that are currently installed\. . .TP \fB\-\-newer\-only\fR -Show the latest version only if it\'s newer than the formula\. +Show the latest version only if it\'s newer than the formula/cask\. . .TP \fB\-\-json\fR @@ -1476,6 +1476,14 @@ Output information in JSON format\. \fB\-q\fR, \fB\-\-quiet\fR Suppress warnings, don\'t print a progress bar for JSON output\. . +.TP +\fB\-\-formula\fR +Only check formulae\. +. +.TP +\fB\-\-cask\fR +Only check casks\. +. .SS "\fBman\fR [\fIoptions\fR]" Generate Homebrew\'s manpages\. . From ad544e465d45da47699b1e4b4bc47a2a05ebd782 Mon Sep 17 00:00:00 2001 From: Sam Ford <1584702+samford@users.noreply.github.com> Date: Sat, 12 Dec 2020 10:04:47 -0500 Subject: [PATCH 20/27] Add livecheck group to cask stanza order --- Library/Homebrew/rubocops/cask/constants/stanza.rb | 1 + 1 file changed, 1 insertion(+) diff --git a/Library/Homebrew/rubocops/cask/constants/stanza.rb b/Library/Homebrew/rubocops/cask/constants/stanza.rb index d5e23b10c8..93a9b67d55 100644 --- a/Library/Homebrew/rubocops/cask/constants/stanza.rb +++ b/Library/Homebrew/rubocops/cask/constants/stanza.rb @@ -9,6 +9,7 @@ module RuboCop [:version, :sha256], [:language], [:url, :appcast, :name, :desc, :homepage], + [:livecheck], [ :auto_updates, :conflicts_with, From 7b14f7446dd9220652b01afd89af722e080cdc55 Mon Sep 17 00:00:00 2001 From: Sam Ford <1584702+samford@users.noreply.github.com> Date: Sat, 12 Dec 2020 10:12:58 -0500 Subject: [PATCH 21/27] dev-cmd/livecheck: format usage_banner --- Library/Homebrew/dev-cmd/livecheck.rb | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/Library/Homebrew/dev-cmd/livecheck.rb b/Library/Homebrew/dev-cmd/livecheck.rb index 692cc061de..1546bcb7ec 100644 --- a/Library/Homebrew/dev-cmd/livecheck.rb +++ b/Library/Homebrew/dev-cmd/livecheck.rb @@ -24,8 +24,9 @@ module Homebrew Check for newer versions of formulae and/or casks from upstream. - If no formula or cask argument is passed, the list of formulae and casks to check is taken from - `HOMEBREW_LIVECHECK_WATCHLIST` or `~/.brew_livecheck_watchlist`. + If no formula or cask argument is passed, the list of formulae and + casks to check is taken from `HOMEBREW_LIVECHECK_WATCHLIST` or + `~/.brew_livecheck_watchlist`. EOS switch "--full-name", description: "Print formulae/casks with fully-qualified names." From d316b7c802bcc67cd8ea9ae82a91b5610a423513 Mon Sep 17 00:00:00 2001 From: Sam Ford <1584702+samford@users.noreply.github.com> Date: Sat, 12 Dec 2020 10:29:25 -0500 Subject: [PATCH 22/27] livecheck: rename variables for clarity --- Library/Homebrew/livecheck/livecheck.rb | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/Library/Homebrew/livecheck/livecheck.rb b/Library/Homebrew/livecheck/livecheck.rb index fdd387ff50..dd2b9ce7e1 100644 --- a/Library/Homebrew/livecheck/livecheck.rb +++ b/Library/Homebrew/livecheck/livecheck.rb @@ -47,12 +47,12 @@ module Homebrew def run_checks(formulae_and_casks_to_check, args) # Identify any non-homebrew/core taps in use for current formulae non_core_taps = {} - formulae_and_casks_to_check.each do |fc| - next if fc.tap.blank? - next if fc.tap.name == CoreTap.instance.name - next if non_core_taps[fc.tap.name] + formulae_and_casks_to_check.each do |formula_or_cask| + next if formula_or_cask.tap.blank? + next if formula_or_cask.tap.name == CoreTap.instance.name + next if non_core_taps[formula_or_cask.tap.name] - non_core_taps[fc.tap.name] = fc.tap + non_core_taps[formula_or_cask.tap.name] = formula_or_cask.tap end non_core_taps = non_core_taps.sort.to_h @@ -73,7 +73,7 @@ module Homebrew has_a_newer_upstream_version = false if args.json? && !args.quiet? && $stderr.tty? - total_formulae = if formulae_and_casks_to_check == Formula + formulae_and_casks_total = if formulae_and_casks_to_check == Formula formulae_and_casks_to_check.count else formulae_and_casks_to_check.length @@ -84,7 +84,7 @@ module Homebrew end progress = ProgressBar.create( - total: total_formulae, + total: formulae_and_casks_total, progress_mark: "#", remainder_mark: ".", format: " %t: [%B] %c/%C ", From c1e5eec826c07152ce7239c2a0911abcc0fccedc Mon Sep 17 00:00:00 2001 From: Sam Ford <1584702+samford@users.noreply.github.com> Date: Sat, 12 Dec 2020 10:30:20 -0500 Subject: [PATCH 23/27] livecheck: reinstate head_only? condition order --- Library/Homebrew/livecheck/livecheck.rb | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/Library/Homebrew/livecheck/livecheck.rb b/Library/Homebrew/livecheck/livecheck.rb index dd2b9ce7e1..3a6a708c18 100644 --- a/Library/Homebrew/livecheck/livecheck.rb +++ b/Library/Homebrew/livecheck/livecheck.rb @@ -123,11 +123,11 @@ module Homebrew Version.new(formula_or_cask.version) end - latest = if formula&.stable? || cask + latest = if formula&.head_only? + formula.head.downloader.fetch_last_commit + else version_info = latest_version(formula_or_cask, args: args) version_info[:latest] if version_info.present? - else - formula.head.downloader.fetch_last_commit end if latest.blank? From 704ec8abf0ba613bbf594254f3da0fc04ba200a2 Mon Sep 17 00:00:00 2001 From: Sam Ford <1584702+samford@users.noreply.github.com> Date: Sat, 12 Dec 2020 11:00:02 -0500 Subject: [PATCH 24/27] livecheck: reinstate previous order of hashes --- Library/Homebrew/livecheck/livecheck.rb | 29 +++++++++++-------------- 1 file changed, 13 insertions(+), 16 deletions(-) diff --git a/Library/Homebrew/livecheck/livecheck.rb b/Library/Homebrew/livecheck/livecheck.rb index 3a6a708c18..070f4a6e63 100644 --- a/Library/Homebrew/livecheck/livecheck.rb +++ b/Library/Homebrew/livecheck/livecheck.rb @@ -153,19 +153,18 @@ module Homebrew is_newer_than_upstream = (formula&.stable? || cask) && (current > latest) - info = { - version: { - current: current.to_s, - latest: latest.to_s, - outdated: is_outdated, - newer_than_upstream: is_newer_than_upstream, - }, - meta: { - livecheckable: formula_or_cask.livecheckable?, - }, - } + info = {} info[:formula] = formula_name(formula, args: args) if formula info[:cask] = cask_name(cask, args: args) if cask + info[:version] = { + current: current.to_s, + latest: latest.to_s, + outdated: is_outdated, + newer_than_upstream: is_newer_than_upstream, + } + info[:meta] = { + livecheckable: formula_or_cask.livecheckable?, + } info[:meta][:head_only] = true if formula&.head_only? info[:meta].merge!(version_info[:meta]) if version_info.present? && version_info.key?(:meta) @@ -231,16 +230,14 @@ module Homebrew def status_hash(formula_or_cask, status_str, messages = nil, args:) formula = formula_or_cask if formula_or_cask.is_a?(Formula) - status_hash = { - status: status_str, - } - status_hash[:messages] = messages if messages.is_a?(Array) - + status_hash = {} if formula status_hash[:formula] = formula_name(formula, args: args) else status_hash[:cask] = cask_name(formula_or_cask, args: args) end + status_hash[:status] = status_str + status_hash[:messages] = messages if messages.is_a?(Array) if args.verbose? status_hash[:meta] = { From 9d08f09714f4c8af8234882440feaed3038d2e30 Mon Sep 17 00:00:00 2001 From: Sam Ford <1584702+samford@users.noreply.github.com> Date: Sat, 12 Dec 2020 11:36:43 -0500 Subject: [PATCH 25/27] livecheck: assume type of formula_or_cask less --- Library/Homebrew/livecheck/livecheck.rb | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) diff --git a/Library/Homebrew/livecheck/livecheck.rb b/Library/Homebrew/livecheck/livecheck.rb index 070f4a6e63..854ebae4fb 100644 --- a/Library/Homebrew/livecheck/livecheck.rb +++ b/Library/Homebrew/livecheck/livecheck.rb @@ -209,9 +209,10 @@ module Homebrew end def formula_or_cask_name(formula_or_cask, args:) - if formula_or_cask.is_a?(Formula) + case formula_or_cask + when Formula formula_name(formula_or_cask, args: args) - else + when Cask::Cask cask_name(formula_or_cask, args: args) end end @@ -229,11 +230,12 @@ module Homebrew def status_hash(formula_or_cask, status_str, messages = nil, args:) formula = formula_or_cask if formula_or_cask.is_a?(Formula) + cask = formula_or_cask if formula_or_cask.is_a?(Cask::Cask) status_hash = {} if formula status_hash[:formula] = formula_name(formula, args: args) - else + elsif cask status_hash[:cask] = cask_name(formula_or_cask, args: args) end status_hash[:status] = status_str @@ -393,6 +395,7 @@ module Homebrew # @return [Hash, nil] def latest_version(formula_or_cask, args:) formula = formula_or_cask if formula_or_cask.is_a?(Formula) + cask = formula_or_cask if formula_or_cask.is_a?(Cask::Cask) has_livecheckable = formula_or_cask.livecheckable? livecheck = formula_or_cask.livecheck @@ -408,7 +411,7 @@ module Homebrew if formula puts "Formula: #{formula_name(formula, args: args)}" puts "Head only?: true" if formula.head_only? - else + elsif cask puts "Cask: #{cask_name(formula_or_cask, args: args)}" end puts "Livecheckable?: #{has_livecheckable ? "Yes" : "No"}" From b041f76ee9d6fcd331ed87f65a8232c8a2c128af Mon Sep 17 00:00:00 2001 From: Sam Ford <1584702+samford@users.noreply.github.com> Date: Sat, 12 Dec 2020 13:21:54 -0500 Subject: [PATCH 26/27] Update manpage --- docs/Manpage.md | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/docs/Manpage.md b/docs/Manpage.md index 3fa05c6f15..e5efc8543c 100644 --- a/docs/Manpage.md +++ b/docs/Manpage.md @@ -1048,8 +1048,9 @@ provided, check all kegs. Raises an error if run on uninstalled formulae. Check for newer versions of formulae and/or casks from upstream. -If no formula or cask argument is passed, the list of formulae and casks to check is taken from -`HOMEBREW_LIVECHECK_WATCHLIST` or `~/.brew_livecheck_watchlist`. +If no formula or cask argument is passed, the list of formulae and +casks to check is taken from `HOMEBREW_LIVECHECK_WATCHLIST` or +`~/.brew_livecheck_watchlist`. * `--full-name`: Print formulae/casks with fully-qualified names. From 15a868c5e65cc1fc5bdc045db6ee5cf323118e8b Mon Sep 17 00:00:00 2001 From: Sam Ford <1584702+samford@users.noreply.github.com> Date: Sat, 12 Dec 2020 17:30:30 -0500 Subject: [PATCH 27/27] dev-cmd/livecheck: respect --cask and --formula When running `brew livecheck --cask` or `brew livecheck --formula`, livecheck wasn't properly respecting these flags. It should have worked by only including the casks or formulae in the watchlist but instead these flags were treating all the names in the watchlist as formulae or casks, which doesn't work properly. This addresses the issue by always using `#to_formulae_and_casks` on the watchlist names and then using `#reject` to conditionally exclude formulae or casks based on whether the related flags were passed to `brew livecheck`. --- Library/Homebrew/dev-cmd/livecheck.rb | 10 ++++------ 1 file changed, 4 insertions(+), 6 deletions(-) diff --git a/Library/Homebrew/dev-cmd/livecheck.rb b/Library/Homebrew/dev-cmd/livecheck.rb index 1546bcb7ec..b2929339a1 100644 --- a/Library/Homebrew/dev-cmd/livecheck.rb +++ b/Library/Homebrew/dev-cmd/livecheck.rb @@ -86,13 +86,11 @@ module Homebrew names = Pathname.new(WATCHLIST_PATH).read.lines .reject { |line| line.start_with?("#") || line.blank? } .map(&:strip) + named_args = T.unsafe(CLI::NamedArgs).new(*names) - if args.formula? - named_args.to_formulae - elsif args.cask? - named_args.to_casks - else - named_args.to_formulae_and_casks + named_args.to_formulae_and_casks.reject do |formula_or_cask| + (args.formula? && !formula_or_cask.is_a?(Formula)) || + (args.cask? && !formula_or_cask.is_a?(Cask::Cask)) end rescue Errno::ENOENT => e onoe e