add --installed to json info

Closes Homebrew/homebrew#29315.
This commit is contained in:
Adam Vandenberg 2014-05-16 08:47:09 -07:00
parent 99ebf05b9c
commit d9ed121c46
5 changed files with 18 additions and 5 deletions

View File

@ -222,7 +222,7 @@ _brew_info ()
local cur="${COMP_WORDS[COMP_CWORD]}" local cur="${COMP_WORDS[COMP_CWORD]}"
case "$cur" in case "$cur" in
--*) --*)
__brewcomp "--all --github --json=v1" __brewcomp "--all --github --installed --json=v1"
return return
;; ;;
esac esac

View File

@ -160,10 +160,13 @@ Note that these flags should only appear after a command.
To view formula history locally: `brew log -p <formula>`. To view formula history locally: `brew log -p <formula>`.
* `info --json=<version>` <formula>: * `info --json=<version>` (--all|--installed|<formula>):
Print a JSON representation of <formula>. Currently the only accepted value Print a JSON representation of <formula>. Currently the only accepted value
for <version> is `v1`. for <version> is `v1`.
Pass `--all` to get information on all formulae, or `--installed` to get
information on all installed formulae.
* `install [--debug] [--env=<std|super>] [--ignore-dependencies] [--only-dependencies] [--cc=<compiler>] [--build-from-source] [--devel|--HEAD]` <formula>: * `install [--debug] [--env=<std|super>] [--ignore-dependencies] [--only-dependencies] [--cc=<compiler>] [--build-from-source] [--devel|--HEAD]` <formula>:
Install <formula>. Install <formula>.

View File

@ -41,8 +41,14 @@ module Homebrew extend self
end end
def print_json def print_json
formulae = ARGV.include?("--all") ? Formula : ARGV.formulae ff = if ARGV.include? "--all"
json = formulae.map {|f| f.to_hash} Formula
elsif ARGV.include? "--installed"
Formula.installed
else
ARGV.formulae
end
json = ff.map {|f| f.to_hash}
if json.size == 1 if json.size == 1
puts Utils::JSON.dump(json.pop) puts Utils::JSON.dump(json.pop)
else else

View File

@ -369,6 +369,7 @@ class Formula
include Enumerable include Enumerable
end end
# An array of all installed formulae
def self.installed def self.installed
return [] unless HOMEBREW_CELLAR.directory? return [] unless HOMEBREW_CELLAR.directory?

View File

@ -177,9 +177,12 @@ Open a browser to the GitHub History page for formula \fIformula\fR\.
To view formula history locally: \fBbrew log \-p <formula>\fR\. To view formula history locally: \fBbrew log \-p <formula>\fR\.
. .
.TP .TP
\fBinfo \-\-json=<version>\fR \fIformula\fR \fBinfo \-\-json=<version>\fR (\-\-all|\-\-installed|\fIformula\fR)
Print a JSON representation of \fIformula\fR\. Currently the only accepted value for \fIversion\fR is \fBv1\fR\. Print a JSON representation of \fIformula\fR\. Currently the only accepted value for \fIversion\fR is \fBv1\fR\.
. .
.IP
Pass \fB\-\-all\fR to get information on all formulae, or \fB\-\-installed\fR to get information on all installed formulae\.
.
.TP .TP
\fBinstall [\-\-debug] [\-\-env=<std|super>] [\-\-ignore\-dependencies] [\-\-only\-dependencies] [\-\-cc=<compiler>] [\-\-build\-from\-source] [\-\-devel|\-\-HEAD]\fR \fIformula\fR \fBinstall [\-\-debug] [\-\-env=<std|super>] [\-\-ignore\-dependencies] [\-\-only\-dependencies] [\-\-cc=<compiler>] [\-\-build\-from\-source] [\-\-devel|\-\-HEAD]\fR \fIformula\fR
Install \fIformula\fR\. Install \fIformula\fR\.