Remove use of `which`

This commit is contained in:
Samuel Cochran 2016-04-23 15:43:27 +08:00
parent f5cbdec8b3
commit 17054f80ad
1 changed files with 7 additions and 7 deletions

View File

@ -32,9 +32,9 @@ require "mail_catcher/web"
require "mail_catcher/version" require "mail_catcher/version"
module MailCatcher extend self module MailCatcher extend self
def which(command) def which?(command)
not windows? and Open3.popen3 'which', 'command' do |stdin, stdout, stderr| ENV["PATH"].split(File::PATH_SEPARATOR).any? do |directory|
return stdout.read.chomp.presence File.executable?(File.join(directory, command.to_s))
end end
end end
@ -50,14 +50,14 @@ module MailCatcher extend self
mac? and const_defined? :MACRUBY_VERSION mac? and const_defined? :MACRUBY_VERSION
end end
def browse? def browseable?
windows? or which "open" windows? or which? "open"
end end
def browse url def browse url
if windows? if windows?
system "start", "/b", url system "start", "/b", url
elsif which "open" elsif which? "open"
system "open", url system "open", url
end end
end end
@ -124,7 +124,7 @@ module MailCatcher extend self
end end
end end
if browse? if browseable?
parser.on('-b', '--browse', 'Open web browser') do parser.on('-b', '--browse', 'Open web browser') do
options[:browse] = true options[:browse] = true
end end