Remove Cask’s which method.

This commit is contained in:
Markus Reiter 2016-10-18 17:22:08 +02:00
parent 8d83516577
commit 6e1c132f99
2 changed files with 2 additions and 30 deletions

View File

@ -107,7 +107,7 @@ module Hbc
if command.respond_to?(:run) if command.respond_to?(:run)
# usual case: built-in command verb # usual case: built-in command verb
command.run(*rest) command.run(*rest)
elsif require? Utils.which("brewcask-#{command}.rb").to_s elsif require? which("brewcask-#{command}.rb").to_s
# external command as Ruby library on PATH, Homebrew-style # external command as Ruby library on PATH, Homebrew-style
elsif command.to_s.include?("/") && require?(command.to_s) elsif command.to_s.include?("/") && require?(command.to_s)
# external command as Ruby library with literal path, useful # external command as Ruby library with literal path, useful
@ -124,7 +124,7 @@ module Hbc
# other Ruby libraries must do everything via "require" # other Ruby libraries must do everything via "require"
klass.run(*rest) klass.run(*rest)
end end
elsif Utils.which "brewcask-#{command}" elsif which("brewcask-#{command}")
# arbitrary external executable on PATH, Homebrew-style # arbitrary external executable on PATH, Homebrew-style
exec "brewcask-#{command}", *ARGV[1..-1] exec "brewcask-#{command}", *ARGV[1..-1]
elsif Pathname.new(command.to_s).executable? && elsif Pathname.new(command.to_s).executable? &&

View File

@ -38,34 +38,6 @@ end
module Hbc module Hbc
module Utils module Utils
def self.which(cmd, path = ENV["PATH"])
unless File.basename(cmd) == cmd.to_s
# cmd contains a directory element
cmd_pn = Pathname(cmd)
return nil unless cmd_pn.absolute?
return resolve_executable(cmd_pn)
end
path.split(File::PATH_SEPARATOR).each do |elt|
fq_cmd = Pathname(elt).expand_path.join(cmd)
resolved = resolve_executable fq_cmd
return resolved if resolved
end
nil
end
def self.resolve_executable(cmd)
cmd_pn = Pathname(cmd)
return nil unless cmd_pn.exist?
return nil unless cmd_pn.executable?
begin
cmd_pn = Pathname(cmd_pn.realpath)
rescue RuntimeError
return nil
end
return nil unless cmd_pn.file?
cmd_pn
end
def self.gain_permissions_remove(path, command: SystemCommand) def self.gain_permissions_remove(path, command: SystemCommand)
if path.respond_to?(:rmtree) && path.exist? if path.respond_to?(:rmtree) && path.exist?
gain_permissions(path, ["-R"], command, &:rmtree) gain_permissions(path, ["-R"], command, &:rmtree)