Merge pull request #10054 from hyuraku/livecheck-raise-error

livecheck: raise error if no watchlist
This commit is contained in:
Sam Ford 2020-12-20 17:48:23 -05:00 committed by GitHub
commit 2ddb71af77
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 46 additions and 36 deletions

View File

@ -60,44 +60,47 @@ module Homebrew
puts ENV["HOMEBREW_LIVECHECK_WATCHLIST"] if ENV["HOMEBREW_LIVECHECK_WATCHLIST"].present?
end
formulae_and_casks_to_check = if args.tap
tap = Tap.fetch(args.tap)
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
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 + casks
elsif args.named.present?
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)
named_args = T.unsafe(CLI::NamedArgs).new(*names)
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))
formulae_and_casks_to_check =
if args.tap
tap = Tap.fetch(args.tap)
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
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 + casks
elsif args.named.present?
if args.formula?
args.named.to_formulae
elsif args.cask?
args.named.to_casks
else
args.named.to_formulae_and_casks
end
rescue Errno::ENOENT => e
onoe e
elsif File.exist?(WATCHLIST_PATH)
begin
names = Pathname.new(WATCHLIST_PATH).read.lines
.reject { |line| line.start_with?("#") || line.blank? }
.map(&:strip)
named_args = T.unsafe(CLI::NamedArgs).new(*names)
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
end
else
raise UsageError, "A watchlist file is required when no arguments are given."
end&.sort_by do |formula_or_cask|
formula_or_cask.respond_to?(:token) ? formula_or_cask.token : formula_or_cask.name
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?

View File

@ -21,4 +21,11 @@ describe "brew livecheck", :integration_test do
.and not_to_output.to_stderr
.and be_a_success
end
it "gives an error when no arguments are given and there's no watchlist" do
expect { brew "livecheck" }
.to output(/Invalid usage: A watchlist file is required when no arguments are given\./).to_stderr
.and not_to_output.to_stdout
.and be_a_failure
end
end