blob: dfd61226aadc08dfc31f1cd707774f4d255fd4ac (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
  | 
#:  * `outdated` [`--quiet`|`--verbose`|`--json=v1`]:
#:    Show formulae that have an updated version available.
#:
#:    By default, version information is displayed in interactive shells, and
#:    suppressed otherwise.
#:
#:    If `--quiet` is passed, list only the names of outdated brews (takes
#:    precedence over `--verbose`).
#:
#:    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`.
require "formula"
require "keg"
module Homebrew
  def outdated
    formulae = ARGV.resolved_formulae.any? ? ARGV.resolved_formulae : Formula.installed
    if ARGV.json == "v1"
      outdated = print_outdated_json(formulae)
    else
      outdated = print_outdated(formulae)
    end
    Homebrew.failed = ARGV.resolved_formulae.any? && outdated.any?
  end
  def print_outdated(formulae)
    verbose = ($stdout.tty? || ARGV.verbose?) && !ARGV.flag?("--quiet")
    formulae.select(&:outdated?).each do |f|
      if verbose
        puts "#{f.full_name} (#{f.outdated_versions*", "} < #{f.pkg_version})"
      else
        puts f.full_name
      end
    end
  end
  def print_outdated_json(formulae)
    json = []
    outdated = formulae.select(&:outdated?).each do |f|
      json << { :name => f.full_name,
                :installed_versions => f.outdated_versions.collect(&:to_s),
                :current_version => f.pkg_version.to_s }
    end
    puts Utils::JSON.dump(json)
    outdated
  end
end
  |