aboutsummaryrefslogtreecommitdiffstats
path: root/Library/Homebrew/cmd
diff options
context:
space:
mode:
authorMisty De Meo2012-08-15 22:08:40 -0500
committerMisty De Meo2012-09-17 20:01:37 -0500
commit33442291229d692fbdf05c3f4c03878fc64ea759 (patch)
treeff9fdcdc1c328690a239827580fc06cd4a08dbcd /Library/Homebrew/cmd
parentb29d1fdd5f1167b9c9e08b3db08ac214ef522d9c (diff)
downloadhomebrew-33442291229d692fbdf05c3f4c03878fc64ea759.tar.bz2
info: Add JSON output
Output JSON with the --json=v1 option. Output is in an array, and supports one or more formulae (or all, with the --all option). Why 'v1'? The format is unstable, presumably we'll deprecate it someday. It should be solid by Homebrew 1.0. Closes #13299.
Diffstat (limited to 'Library/Homebrew/cmd')
-rw-r--r--Library/Homebrew/cmd/info.rb22
1 files changed, 22 insertions, 0 deletions
diff --git a/Library/Homebrew/cmd/info.rb b/Library/Homebrew/cmd/info.rb
index c9040eac6..6fe43e687 100644
--- a/Library/Homebrew/cmd/info.rb
+++ b/Library/Homebrew/cmd/info.rb
@@ -4,6 +4,16 @@ require 'keg'
module Homebrew extend self
def info
+ # eventually we'll solidify an API, but we'll keep old versions
+ # awhile around for compatibility
+ if ARGV.json == "v1"
+ print_json
+ else
+ print_info
+ end
+ end
+
+ def print_info
if ARGV.named.empty?
if ARGV.include? "--all"
Formula.each do |f|
@@ -20,6 +30,18 @@ module Homebrew extend self
end
end
+ def print_json
+ require 'vendor/multi_json'
+
+ formulae = ARGV.include?("--all") ? Formula : ARGV.formulae
+ json = formulae.map {|f| f.to_hash}
+ if json.size == 1
+ puts MultiJson.encode json.pop
+ else
+ puts MultiJson.encode json
+ end
+ end
+
def github_fork
if which 'git' and (HOMEBREW_REPOSITORY/".git").directory?
if `git remote -v` =~ %r{origin\s+(https?://|git(?:@|://))github.com[:/](.+)/homebrew}