2020-10-10 14:16:11 +02:00
|
|
|
# typed: false
|
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
|
|
|
|
`livecheck` [<formulae>]
|
|
|
|
|
|
|
|
Check for newer versions of formulae from upstream.
|
|
|
|
|
|
|
|
If no formula argument is passed, the list of formulae to check is taken from `HOMEBREW_LIVECHECK_WATCHLIST`
|
|
|
|
or `~/.brew_livecheck_watchlist`.
|
|
|
|
EOS
|
|
|
|
switch "--full-name",
|
|
|
|
description: "Print formulae with fully-qualified names."
|
|
|
|
flag "--tap=",
|
2020-09-03 00:41:16 +05:30
|
|
|
description: "Check formulae within the given tap, specified as <user>`/`<repo>."
|
2020-08-02 00:59:36 +05:30
|
|
|
switch "--all",
|
|
|
|
description: "Check all available formulae."
|
2020-09-03 00:41:16 +05:30
|
|
|
switch "--installed",
|
|
|
|
description: "Check formulae that are currently installed."
|
2020-08-02 00:59:36 +05:30
|
|
|
switch "--newer-only",
|
|
|
|
description: "Show the latest version only if it's newer than the formula."
|
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-08-02 00:59:36 +05:30
|
|
|
conflicts "--debug", "--json"
|
|
|
|
conflicts "--tap=", "--all", "--installed"
|
|
|
|
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
|
|
|
|
|
|
|
|
formulae_to_check = if args.tap
|
|
|
|
Tap.fetch(args.tap).formula_names.map { |name| Formula[name] }
|
|
|
|
elsif args.installed?
|
|
|
|
Formula.installed
|
|
|
|
elsif args.all?
|
|
|
|
Formula
|
2020-09-03 10:34:22 +01:00
|
|
|
elsif (formulae_args = args.named.to_formulae) && formulae_args.present?
|
|
|
|
formulae_args
|
2020-08-02 00:59:36 +05:30
|
|
|
elsif File.exist?(WATCHLIST_PATH)
|
|
|
|
begin
|
2020-09-01 11:20:39 -07:00
|
|
|
Pathname.new(WATCHLIST_PATH).read.lines.map do |line|
|
2020-08-02 00:59:36 +05:30
|
|
|
next if line.start_with?("#")
|
|
|
|
|
|
|
|
Formula[line.strip]
|
|
|
|
end.compact
|
|
|
|
rescue Errno::ENOENT => e
|
|
|
|
onoe e
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
raise UsageError, "No formulae to check." if formulae_to_check.blank?
|
|
|
|
|
|
|
|
Livecheck.livecheck_formulae(formulae_to_check, args)
|
|
|
|
end
|
|
|
|
end
|