missing.rb 1.16 KB
Newer Older
Markus Reiter's avatar
Markus Reiter committed
1
# typed: true
2
3
# frozen_string_literal: true

BrewTestBot's avatar
BrewTestBot committed
4
5
require "formula"
require "tab"
6
require "diagnostic"
7
require "cli/parser"
Adam Vandenberg's avatar
Adam Vandenberg committed
8

9
module Homebrew
Markus Reiter's avatar
Markus Reiter committed
10
11
  extend T::Sig

12
13
  module_function

Markus Reiter's avatar
Markus Reiter committed
14
  sig { returns(CLI::Parser) }
15
16
17
  def missing_args
    Homebrew::CLI::Parser.new do
      usage_banner <<~EOS
18
        `missing` [<options>] [<formula>]
19

20
21
22
        Check the given <formula> kegs for missing dependencies. If no <formula> are
        provided, check all kegs. Will exit with a non-zero status if any kegs are found
        to be missing dependencies.
23
24
      EOS
      comma_array "--hide",
25
                  description: "Act as if none of the specified <hidden> are installed. <hidden> should be "\
EricFromCanada's avatar
EricFromCanada committed
26
                               "a comma-separated list of formulae."
27
28
29
    end
  end

Adam Vandenberg's avatar
Adam Vandenberg committed
30
  def missing
Markus Reiter's avatar
Markus Reiter committed
31
    args = missing_args.parse
32

Adam Vandenberg's avatar
Adam Vandenberg committed
33
34
    return unless HOMEBREW_CELLAR.exist?

35
    ff = if args.no_named?
36
      Formula.installed.sort
Adam Vandenberg's avatar
Adam Vandenberg committed
37
    else
38
      args.named.to_resolved_formulae.sort
Adam Vandenberg's avatar
Adam Vandenberg committed
39
40
    end

41
    ff.each do |f|
42
      missing = f.missing_dependencies(hide: args.hide)
43
44
      next if missing.empty?

45
      Homebrew.failed = true
46
      print "#{f}: " if ff.size > 1
Mike McQuaid's avatar
Mike McQuaid committed
47
      puts missing.join(" ")
Adam Vandenberg's avatar
Adam Vandenberg committed
48
49
50
    end
  end
end