mirror of
https://github.com/Homebrew/brew.git
synced 2025-07-14 16:09:03 +08:00

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.
24 lines
588 B
Ruby
24 lines
588 B
Ruby
#: * `command` <cmd>:
|
|
#: Display the path to the file which is used when invoking `brew` <cmd>.
|
|
|
|
require "commands"
|
|
|
|
module Homebrew
|
|
module_function
|
|
|
|
def command
|
|
abort "This command requires a command argument" if ARGV.empty?
|
|
|
|
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
|