aboutsummaryrefslogtreecommitdiffstats
path: root/Library/Homebrew/cmd/outdated.rb
diff options
context:
space:
mode:
authorColin Dean2014-07-06 11:41:03 -0400
committerJack Nagel2015-06-25 19:32:23 -0400
commite12295849da2aac67cb7266f165a054a0a0ca5b7 (patch)
tree576178e7971747cd5ab1ba38f003d2bef57c70fb /Library/Homebrew/cmd/outdated.rb
parent4c7c17255a1c7d9d089616e8f7772cf5b3626763 (diff)
downloadbrew-e12295849da2aac67cb7266f165a054a0a0ca5b7.tar.bz2
Adds JSON output to `outdated` command
After some musing on brunophilipe/Cakebrew#71, I thought it would be useful to let Cakebrew and other tools grab the outdated formulae version information using a method more elegant than regex. Closes Homebrew/homebrew#30693. Signed-off-by: Jack Nagel <jacknagel@gmail.com>
Diffstat (limited to 'Library/Homebrew/cmd/outdated.rb')
-rw-r--r--Library/Homebrew/cmd/outdated.rb38
1 files changed, 30 insertions, 8 deletions
diff --git a/Library/Homebrew/cmd/outdated.rb b/Library/Homebrew/cmd/outdated.rb
index 6ae5254e5..10fa36953 100644
--- a/Library/Homebrew/cmd/outdated.rb
+++ b/Library/Homebrew/cmd/outdated.rb
@@ -3,14 +3,10 @@ require 'keg'
module Homebrew
def outdated
- formulae = ARGV.resolved_formulae.any? ? ARGV.resolved_formulae : Formula.installed
-
- outdated = outdated_brews(formulae) do |f, versions|
- if ($stdout.tty? || ARGV.verbose?) && !ARGV.flag?("--quiet")
- puts "#{f.full_name} (#{versions*', '} < #{f.pkg_version})"
- else
- puts f.full_name
- end
+ if ARGV.json == "v1"
+ outdated = print_outdated_json
+ else
+ outdated = print_outdated
end
Homebrew.failed = ARGV.resolved_formulae.any? && outdated.any?
end
@@ -37,4 +33,30 @@ module Homebrew
end
end.compact
end
+
+ def formulae_to_check
+ ARGV.resolved_formulae.any? ? ARGV.resolved_formulae : Formula.installed
+ end
+
+ def print_outdated
+ outdated_brews(formulae_to_check) do |f, versions|
+ if ($stdout.tty? || ARGV.verbose?) && !ARGV.flag?("--quiet")
+ puts "#{f.full_name} (#{versions*', '} < #{f.pkg_version})"
+ else
+ puts f.full_name
+ end
+ end
+ end
+
+ def print_outdated_json
+ json = []
+ outdated = outdated_brews(formulae_to_check) do |f, versions|
+ json << {:name => f.name,
+ :installed_versions => versions.collect(&:to_s),
+ :current_version => f.pkg_version.to_s}
+ end
+ puts Utils::JSON.dump(json)
+
+ outdated
+ end
end