diff options
| author | Misty De Meo | 2012-08-15 22:08:40 -0500 |
|---|---|---|
| committer | Misty De Meo | 2012-09-17 20:01:37 -0500 |
| commit | 2f2645e962974002bdd6e78111678bb2d5f9b389 (patch) | |
| tree | efbd3e0d6991a008fe0643f8192a70ba2afbb890 /Library | |
| parent | ee4c696380fe34cd3a5dcca42156f4f56f7f3dcc (diff) | |
| download | brew-2f2645e962974002bdd6e78111678bb2d5f9b389.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 Homebrew/homebrew#13299.
Diffstat (limited to 'Library')
| -rw-r--r-- | Library/Homebrew/cmd/info.rb | 22 | ||||
| -rw-r--r-- | Library/Homebrew/formula.rb | 43 |
2 files changed, 65 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} diff --git a/Library/Homebrew/formula.rb b/Library/Homebrew/formula.rb index 184775835..bf784d0ce 100644 --- a/Library/Homebrew/formula.rb +++ b/Library/Homebrew/formula.rb @@ -464,6 +464,49 @@ class Formula reqs.flatten end + def to_hash + hsh = { + "name" => name, + "homepage" => homepage, + "versions" => { + "stable" => (stable.version.to_s if stable), + "bottle" => bottle && MacOS.bottles_supported? || false, + "devel" => (devel.version.to_s if devel), + "head" => (head.version.to_s if head) + }, + "installed" => [], + "linked_keg" => (linked_keg.realpath.basename.to_s if linked_keg.exist?), + "keg_only" => keg_only?, + "dependencies" => deps.map {|dep| dep.to_s}, + "conflicts_with" => conflicts.map {|c| c.formula}, + "options" => [], + "caveats" => caveats + } + + build.each do |opt| + hsh["options"] << { + "option" => "--"+opt.name, + "description" => opt.description + } + end + + if rack.directory? + rack.children.each do |keg| + next if keg.basename.to_s == '.DS_Store' + tab = Tab.for_keg keg + + hsh["installed"] << { + "version" => keg.basename.to_s, + "used_options" => tab.used_options, + "built_as_bottle" => tab.built_bottle + } + end + end + + hsh + + end + protected # Pretty titles the command and buffers stdout/stderr |
