outdated: Allow references to cask
This commit is contained in:
parent
ad04284a20
commit
bdc99ebd98
@ -3,6 +3,8 @@
|
|||||||
require "formula"
|
require "formula"
|
||||||
require "keg"
|
require "keg"
|
||||||
require "cli/parser"
|
require "cli/parser"
|
||||||
|
require "cask/cmd"
|
||||||
|
require "cask/caskroom"
|
||||||
|
|
||||||
module Homebrew
|
module Homebrew
|
||||||
module_function
|
module_function
|
||||||
@ -22,43 +24,67 @@ module Homebrew
|
|||||||
flag "--json",
|
flag "--json",
|
||||||
description: "Print output in JSON format. Currently the default and only accepted "\
|
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 "\
|
"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",
|
switch "--fetch-HEAD",
|
||||||
description: "Fetch the upstream repository to detect if the HEAD installation of the "\
|
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 "\
|
"formula is outdated. Otherwise, the repository's HEAD will only be checked for "\
|
||||||
"updates when a new stable or development version has been released."
|
"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
|
switch :debug
|
||||||
conflicts "--quiet", "--verbose", "--json"
|
conflicts "--quiet", "--verbose", "--json"
|
||||||
|
conflicts "--formula-only", "--cask-only"
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
def outdated
|
def outdated
|
||||||
outdated_args.parse
|
outdated_args.parse
|
||||||
|
|
||||||
formulae = if args.resolved_formulae.blank?
|
if args.formula_only? || !args.cask_only? && args.json
|
||||||
Formula.installed
|
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
|
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
|
||||||
|
end
|
||||||
|
|
||||||
|
def print_outdated_formulae(formulae)
|
||||||
if args.json
|
if args.json
|
||||||
raise UsageError, "invalid JSON version: #{args.json}" unless ["v1", true].include? args.json
|
raise UsageError, "invalid JSON version: #{args.json}" unless ["v1", true].include? args.json
|
||||||
|
|
||||||
outdated = print_outdated_json(formulae)
|
return print_outdated_formulae_json(formulae)
|
||||||
else
|
|
||||||
outdated = print_outdated(formulae)
|
|
||||||
end
|
end
|
||||||
Homebrew.failed = args.resolved_formulae.present? && !outdated.empty?
|
|
||||||
end
|
|
||||||
|
|
||||||
def print_outdated(formulae)
|
|
||||||
verbose = ($stdout.tty? || args.verbose?) && !args.quiet?
|
|
||||||
fetch_head = args.fetch_HEAD?
|
fetch_head = args.fetch_HEAD?
|
||||||
|
|
||||||
outdated_formulae = formulae.select { |f| f.outdated?(fetch_head: fetch_head) }
|
outdated_formulae = formulae.select { |f| f.outdated?(fetch_head: fetch_head) }
|
||||||
.sort
|
.sort
|
||||||
|
|
||||||
outdated_formulae.each do |f|
|
outdated_formulae.each do |f|
|
||||||
if verbose
|
if verbose?
|
||||||
outdated_kegs = f.outdated_kegs(fetch_head: fetch_head)
|
outdated_kegs = f.outdated_kegs(fetch_head: fetch_head)
|
||||||
|
|
||||||
current_version = if f.alias_changed?
|
current_version = if f.alias_changed?
|
||||||
@ -87,7 +113,7 @@ module Homebrew
|
|||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
def print_outdated_json(formulae)
|
def print_outdated_formulae_json(formulae)
|
||||||
json = []
|
json = []
|
||||||
fetch_head = args.fetch_HEAD?
|
fetch_head = args.fetch_HEAD?
|
||||||
outdated_formulae = formulae.select { |f| f.outdated?(fetch_head: fetch_head) }
|
outdated_formulae = formulae.select { |f| f.outdated?(fetch_head: fetch_head) }
|
||||||
@ -110,4 +136,20 @@ module Homebrew
|
|||||||
|
|
||||||
outdated
|
outdated
|
||||||
end
|
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
|
end
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user