--cellar.rb 741 Bytes
Newer Older
Markus Reiter's avatar
Markus Reiter committed
1
# typed: true
2
3
# frozen_string_literal: true

4
require "cli/parser"
5

6
module Homebrew
7
8
  module_function

Mike McQuaid's avatar
Mike McQuaid committed
9
10
11
  def __cellar_args
    Homebrew::CLI::Parser.new do
      usage_banner <<~EOS
12
        `--cellar` [<formula>]
Mike McQuaid's avatar
Mike McQuaid committed
13
14
15
16

        Display Homebrew's Cellar path. *Default:* `$(brew --prefix)/Cellar`, or if
        that directory doesn't exist, `$(brew --repository)/Cellar`.

17
        If <formula> is provided, display the location in the Cellar where <formula>
Mike McQuaid's avatar
Mike McQuaid committed
18
19
20
21
22
        would be installed, without any sort of versioned directory as the last path.
      EOS
    end
  end

23
  def __cellar
Markus Reiter's avatar
Markus Reiter committed
24
    args = __cellar_args.parse
Mike McQuaid's avatar
Mike McQuaid committed
25

26
    if args.no_named?
27
28
      puts HOMEBREW_CELLAR
    else
29
      puts args.named.to_resolved_formulae.map(&:rack)
30
31
32
    end
  end
end