outdated: Allow references to cask
This commit is contained in:
parent
ad04284a20
commit
bdc99ebd98
@ -3,6 +3,8 @@
|
||||
require "formula"
|
||||
require "keg"
|
||||
require "cli/parser"
|
||||
require "cask/cmd"
|
||||
require "cask/caskroom"
|
||||
|
||||
module Homebrew
|
||||
module_function
|
||||
@ -22,43 +24,67 @@ module Homebrew
|
||||
flag "--json",
|
||||
description: "Print output in JSON format. Currently the default and only accepted "\
|
||||
"value for <version> is `v1`. See the docs for examples of using the JSON "\
|
||||
"output: <https://docs.brew.sh/Querying-Brew>"
|
||||
"output: <https://docs.brew.sh/Querying-Brew>."\
|
||||
"By default, this option treats all arguments as formulae."\
|
||||
"To treat arguments as casks, use the --cask-only option."
|
||||
switch "--fetch-HEAD",
|
||||
description: "Fetch the upstream repository to detect if the HEAD installation of the "\
|
||||
"formula is outdated. Otherwise, the repository's HEAD will only be checked for "\
|
||||
"updates when a new stable or development version has been released."
|
||||
switch "--greedy",
|
||||
description: "Print outdated casks with `auto_updates` or `version :latest`"
|
||||
switch "--formula-only",
|
||||
description: "Treat all arguments as formulae"
|
||||
switch "--cask-only",
|
||||
description: "Treat all arguments as casks"
|
||||
switch :debug
|
||||
conflicts "--quiet", "--verbose", "--json"
|
||||
conflicts "--formula-only", "--cask-only"
|
||||
end
|
||||
end
|
||||
|
||||
def outdated
|
||||
outdated_args.parse
|
||||
|
||||
formulae = if args.resolved_formulae.blank?
|
||||
Formula.installed
|
||||
if args.formula_only? || !args.cask_only? && args.json
|
||||
formulae = args.resolved_formulae.blank? ? Formula.installed : args.resolved_formulae
|
||||
outdated = print_outdated_formulae(formulae)
|
||||
|
||||
Homebrew.failed = !formulae.blank? && !outdated.blank?
|
||||
elsif args.cask_only?
|
||||
casks = args.named.blank? ? Cask::Caskroom.casks : args.named
|
||||
outdated = print_outdated_casks(casks)
|
||||
|
||||
Homebrew.failed = !casks.blank? && !outdated.blank?
|
||||
else
|
||||
args.resolved_formulae
|
||||
formulae, casks = args.resolved_formulae_casks
|
||||
|
||||
if formulae.blank? && casks.blank?
|
||||
formulae = Formula.installed
|
||||
casks = Cask::Caskroom.casks
|
||||
end
|
||||
|
||||
outdated_formulae = print_outdated_formulae(formulae)
|
||||
outdated_casks = print_outdated_casks(casks)
|
||||
|
||||
Homebrew.failed = !formulae.blank? && !outdated_formulae.blank? || !casks.blank? && !outdated_casks.blank?
|
||||
end
|
||||
end
|
||||
|
||||
def print_outdated_formulae(formulae)
|
||||
if args.json
|
||||
raise UsageError, "invalid JSON version: #{args.json}" unless ["v1", true].include? args.json
|
||||
|
||||
outdated = print_outdated_json(formulae)
|
||||
else
|
||||
outdated = print_outdated(formulae)
|
||||
end
|
||||
Homebrew.failed = args.resolved_formulae.present? && !outdated.empty?
|
||||
return print_outdated_formulae_json(formulae)
|
||||
end
|
||||
|
||||
def print_outdated(formulae)
|
||||
verbose = ($stdout.tty? || args.verbose?) && !args.quiet?
|
||||
fetch_head = args.fetch_HEAD?
|
||||
|
||||
outdated_formulae = formulae.select { |f| f.outdated?(fetch_head: fetch_head) }
|
||||
.sort
|
||||
|
||||
outdated_formulae.each do |f|
|
||||
if verbose
|
||||
if verbose?
|
||||
outdated_kegs = f.outdated_kegs(fetch_head: fetch_head)
|
||||
|
||||
current_version = if f.alias_changed?
|
||||
@ -87,7 +113,7 @@ module Homebrew
|
||||
end
|
||||
end
|
||||
|
||||
def print_outdated_json(formulae)
|
||||
def print_outdated_formulae_json(formulae)
|
||||
json = []
|
||||
fetch_head = args.fetch_HEAD?
|
||||
outdated_formulae = formulae.select { |f| f.outdated?(fetch_head: fetch_head) }
|
||||
@ -110,4 +136,20 @@ module Homebrew
|
||||
|
||||
outdated
|
||||
end
|
||||
|
||||
def print_outdated_casks(casks)
|
||||
outdated = casks.map { |cask| Cask::CaskLoader.load(cask) }.select do |cask|
|
||||
odebug "Checking update info of Cask #{cask}"
|
||||
cask.outdated?(args.greedy?)
|
||||
end
|
||||
|
||||
output = outdated.map { |cask| cask.outdated_info(args.greedy?, verbose?, args.json?) }
|
||||
puts args.json ? JSON.generate(output) : output
|
||||
|
||||
outdated
|
||||
end
|
||||
|
||||
def verbose?
|
||||
($stdout.tty? || args.verbose?) && !args.quiet?
|
||||
end
|
||||
end
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user