command: support .sh commands
Closes Homebrew/homebrew#48192. Signed-off-by: Baptiste Fontaine <batifon@yahoo.fr>
This commit is contained in:
parent
c1e673e19a
commit
5775d3b326
@ -4,9 +4,7 @@ module Homebrew
|
|||||||
cmd = ARGV.first
|
cmd = ARGV.first
|
||||||
cmd = HOMEBREW_INTERNAL_COMMAND_ALIASES.fetch(cmd, cmd)
|
cmd = HOMEBREW_INTERNAL_COMMAND_ALIASES.fetch(cmd, cmd)
|
||||||
|
|
||||||
if (path = HOMEBREW_LIBRARY_PATH/"cmd/#{cmd}.rb").file?
|
if (path = internal_command_path cmd)
|
||||||
puts path
|
|
||||||
elsif ARGV.homebrew_developer? && (path = HOMEBREW_LIBRARY_PATH/"dev-cmd/#{cmd}.rb").file?
|
|
||||||
puts path
|
puts path
|
||||||
elsif (path = which("brew-#{cmd}") || which("brew-#{cmd}.rb"))
|
elsif (path = which("brew-#{cmd}") || which("brew-#{cmd}.rb"))
|
||||||
puts path
|
puts path
|
||||||
@ -14,4 +12,17 @@ module Homebrew
|
|||||||
odie "Unknown command: #{cmd}"
|
odie "Unknown command: #{cmd}"
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
private
|
||||||
|
|
||||||
|
def internal_command_path(cmd)
|
||||||
|
extensions = %w[rb sh]
|
||||||
|
paths = extensions.map { |ext| HOMEBREW_LIBRARY_PATH/"cmd/#{cmd}.#{ext}" }
|
||||||
|
|
||||||
|
if ARGV.homebrew_developer?
|
||||||
|
paths += extensions.map { |ext| HOMEBREW_LIBRARY_PATH/"dev-cmd/#{cmd}.#{ext}" }
|
||||||
|
end
|
||||||
|
|
||||||
|
paths.find { |p| p.file? }
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|||||||
@ -1,8 +1,9 @@
|
|||||||
require "testing_env"
|
require "testing_env"
|
||||||
|
require "cmd/command"
|
||||||
require "cmd/commands"
|
require "cmd/commands"
|
||||||
require "fileutils"
|
require "fileutils"
|
||||||
|
|
||||||
class CommandsCommandTests < Homebrew::TestCase
|
class CommandsTests < Homebrew::TestCase
|
||||||
def setup
|
def setup
|
||||||
@cmds = [
|
@cmds = [
|
||||||
# internal commands
|
# internal commands
|
||||||
@ -59,4 +60,23 @@ class CommandsCommandTests < Homebrew::TestCase
|
|||||||
ensure
|
ensure
|
||||||
ENV.replace(env)
|
ENV.replace(env)
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def test_internal_command_path
|
||||||
|
assert_equal HOMEBREW_LIBRARY_PATH/"cmd/rbcmd.rb",
|
||||||
|
Homebrew.send(:internal_command_path, "rbcmd")
|
||||||
|
assert_equal HOMEBREW_LIBRARY_PATH/"cmd/shcmd.sh",
|
||||||
|
Homebrew.send(:internal_command_path, "shcmd")
|
||||||
|
assert_nil Homebrew.send(:internal_command_path, "idontexist1234")
|
||||||
|
end
|
||||||
|
|
||||||
|
def test_internal_dev_command_path
|
||||||
|
ARGV.stubs(:homebrew_developer?).returns false
|
||||||
|
assert_nil Homebrew.send(:internal_command_path, "rbdevcmd")
|
||||||
|
|
||||||
|
ARGV.stubs(:homebrew_developer?).returns true
|
||||||
|
assert_equal HOMEBREW_LIBRARY_PATH/"dev-cmd/rbdevcmd.rb",
|
||||||
|
Homebrew.send(:internal_command_path, "rbdevcmd")
|
||||||
|
assert_equal HOMEBREW_LIBRARY_PATH/"dev-cmd/shdevcmd.sh",
|
||||||
|
Homebrew.send(:internal_command_path, "shdevcmd")
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user