2020-11-25 17:03:23 +01:00
|
|
|
# typed: true
|
2020-08-02 00:59:36 +05:30
|
|
|
# frozen_string_literal: true
|
|
|
|
|
|
|
|
require "cli/parser"
|
|
|
|
require "formula"
|
|
|
|
require "livecheck/livecheck"
|
|
|
|
require "livecheck/strategy"
|
|
|
|
|
|
|
|
module Homebrew
|
2020-10-20 12:03:48 +02:00
|
|
|
extend T::Sig
|
|
|
|
|
2020-08-02 00:59:36 +05:30
|
|
|
module_function
|
|
|
|
|
|
|
|
WATCHLIST_PATH = (
|
|
|
|
ENV["HOMEBREW_LIVECHECK_WATCHLIST"] ||
|
2020-09-01 11:45:05 -07:00
|
|
|
"#{Dir.home}/.brew_livecheck_watchlist"
|
2020-08-02 00:59:36 +05:30
|
|
|
).freeze
|
|
|
|
|
2020-10-20 12:03:48 +02:00
|
|
|
sig { returns(CLI::Parser) }
|
2020-08-02 00:59:36 +05:30
|
|
|
def livecheck_args
|
|
|
|
Homebrew::CLI::Parser.new do
|
|
|
|
usage_banner <<~EOS
|
2020-09-03 21:18:04 -07:00
|
|
|
`livecheck` [<formulae>|<casks>]
|
2020-08-02 00:59:36 +05:30
|
|
|
|
2020-09-03 21:18:04 -07:00
|
|
|
Check for newer versions of formulae and/or casks from upstream.
|
2020-08-02 00:59:36 +05:30
|
|
|
|
2020-12-12 10:12:58 -05:00
|
|
|
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`.
|
2020-08-02 00:59:36 +05:30
|
|
|
EOS
|
|
|
|
switch "--full-name",
|
2020-09-03 21:18:04 -07:00
|
|
|
description: "Print formulae/casks with fully-qualified names."
|
2020-08-02 00:59:36 +05:30
|
|
|
flag "--tap=",
|
2020-09-03 21:18:04 -07:00
|
|
|
description: "Check formulae/casks within the given tap, specified as <user>`/`<repo>."
|
2020-08-02 00:59:36 +05:30
|
|
|
switch "--all",
|
2020-09-03 21:18:04 -07:00
|
|
|
description: "Check all available formulae/casks."
|
2020-09-03 00:41:16 +05:30
|
|
|
switch "--installed",
|
2020-09-03 21:18:04 -07:00
|
|
|
description: "Check formulae/casks that are currently installed."
|
2020-08-02 00:59:36 +05:30
|
|
|
switch "--newer-only",
|
2020-09-03 21:18:04 -07:00
|
|
|
description: "Show the latest version only if it's newer than the formula/cask."
|
2020-09-03 00:41:16 +05:30
|
|
|
switch "--json",
|
|
|
|
description: "Output information in JSON format."
|
|
|
|
switch "-q", "--quiet",
|
|
|
|
description: "Suppress warnings, don't print a progress bar for JSON output."
|
2020-09-03 21:33:08 -07:00
|
|
|
switch "--formula", "--formulae",
|
|
|
|
description: "Only check formulae."
|
|
|
|
switch "--cask", "--casks",
|
|
|
|
description: "Only check casks."
|
2020-08-02 00:59:36 +05:30
|
|
|
conflicts "--debug", "--json"
|
|
|
|
conflicts "--tap=", "--all", "--installed"
|
2020-09-03 21:33:08 -07:00
|
|
|
conflicts "--cask", "--formula"
|
2020-08-02 00:59:36 +05:30
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
def livecheck
|
|
|
|
args = livecheck_args.parse
|
|
|
|
|
|
|
|
if args.debug? && args.verbose?
|
|
|
|
puts args
|
|
|
|
puts ENV["HOMEBREW_LIVECHECK_WATCHLIST"] if ENV["HOMEBREW_LIVECHECK_WATCHLIST"].present?
|
|
|
|
end
|
|
|
|
|
2020-09-02 12:24:21 -07:00
|
|
|
formulae_and_casks_to_check = if args.tap
|
|
|
|
tap = Tap.fetch(args.tap)
|
2020-12-11 17:08:19 +01:00
|
|
|
formulae = args.cask? ? [] : tap.formula_files.map { |path| Formulary.factory(path) }
|
|
|
|
casks = args.formula? ? [] : tap.cask_files.map { |path| Cask::CaskLoader.load(path) }
|
2020-09-02 12:24:21 -07:00
|
|
|
formulae + casks
|
2020-08-02 00:59:36 +05:30
|
|
|
elsif args.installed?
|
2020-12-11 16:24:49 +01:00
|
|
|
formulae = args.cask? ? [] : Formula.installed
|
|
|
|
casks = args.formula? ? [] : Cask::Caskroom.casks
|
2020-09-03 21:33:08 -07:00
|
|
|
formulae + casks
|
2020-08-02 00:59:36 +05:30
|
|
|
elsif args.all?
|
2020-12-11 16:24:49 +01:00
|
|
|
formulae = args.cask? ? [] : Formula.to_a
|
|
|
|
casks = args.formula? ? [] : Cask::Cask.to_a
|
2020-09-03 21:33:08 -07:00
|
|
|
formulae + casks
|
2020-09-02 12:24:21 -07:00
|
|
|
elsif args.named.present?
|
2020-09-03 21:33:08 -07:00
|
|
|
if args.formula?
|
|
|
|
args.named.to_formulae
|
|
|
|
elsif args.cask?
|
|
|
|
args.named.to_casks
|
|
|
|
else
|
|
|
|
args.named.to_formulae_and_casks
|
|
|
|
end
|
2020-08-02 00:59:36 +05:30
|
|
|
elsif File.exist?(WATCHLIST_PATH)
|
|
|
|
begin
|
2020-09-03 20:09:56 -07:00
|
|
|
names = Pathname.new(WATCHLIST_PATH).read.lines
|
|
|
|
.reject { |line| line.start_with?("#") || line.blank? }
|
|
|
|
.map(&:strip)
|
2020-12-11 16:50:09 +01:00
|
|
|
named_args = T.unsafe(CLI::NamedArgs).new(*names)
|
2020-09-03 21:33:08 -07:00
|
|
|
if args.formula?
|
|
|
|
named_args.to_formulae
|
|
|
|
elsif args.cask?
|
|
|
|
named_args.to_casks
|
|
|
|
else
|
|
|
|
named_args.to_formulae_and_casks
|
|
|
|
end
|
2020-08-02 00:59:36 +05:30
|
|
|
rescue Errno::ENOENT => e
|
|
|
|
onoe e
|
|
|
|
end
|
2020-09-03 20:33:24 -07:00
|
|
|
end.sort_by do |formula_or_cask|
|
2020-12-11 16:38:29 +01:00
|
|
|
formula_or_cask.respond_to?(:token) ? formula_or_cask.token : formula_or_cask.name
|
2020-08-02 00:59:36 +05:30
|
|
|
end
|
|
|
|
|
2020-09-02 12:24:21 -07:00
|
|
|
raise UsageError, "No formulae or casks to check." if formulae_and_casks_to_check.blank?
|
2020-08-02 00:59:36 +05:30
|
|
|
|
2020-09-03 20:55:33 -07:00
|
|
|
Livecheck.run_checks(formulae_and_casks_to_check, args)
|
2020-08-02 00:59:36 +05:30
|
|
|
end
|
|
|
|
end
|