commands: add commands module for path lookup.
This commit is contained in:
parent
9514d1f8f5
commit
0bb7fda143
13
Library/Homebrew/commands.rb
Normal file
13
Library/Homebrew/commands.rb
Normal file
@ -0,0 +1,13 @@
|
||||
module Commands
|
||||
def self.path(cmd)
|
||||
if File.exist?(HOMEBREW_LIBRARY_PATH/"cmd/#{cmd}.sh")
|
||||
HOMEBREW_LIBRARY_PATH/"cmd/#{cmd}.sh"
|
||||
elsif File.exist?(HOMEBREW_LIBRARY_PATH/"dev-cmd/#{cmd}.sh")
|
||||
HOMEBREW_LIBRARY_PATH/"dev-cmd/#{cmd}.sh"
|
||||
elsif File.exist?(HOMEBREW_LIBRARY_PATH/"cmd/#{cmd}.rb")
|
||||
HOMEBREW_LIBRARY_PATH/"cmd/#{cmd}.rb"
|
||||
elsif File.exist?(HOMEBREW_LIBRARY_PATH/"dev-cmd/#{cmd}.rb")
|
||||
HOMEBREW_LIBRARY_PATH/"dev-cmd/#{cmd}.rb"
|
||||
end
|
||||
end
|
||||
end
|
@ -63,16 +63,16 @@ class CommandsTests < Homebrew::TestCase
|
||||
|
||||
def test_internal_command_path
|
||||
assert_equal HOMEBREW_LIBRARY_PATH/"cmd/rbcmd.rb",
|
||||
Homebrew.send(:internal_command_path, "rbcmd")
|
||||
Commands.path("rbcmd")
|
||||
assert_equal HOMEBREW_LIBRARY_PATH/"cmd/shcmd.sh",
|
||||
Homebrew.send(:internal_command_path, "shcmd")
|
||||
assert_nil Homebrew.send(:internal_command_path, "idontexist1234")
|
||||
Commands.path("shcmd")
|
||||
assert_nil Commands.path("idontexist1234")
|
||||
end
|
||||
|
||||
def test_internal_dev_command_path
|
||||
assert_equal HOMEBREW_LIBRARY_PATH/"dev-cmd/rbdevcmd.rb",
|
||||
Homebrew.send(:internal_command_path, "rbdevcmd")
|
||||
Commands.path("rbdevcmd")
|
||||
assert_equal HOMEBREW_LIBRARY_PATH/"dev-cmd/shdevcmd.sh",
|
||||
Homebrew.send(:internal_command_path, "shdevcmd")
|
||||
Commands.path("shdevcmd")
|
||||
end
|
||||
end
|
||||
|
Loading…
x
Reference in New Issue
Block a user