aboutsummaryrefslogtreecommitdiffstats
path: root/Library/Homebrew/brew.rb
diff options
context:
space:
mode:
authorMike McQuaid2017-11-05 15:37:57 +0000
committerMike McQuaid2017-11-05 15:37:57 +0000
commit7a68b4a3f96c0cc76f94de2cd72b463b40be0343 (patch)
tree3a60bab25001d67966c8bf239b2d7a28f72cd1d3 /Library/Homebrew/brew.rb
parentc3006f0f121b44baa7acb5e2a023dfd96e582e7a (diff)
downloadbrew-7a68b4a3f96c0cc76f94de2cd72b463b40be0343.tar.bz2
Refactor command handling code
Don’t rely on having external commands always present in the PATH in order to find them. Instead, provide an accessory method to Tap so they can be added and used when needed. While we’re here, do some general refactoring and cleanup of the command code in these places.
Diffstat (limited to 'Library/Homebrew/brew.rb')
-rw-r--r--Library/Homebrew/brew.rb14
1 files changed, 6 insertions, 8 deletions
diff --git a/Library/Homebrew/brew.rb b/Library/Homebrew/brew.rb
index e21e0bbd4..bb663537d 100644
--- a/Library/Homebrew/brew.rb
+++ b/Library/Homebrew/brew.rb
@@ -33,7 +33,6 @@ begin
empty_argv = ARGV.empty?
help_flag_list = %w[-h --help --usage -?]
help_flag = !ENV["HOMEBREW_HELP"].nil?
- internal_cmd = true
cmd = nil
ARGV.dup.each_with_index do |arg, i|
@@ -60,8 +59,9 @@ begin
internal_cmd = require? HOMEBREW_LIBRARY_PATH/"cmd"/cmd
unless internal_cmd
- internal_cmd = require? HOMEBREW_LIBRARY_PATH/"dev-cmd"/cmd
- if internal_cmd && !ARGV.homebrew_developer?
+ internal_dev_cmd = require? HOMEBREW_LIBRARY_PATH/"dev-cmd"/cmd
+ internal_cmd = internal_dev_cmd
+ if internal_dev_cmd && !ARGV.homebrew_developer?
system "git", "config", "--file=#{HOMEBREW_REPOSITORY}/.git/config",
"--replace-all", "homebrew.devcmdrun", "true"
ENV["HOMEBREW_DEV_CMD_RUN"] = "1"
@@ -90,8 +90,7 @@ begin
unless internal_cmd
# Add contributed commands to PATH before checking.
- tap_cmds = Pathname.glob(Tap::TAP_DIRECTORY/"*/*/cmd")
- homebrew_path.append(tap_cmds)
+ homebrew_path.append(Tap.cmd_directories)
# External commands expect a normal PATH
ENV["PATH"] = homebrew_path
@@ -100,14 +99,13 @@ begin
if internal_cmd
Homebrew.send cmd.to_s.tr("-", "_").downcase
elsif which "brew-#{cmd}"
- %w[CACHE LIBRARY_PATH].each do |e|
- ENV["HOMEBREW_#{e}"] = Object.const_get("HOMEBREW_#{e}").to_s
+ %w[CACHE LIBRARY_PATH].each do |env|
+ ENV["HOMEBREW_#{env}"] = Object.const_get("HOMEBREW_#{env}").to_s
end
exec "brew-#{cmd}", *ARGV
elsif (path = which("brew-#{cmd}.rb")) && require?(path)
exit Homebrew.failed? ? 1 : 0
else
- require "tap"
possible_tap = OFFICIAL_CMD_TAPS.find { |_, cmds| cmds.include?(cmd) }
possible_tap = Tap.fetch(possible_tap.first) if possible_tap