diff options
| author | Mike McQuaid | 2017-11-05 15:37:57 +0000 | 
|---|---|---|
| committer | Mike McQuaid | 2017-11-05 15:37:57 +0000 | 
| commit | 7a68b4a3f96c0cc76f94de2cd72b463b40be0343 (patch) | |
| tree | 3a60bab25001d67966c8bf239b2d7a28f72cd1d3 /Library/Homebrew/cmd/command.rb | |
| parent | c3006f0f121b44baa7acb5e2a023dfd96e582e7a (diff) | |
| download | brew-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/cmd/command.rb')
| -rw-r--r-- | Library/Homebrew/cmd/command.rb | 19 | 
1 files changed, 10 insertions, 9 deletions
| diff --git a/Library/Homebrew/cmd/command.rb b/Library/Homebrew/cmd/command.rb index 39e8ba6fc..d964fa1a9 100644 --- a/Library/Homebrew/cmd/command.rb +++ b/Library/Homebrew/cmd/command.rb @@ -8,15 +8,16 @@ module Homebrew    def command      abort "This command requires a command argument" if ARGV.empty? -    cmd = ARGV.first -    cmd = HOMEBREW_INTERNAL_COMMAND_ALIASES.fetch(cmd, cmd) -    if (path = Commands.path(cmd)) -      puts path -    elsif (path = which("brew-#{cmd}") || which("brew-#{cmd}.rb")) -      puts path -    else -      odie "Unknown command: #{cmd}" -    end +    cmd = HOMEBREW_INTERNAL_COMMAND_ALIASES.fetch(ARGV.first, ARGV.first) + +    path = Commands.path(cmd) + +    cmd_paths = PATH.new(ENV["PATH"]).append(Tap.cmd_directories) unless path +    path ||= which("brew-#{cmd}", cmd_paths) +    path ||= which("brew-#{cmd}.rb", cmd_paths) + +    odie "Unknown command: #{cmd}" unless path +    puts path    end  end | 
