Port Homebrew::Cmd::Outdated
This commit is contained in:
parent
57442ab67e
commit
7725fc62d4
@ -1,16 +1,16 @@
|
||||
# typed: true
|
||||
# frozen_string_literal: true
|
||||
|
||||
require "abstract_command"
|
||||
require "formula"
|
||||
require "keg"
|
||||
require "cli/parser"
|
||||
require "cask/caskroom"
|
||||
require "api"
|
||||
|
||||
module Homebrew
|
||||
sig { returns(CLI::Parser) }
|
||||
def self.outdated_args
|
||||
Homebrew::CLI::Parser.new do
|
||||
module Cmd
|
||||
class Outdated < AbstractCommand
|
||||
cmd_args do
|
||||
description <<~EOS
|
||||
List installed casks and formulae that have an updated version available. By default, version
|
||||
information is displayed in interactive shells, and suppressed otherwise.
|
||||
@ -45,26 +45,24 @@ module Homebrew
|
||||
|
||||
named_args [:formula, :cask]
|
||||
end
|
||||
end
|
||||
|
||||
def self.outdated
|
||||
args = outdated_args.parse
|
||||
|
||||
sig { override.void }
|
||||
def run
|
||||
case json_version(args.json)
|
||||
when :v1
|
||||
odie "`brew outdated --json=v1` is no longer supported. Use brew outdated --json=v2 instead."
|
||||
when :v2, :default
|
||||
formulae, casks = if args.formula?
|
||||
[outdated_formulae(args:), []]
|
||||
[outdated_formulae, []]
|
||||
elsif args.cask?
|
||||
[[], outdated_casks(args:)]
|
||||
[[], outdated_casks]
|
||||
else
|
||||
outdated_formulae_casks(args:)
|
||||
outdated_formulae_casks
|
||||
end
|
||||
|
||||
json = {
|
||||
"formulae" => json_info(formulae, args:),
|
||||
"casks" => json_info(casks, args:),
|
||||
"formulae" => json_info(formulae),
|
||||
"casks" => json_info(casks),
|
||||
}
|
||||
puts JSON.pretty_generate(json)
|
||||
|
||||
@ -72,20 +70,22 @@ module Homebrew
|
||||
|
||||
else
|
||||
outdated = if args.formula?
|
||||
outdated_formulae(args:)
|
||||
outdated_formulae
|
||||
elsif args.cask?
|
||||
outdated_casks(args:)
|
||||
outdated_casks
|
||||
else
|
||||
outdated_formulae_casks(args:).flatten
|
||||
outdated_formulae_casks.flatten
|
||||
end
|
||||
|
||||
print_outdated(outdated, args:)
|
||||
print_outdated(outdated)
|
||||
end
|
||||
|
||||
Homebrew.failed = args.named.present? && outdated.present?
|
||||
end
|
||||
|
||||
def self.print_outdated(formulae_or_casks, args:)
|
||||
private
|
||||
|
||||
def print_outdated(formulae_or_casks)
|
||||
formulae_or_casks.each do |formula_or_cask|
|
||||
if formula_or_cask.is_a?(Formula)
|
||||
f = formula_or_cask
|
||||
@ -123,7 +123,7 @@ module Homebrew
|
||||
end
|
||||
end
|
||||
|
||||
def self.json_info(formulae_or_casks, args:)
|
||||
def json_info(formulae_or_casks)
|
||||
formulae_or_casks.map do |formula_or_cask|
|
||||
if formula_or_cask.is_a?(Formula)
|
||||
f = formula_or_cask
|
||||
@ -148,11 +148,11 @@ module Homebrew
|
||||
end
|
||||
end
|
||||
|
||||
def self.verbose?
|
||||
($stdout.tty? || super) && !quiet?
|
||||
def verbose?
|
||||
($stdout.tty? || Context.current.verbose?) && !Context.current.quiet?
|
||||
end
|
||||
|
||||
def self.json_version(version)
|
||||
def json_version(version)
|
||||
version_hash = {
|
||||
nil => nil,
|
||||
true => :default,
|
||||
@ -165,19 +165,19 @@ module Homebrew
|
||||
version_hash[version]
|
||||
end
|
||||
|
||||
def self.outdated_formulae(args:)
|
||||
select_outdated((args.named.to_resolved_formulae.presence || Formula.installed), args:).sort
|
||||
def outdated_formulae
|
||||
select_outdated((args.named.to_resolved_formulae.presence || Formula.installed)).sort
|
||||
end
|
||||
|
||||
def self.outdated_casks(args:)
|
||||
def outdated_casks
|
||||
if args.named.present?
|
||||
select_outdated(args.named.to_casks, args:)
|
||||
select_outdated(args.named.to_casks)
|
||||
else
|
||||
select_outdated(Cask::Caskroom.casks, args:)
|
||||
select_outdated(Cask::Caskroom.casks)
|
||||
end
|
||||
end
|
||||
|
||||
def self.outdated_formulae_casks(args:)
|
||||
def outdated_formulae_casks
|
||||
formulae, casks = args.named.to_resolved_formulae_to_casks
|
||||
|
||||
if formulae.blank? && casks.blank?
|
||||
@ -185,10 +185,10 @@ module Homebrew
|
||||
casks = Cask::Caskroom.casks
|
||||
end
|
||||
|
||||
[select_outdated(formulae, args:).sort, select_outdated(casks, args:)]
|
||||
[select_outdated(formulae).sort, select_outdated(casks)]
|
||||
end
|
||||
|
||||
def self.select_outdated(formulae_or_casks, args:)
|
||||
def select_outdated(formulae_or_casks)
|
||||
formulae_or_casks.select do |formula_or_cask|
|
||||
if formula_or_cask.is_a?(Formula)
|
||||
formula_or_cask.outdated?(fetch_head: args.fetch_HEAD?)
|
||||
@ -198,4 +198,6 @@ module Homebrew
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
@ -1,8 +1,9 @@
|
||||
# frozen_string_literal: true
|
||||
|
||||
require "cmd/outdated"
|
||||
require "cmd/shared_examples/args_parse"
|
||||
|
||||
RSpec.describe "brew outdated" do
|
||||
RSpec.describe Homebrew::Cmd::Outdated do
|
||||
it_behaves_like "parseable arguments"
|
||||
|
||||
it "outputs JSON", :integration_test do
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user