Skip to content
Snippets Groups Projects
Commit e1229584 authored by Colin Dean's avatar Colin Dean Committed by Jack Nagel
Browse files

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: default avatarJack Nagel <jacknagel@gmail.com>
parent 4c7c1725
No related branches found
No related tags found
No related merge requests found
...@@ -395,7 +395,7 @@ _brew_outdated () ...@@ -395,7 +395,7 @@ _brew_outdated ()
local cur="${COMP_WORDS[COMP_CWORD]}" local cur="${COMP_WORDS[COMP_CWORD]}"
case "$cur" in case "$cur" in
--*) --*)
__brewcomp "--quiet" __brewcomp "--quiet --json=v1"
return return
;; ;;
esac esac
......
...@@ -3,14 +3,10 @@ require 'keg' ...@@ -3,14 +3,10 @@ require 'keg'
module Homebrew module Homebrew
def outdated def outdated
formulae = ARGV.resolved_formulae.any? ? ARGV.resolved_formulae : Formula.installed if ARGV.json == "v1"
outdated = print_outdated_json
outdated = outdated_brews(formulae) do |f, versions| else
if ($stdout.tty? || ARGV.verbose?) && !ARGV.flag?("--quiet") outdated = print_outdated
puts "#{f.full_name} (#{versions*', '} < #{f.pkg_version})"
else
puts f.full_name
end
end end
Homebrew.failed = ARGV.resolved_formulae.any? && outdated.any? Homebrew.failed = ARGV.resolved_formulae.any? && outdated.any?
end end
...@@ -37,4 +33,30 @@ module Homebrew ...@@ -37,4 +33,30 @@ module Homebrew
end end
end.compact end.compact
end 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 end
...@@ -296,7 +296,7 @@ Note that these flags should only appear after a command. ...@@ -296,7 +296,7 @@ Note that these flags should only appear after a command.
If `--installed` is passed, show options for all installed formulae. If `--installed` is passed, show options for all installed formulae.
* `outdated [--quiet|--verbose]`: * `outdated [--quiet | --verbose | --json=v1 ]`:
Show formulae that have an updated version available. Show formulae that have an updated version available.
By default, version information is displayed in interactive shells, and By default, version information is displayed in interactive shells, and
...@@ -307,6 +307,9 @@ Note that these flags should only appear after a command. ...@@ -307,6 +307,9 @@ Note that these flags should only appear after a command.
If `--verbose` is passed, display detailed version information. If `--verbose` is passed, display detailed version information.
If `--json=<version>` is passed, the output will be in JSON format. The only
valid version is `v1`.
* `pin` <formulae>: * `pin` <formulae>:
Pin the specified <formulae>, preventing them from being upgraded when Pin the specified <formulae>, preventing them from being upgraded when
issuing the `brew upgrade --all` command. See also `unpin`. issuing the `brew upgrade --all` command. See also `unpin`.
......
...@@ -290,7 +290,7 @@ If \fB\-\-all\fR is passed, show options for all formulae\. ...@@ -290,7 +290,7 @@ If \fB\-\-all\fR is passed, show options for all formulae\.
If \fB\-\-installed\fR is passed, show options for all installed formulae\. If \fB\-\-installed\fR is passed, show options for all installed formulae\.
. .
.IP "\(bu" 4 .IP "\(bu" 4
\fBoutdated [\-\-quiet|\-\-verbose]\fR: Show formulae that have an updated version available\. \fBoutdated [\-\-quiet | \-\-verbose | \-\-json=v1 ]\fR: Show formulae that have an updated version available\.
. .
.IP .IP
By default, version information is displayed in interactive shells, and suppressed otherwise\. By default, version information is displayed in interactive shells, and suppressed otherwise\.
...@@ -301,6 +301,9 @@ If \fB\-\-quiet\fR is passed, list only the names of outdated brews (takes prece ...@@ -301,6 +301,9 @@ If \fB\-\-quiet\fR is passed, list only the names of outdated brews (takes prece
.IP .IP
If \fB\-\-verbose\fR is passed, display detailed version information\. If \fB\-\-verbose\fR is passed, display detailed version information\.
. .
.IP
If \fB\-\-json=<version>\fR is passed, the output will be in JSON format\. The only valid version is \fBv1\fR\.
.
.IP "\(bu" 4 .IP "\(bu" 4
\fBpin\fR \fIformulae\fR: Pin the specified \fIformulae\fR, preventing them from being upgraded when issuing the \fBbrew upgrade \-\-all\fR command\. See also \fBunpin\fR\. \fBpin\fR \fIformulae\fR: Pin the specified \fIformulae\fR, preventing them from being upgraded when issuing the \fBbrew upgrade \-\-all\fR command\. See also \fBunpin\fR\.
. .
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment