--prefix.rb 786 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
Markus Reiter's avatar
Markus Reiter committed
7
8
  extend T::Sig

9
10
  module_function

Markus Reiter's avatar
Markus Reiter committed
11
  sig { returns(CLI::Parser) }
Mike McQuaid's avatar
Mike McQuaid committed
12
13
14
15
16
17
18
19
  def __prefix_args
    Homebrew::CLI::Parser.new do
      usage_banner <<~EOS
        `--prefix` [<formula>]

        Display Homebrew's install path. *Default:* `/usr/local` on macOS and
        `/home/linuxbrew/.linuxbrew` on Linux.

20
        If <formula> is provided, display the location in the Cellar where <formula>
Mike McQuaid's avatar
Mike McQuaid committed
21
22
23
24
25
        is or would be installed.
      EOS
    end
  end

26
  def __prefix
Markus Reiter's avatar
Markus Reiter committed
27
    args = __prefix_args.parse
Mike McQuaid's avatar
Mike McQuaid committed
28

29
    if args.no_named?
30
31
      puts HOMEBREW_PREFIX
    else
32
      puts args.named.to_resolved_formulae.map { |f|
33
        f.opt_prefix.exist? ? f.opt_prefix : f.latest_installed_prefix
34
      }
35
36
37
    end
  end
end