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
|
|
|
|
module_function
|
|
|
|
|
2022-06-21 17:57:19 -07:00
|
|
|
WATCHLIST_PATH = File.expand_path(Homebrew::EnvConfig.livecheck_watchlist).freeze
|
2020-08-02 00:59:36 +05:30
|
|
|
|
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
|
2021-01-15 15:04:02 -05:00
|
|
|
description <<~EOS
|
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",
|
2022-09-05 13:57:22 +01:00
|
|
|
description: "Print formulae and casks with fully-qualified names."
|
2020-08-02 00:59:36 +05:30
|
|
|
flag "--tap=",
|
2022-09-05 13:57:22 +01:00
|
|
|
description: "Check formulae and casks within the given tap, specified as <user>`/`<repo>."
|
|
|
|
switch "--eval-all",
|
|
|
|
description: "Evaluate all available formulae and casks, whether installed or not, to check them."
|
2020-08-02 00:59:36 +05:30
|
|
|
switch "--all",
|
2022-09-05 13:57:22 +01:00
|
|
|
hidden: true
|
2020-09-03 00:41:16 +05:30
|
|
|
switch "--installed",
|
2022-09-05 13:57:22 +01:00
|
|
|
description: "Check formulae and 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."
|
2022-07-17 12:45:29 +02:00
|
|
|
switch "-r", "--resources",
|
2022-07-31 12:29:20 +05:00
|
|
|
description: "Also check resources for formulae."
|
2020-09-03 00:41:16 +05:30
|
|
|
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-11-27 11:41:08 -05:00
|
|
|
|
2020-08-02 00:59:36 +05:30
|
|
|
conflicts "--debug", "--json"
|
2022-09-05 13:57:22 +01:00
|
|
|
conflicts "--tap=", "--eval-all", "--installed"
|
2020-09-03 21:33:08 -07:00
|
|
|
conflicts "--cask", "--formula"
|
2021-01-10 14:26:40 -05:00
|
|
|
|
|
|
|
named_args [:formula, :cask]
|
2020-08-02 00:59:36 +05:30
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
def livecheck
|
|
|
|
args = livecheck_args.parse
|
|
|
|
|
2022-09-05 13:57:22 +01:00
|
|
|
all = args.eval_all?
|
|
|
|
if args.all?
|
2023-02-07 19:25:51 +01:00
|
|
|
odisabled "brew livecheck --all", "brew livecheck --eval-all" if !all && !Homebrew::EnvConfig.eval_all?
|
2022-09-05 13:57:22 +01:00
|
|
|
all = true
|
|
|
|
end
|
|
|
|
|
2020-08-02 00:59:36 +05:30
|
|
|
if args.debug? && args.verbose?
|
|
|
|
puts args
|
2022-05-30 04:15:28 +01:00
|
|
|
puts Homebrew::EnvConfig.livecheck_watchlist if Homebrew::EnvConfig.livecheck_watchlist.present?
|
2020-08-02 00:59:36 +05:30
|
|
|
end
|
|
|
|
|
2022-07-27 20:54:28 +02:00
|
|
|
formulae_and_casks_to_check = if args.tap
|
2021-03-04 23:54:25 +05:30
|
|
|
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
|
2022-09-05 13:57:22 +01:00
|
|
|
elsif all
|
2022-01-03 14:59:10 +00:00
|
|
|
formulae = args.cask? ? [] : Formula.all
|
|
|
|
casks = args.formula? ? [] : Cask::Cask.all
|
2021-03-04 23:54:25 +05:30
|
|
|
formulae + casks
|
|
|
|
elsif args.named.present?
|
|
|
|
if args.formula?
|
|
|
|
args.named.to_formulae
|
|
|
|
elsif args.cask?
|
|
|
|
args.named.to_casks
|
2020-12-18 21:59:31 +09:00
|
|
|
else
|
2022-07-27 13:53:54 +02:00
|
|
|
args.named.to_formulae_and_casks
|
2021-03-04 23:54:25 +05:30
|
|
|
end
|
|
|
|
elsif File.exist?(WATCHLIST_PATH)
|
|
|
|
begin
|
|
|
|
names = Pathname.new(WATCHLIST_PATH).read.lines
|
|
|
|
.reject { |line| line.start_with?("#") || line.blank? }
|
|
|
|
.map(&:strip)
|
|
|
|
|
2023-04-03 17:34:39 -07:00
|
|
|
named_args = CLI::NamedArgs.new(*names, parent: args)
|
2022-07-27 13:53:54 +02:00
|
|
|
named_args.to_formulae_and_casks(ignore_unavailable: true)
|
2021-03-04 23:54:25 +05:30
|
|
|
rescue Errno::ENOENT => e
|
|
|
|
onoe e
|
2020-08-02 00:59:36 +05:30
|
|
|
end
|
2021-03-04 23:54:25 +05:30
|
|
|
else
|
|
|
|
raise UsageError, "A watchlist file is required when no arguments are given."
|
|
|
|
end
|
2022-07-18 14:03:40 +02:00
|
|
|
|
2022-07-27 20:54:28 +02:00
|
|
|
formulae_and_casks_to_check = formulae_and_casks_to_check.sort_by do |formula_or_cask|
|
|
|
|
formula_or_cask.respond_to?(:token) ? formula_or_cask.token : formula_or_cask.name
|
2021-03-04 23:54:25 +05:30
|
|
|
end
|
2020-08-02 00:59:36 +05:30
|
|
|
|
2022-07-27 20:54:28 +02: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-12-14 14:30:36 +01:00
|
|
|
options = {
|
2021-02-18 15:05:01 +05:30
|
|
|
json: args.json?,
|
|
|
|
full_name: args.full_name?,
|
2021-03-04 01:01:56 +05:30
|
|
|
handle_name_conflict: !args.formula? && !args.cask?,
|
2022-07-27 13:53:54 +02:00
|
|
|
check_resources: args.resources?,
|
2021-02-18 15:05:01 +05:30
|
|
|
newer_only: args.newer_only?,
|
|
|
|
quiet: args.quiet?,
|
|
|
|
debug: args.debug?,
|
|
|
|
verbose: args.verbose?,
|
2020-12-14 14:30:36 +01:00
|
|
|
}.compact
|
|
|
|
|
2022-07-27 20:54:28 +02:00
|
|
|
Livecheck.run_checks(formulae_and_casks_to_check, **options)
|
2020-08-02 00:59:36 +05:30
|
|
|
end
|
|
|
|
end
|