2017-02-25 17:37:57 -05:00
|
|
|
#: * `outdated` [`--quiet`|`--verbose`|`--json=`<version>] [`--fetch-HEAD`]:
|
2016-04-08 16:28:43 +02:00
|
|
|
#: Show formulae that have an updated version available.
|
|
|
|
#:
|
|
|
|
#: By default, version information is displayed in interactive shells, and
|
|
|
|
#: suppressed otherwise.
|
|
|
|
#:
|
|
|
|
#: If `--quiet` is passed, list only the names of outdated brews (takes
|
|
|
|
#: precedence over `--verbose`).
|
|
|
|
#:
|
2017-04-02 10:14:21 +01:00
|
|
|
#: If `--verbose` (or `-v`) is passed, display detailed version information.
|
2016-04-08 16:28:43 +02:00
|
|
|
#:
|
2018-02-01 16:06:17 -05:00
|
|
|
#: If `--json=`<version> is passed, the output will be in JSON format.
|
|
|
|
#: Currently the only accepted value for <version> is `v1`.
|
2016-08-06 17:08:35 +03:00
|
|
|
#:
|
2016-08-11 09:28:29 +02:00
|
|
|
#: If `--fetch-HEAD` is passed, fetch the upstream repository to detect if
|
|
|
|
#: the HEAD installation of the formula is outdated. Otherwise, the
|
|
|
|
#: repository's HEAD will be checked for updates when a new stable or devel
|
|
|
|
#: version has been released.
|
2016-04-08 16:28:43 +02:00
|
|
|
|
2015-08-03 13:09:07 +01:00
|
|
|
require "formula"
|
|
|
|
require "keg"
|
2018-11-05 16:59:46 +05:30
|
|
|
require "cli_parser"
|
2010-09-11 20:22:54 +01:00
|
|
|
|
2014-06-18 22:41:47 -05:00
|
|
|
module Homebrew
|
2016-09-26 01:44:51 +02:00
|
|
|
module_function
|
|
|
|
|
2018-11-05 16:59:46 +05:30
|
|
|
def outdated_args
|
|
|
|
Homebrew::CLI::Parser.new do
|
|
|
|
usage_banner <<~EOS
|
|
|
|
`outdated` [<options>]
|
|
|
|
|
|
|
|
Show formulae that have an updated version available.
|
|
|
|
|
|
|
|
By default, version information is displayed in interactive shells, and
|
|
|
|
suppressed otherwise.
|
|
|
|
EOS
|
|
|
|
switch :quiet,
|
|
|
|
description: "List only the names of outdated brews (takes precedence over `--verbose`)."
|
|
|
|
switch :verbose,
|
|
|
|
description: "Display detailed version information."
|
|
|
|
flag "--json=",
|
|
|
|
description: "Show output in JSON format for provided <version>. Currently the only "\
|
|
|
|
"accepted value of <version> is `v1`."
|
|
|
|
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 be checked for "\
|
|
|
|
"updates when a new stable or devel version has been released."
|
|
|
|
switch :debug
|
2019-01-29 19:39:41 +00:00
|
|
|
conflicts "--quiet", "--verbose", "--json="
|
2018-11-05 16:59:46 +05:30
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2010-09-11 20:22:54 +01:00
|
|
|
def outdated
|
2018-11-05 16:59:46 +05:30
|
|
|
outdated_args.parse
|
|
|
|
|
2016-08-05 22:01:32 +08:00
|
|
|
formulae = if ARGV.resolved_formulae.empty?
|
|
|
|
Formula.installed
|
|
|
|
else
|
|
|
|
ARGV.resolved_formulae
|
|
|
|
end
|
2018-11-05 16:59:46 +05:30
|
|
|
if args.json == "v1"
|
2015-06-26 15:15:51 +08:00
|
|
|
outdated = print_outdated_json(formulae)
|
2014-07-06 11:41:03 -04:00
|
|
|
else
|
2015-06-26 15:15:51 +08:00
|
|
|
outdated = print_outdated(formulae)
|
2010-09-11 20:22:54 +01:00
|
|
|
end
|
2016-08-05 22:01:32 +08:00
|
|
|
Homebrew.failed = !ARGV.resolved_formulae.empty? && !outdated.empty?
|
2010-09-11 20:22:54 +01:00
|
|
|
end
|
|
|
|
|
2015-06-26 15:15:51 +08:00
|
|
|
def print_outdated(formulae)
|
2018-11-05 16:59:46 +05:30
|
|
|
verbose = ($stdout.tty? || args.verbose?) && !args.quiet?
|
|
|
|
fetch_head = args.fetch_HEAD?
|
2015-06-25 19:33:47 -04:00
|
|
|
|
2018-05-16 13:41:40 +01:00
|
|
|
outdated_formulae = formulae.select { |f| f.outdated?(fetch_head: fetch_head) }
|
|
|
|
.sort
|
2016-07-22 12:47:47 +03:00
|
|
|
|
|
|
|
outdated_formulae.each do |f|
|
2015-06-25 19:33:47 -04:00
|
|
|
if verbose
|
2016-09-15 16:01:18 +01:00
|
|
|
outdated_kegs = f.outdated_kegs(fetch_head: fetch_head)
|
|
|
|
|
|
|
|
current_version = if f.alias_changed?
|
|
|
|
latest = f.latest_formula
|
|
|
|
"#{latest.name} (#{latest.pkg_version})"
|
|
|
|
elsif f.head? && outdated_kegs.any? { |k| k.version.to_s == f.pkg_version.to_s }
|
|
|
|
# There is a newer HEAD but the version number has not changed.
|
2016-07-22 12:47:47 +03:00
|
|
|
"latest HEAD"
|
|
|
|
else
|
|
|
|
f.pkg_version.to_s
|
|
|
|
end
|
2016-09-15 16:01:18 +01:00
|
|
|
|
2016-09-19 16:04:32 +01:00
|
|
|
outdated_versions = outdated_kegs
|
2016-10-20 00:53:10 +03:00
|
|
|
.group_by { |keg| Formulary.from_keg(keg).full_name }
|
|
|
|
.sort_by { |full_name, _kegs| full_name }
|
|
|
|
.map do |full_name, kegs|
|
|
|
|
"#{full_name} (#{kegs.map(&:version).join(", ")})"
|
2016-09-19 16:04:32 +01:00
|
|
|
end.join(", ")
|
2016-09-15 16:01:18 +01:00
|
|
|
|
2017-03-27 11:30:36 +01:00
|
|
|
pinned_version = " [pinned at #{f.pinned_version}]" if f.pinned?
|
|
|
|
|
|
|
|
puts "#{outdated_versions} < #{current_version}#{pinned_version}"
|
2014-07-06 11:41:03 -04:00
|
|
|
else
|
2016-09-15 16:01:18 +01:00
|
|
|
puts f.full_installed_specified_name
|
2014-07-06 11:41:03 -04:00
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2015-06-26 15:15:51 +08:00
|
|
|
def print_outdated_json(formulae)
|
2014-07-06 11:41:03 -04:00
|
|
|
json = []
|
2018-11-05 16:59:46 +05:30
|
|
|
fetch_head = args.fetch_HEAD?
|
2016-09-17 15:32:44 +01:00
|
|
|
outdated_formulae = formulae.select { |f| f.outdated?(fetch_head: fetch_head) }
|
2016-07-22 12:47:47 +03:00
|
|
|
|
|
|
|
outdated = outdated_formulae.each do |f|
|
2016-09-15 16:01:18 +01:00
|
|
|
outdated_versions = f.outdated_kegs(fetch_head: fetch_head).map(&:version)
|
2016-07-22 12:47:47 +03:00
|
|
|
current_version = if f.head? && outdated_versions.any? { |v| v.to_s == f.pkg_version.to_s }
|
|
|
|
"HEAD"
|
|
|
|
else
|
|
|
|
f.pkg_version.to_s
|
|
|
|
end
|
2015-11-27 15:11:00 +00:00
|
|
|
|
2018-11-02 17:18:07 +00:00
|
|
|
json << { name: f.full_name,
|
2018-09-02 20:14:54 +01:00
|
|
|
installed_versions: outdated_versions.map(&:to_s),
|
2018-11-02 17:18:07 +00:00
|
|
|
current_version: current_version,
|
|
|
|
pinned: f.pinned?,
|
|
|
|
pinned_version: f.pinned_version }
|
2014-07-06 11:41:03 -04:00
|
|
|
end
|
2016-11-20 13:00:01 -05:00
|
|
|
puts JSON.generate(json)
|
2014-07-06 11:41:03 -04:00
|
|
|
|
|
|
|
outdated
|
|
|
|
end
|
2011-09-11 13:06:05 -07:00
|
|
|
end
|