forked from Homebrew/homebrew-bundle
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathbrewfile.rb
53 lines (46 loc) · 1.43 KB
/
brewfile.rb
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
# frozen_string_literal: true
module Bundle
module Brewfile
module_function
def path(dash_writes_to_stdout: false, global: false, file: nil)
env_bundle_file_global = ENV.fetch("HOMEBREW_BUNDLE_FILE_GLOBAL", nil)
env_bundle_file = ENV.fetch("HOMEBREW_BUNDLE_FILE", nil)
user_config_home = ENV.fetch("HOMEBREW_USER_CONFIG_HOME", nil)
filename = if global
if env_bundle_file_global.present?
env_bundle_file_global
else
raise "'HOMEBREW_BUNDLE_FILE' cannot be specified with '--global'" if env_bundle_file.present?
if user_config_home && File.exist?("#{user_config_home}/Brewfile")
"#{user_config_home}/Brewfile"
else
Bundle.exchange_uid_if_needed! do
"#{Dir.home}/.Brewfile"
end
end
end
elsif file.present?
handle_file_value(file, dash_writes_to_stdout)
elsif env_bundle_file.present?
env_bundle_file
else
"Brewfile"
end
Pathname.new(filename).expand_path(Dir.pwd)
end
def read(global: false, file: nil)
Bundle::Dsl.new(Brewfile.path(global:, file:))
rescue Errno::ENOENT
raise "No Brewfile found"
end
def handle_file_value(filename, dash_writes_to_stdout)
if filename != "-"
filename
elsif dash_writes_to_stdout
"/dev/stdout"
else
"/dev/stdin"
end
end
end
end