Port Homebrew::DevCmd::Livecheck
This commit is contained in:
parent
5848c3d81b
commit
d15f99514c
@ -1,17 +1,19 @@
|
||||
# typed: true
|
||||
# frozen_string_literal: true
|
||||
|
||||
require "abstract_command"
|
||||
require "cli/parser"
|
||||
require "formula"
|
||||
require "livecheck/livecheck"
|
||||
require "livecheck/strategy"
|
||||
|
||||
module Homebrew
|
||||
module_function
|
||||
module DevCmd
|
||||
class LivecheckCmd < AbstractCommand
|
||||
sig { returns(String) }
|
||||
def self.command_name = "livecheck"
|
||||
|
||||
sig { returns(CLI::Parser) }
|
||||
def livecheck_args
|
||||
Homebrew::CLI::Parser.new do
|
||||
cmd_args do
|
||||
description <<~EOS
|
||||
Check for newer versions of formulae and/or casks from upstream.
|
||||
If no formula or cask argument is passed, the list of formulae and
|
||||
@ -48,27 +50,9 @@ module Homebrew
|
||||
|
||||
named_args [:formula, :cask], without_api: true
|
||||
end
|
||||
end
|
||||
|
||||
def watchlist_path
|
||||
@watchlist_path ||= begin
|
||||
watchlist = File.expand_path(Homebrew::EnvConfig.livecheck_watchlist)
|
||||
|
||||
unless File.exist?(watchlist)
|
||||
previous_default_watchlist = File.expand_path("~/.brew_livecheck_watchlist")
|
||||
if File.exist?(previous_default_watchlist)
|
||||
odisabled "~/.brew_livecheck_watchlist", "~/.homebrew/livecheck_watchlist.txt"
|
||||
watchlist = previous_default_watchlist
|
||||
end
|
||||
end
|
||||
|
||||
watchlist
|
||||
end
|
||||
end
|
||||
|
||||
def livecheck
|
||||
args = livecheck_args.parse
|
||||
|
||||
sig { override.void }
|
||||
def run
|
||||
Homebrew.install_bundler_gems!(groups: ["livecheck"])
|
||||
|
||||
all = args.eval_all?
|
||||
@ -80,7 +64,7 @@ module Homebrew
|
||||
|
||||
formulae_and_casks_to_check = Homebrew.with_no_api_env do
|
||||
if args.tap
|
||||
tap = Tap.fetch(args.tap)
|
||||
tap = Tap.fetch(T.must(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
|
||||
@ -136,4 +120,24 @@ module Homebrew
|
||||
|
||||
Livecheck.run_checks(formulae_and_casks_to_check, **options)
|
||||
end
|
||||
|
||||
private
|
||||
|
||||
def watchlist_path
|
||||
@watchlist_path ||= begin
|
||||
watchlist = File.expand_path(Homebrew::EnvConfig.livecheck_watchlist)
|
||||
|
||||
unless File.exist?(watchlist)
|
||||
previous_default_watchlist = File.expand_path("~/.brew_livecheck_watchlist")
|
||||
if File.exist?(previous_default_watchlist)
|
||||
odisabled "~/.brew_livecheck_watchlist", "~/.homebrew/livecheck_watchlist.txt"
|
||||
watchlist = previous_default_watchlist
|
||||
end
|
||||
end
|
||||
|
||||
watchlist
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
@ -1,8 +1,9 @@
|
||||
# frozen_string_literal: true
|
||||
|
||||
require "cmd/shared_examples/args_parse"
|
||||
require "dev-cmd/livecheck"
|
||||
|
||||
RSpec.describe "brew livecheck" do
|
||||
RSpec.describe Homebrew::DevCmd::LivecheckCmd do
|
||||
it_behaves_like "parseable arguments"
|
||||
|
||||
it "reports the latest version of a Formula", :integration_test, :needs_network do
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user