From 7a68b4a3f96c0cc76f94de2cd72b463b40be0343 Mon Sep 17 00:00:00 2001 From: Mike McQuaid Date: Sun, 5 Nov 2017 15:37:57 +0000 Subject: 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. --- Library/Homebrew/brew.rb | 14 ++++++-------- 1 file changed, 6 insertions(+), 8 deletions(-) (limited to 'Library/Homebrew/brew.rb') 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 -- cgit v1.2.3