lib/faastruby/cli.rb in faastruby-0.5.27 vs lib/faastruby/cli.rb in faastruby-0.5.28

- old
+ new

@@ -76,9 +76,25 @@ end parsed << "SERVER_PORT=#{server_port}" server_dir = "#{Gem::Specification.find_by_name("faastruby").gem_dir}/lib/faastruby/server" config_ru = "#{server_dir}/config.ru" puma_config = "#{server_dir}/puma.rb" - exec "#{parsed.join(' ')} puma -C #{puma_config} -p #{server_port} #{args.join(' ')} #{config_ru}" + puma_executable = which("puma") + error("FATAL: Could not find 'puma' executable.") unless puma_executable + exec "#{parsed.join(' ')} #{puma_executable} -C #{puma_config} -p #{server_port} #{args.join(' ')} #{config_ru}" + end + + # Cross-platform way of finding an executable in the $PATH. + # + # which('ruby') #=> /usr/bin/ruby + def self.which(cmd) + exts = ENV['PATHEXT'] ? ENV['PATHEXT'].split(';') : [''] + ENV['PATH'].split(File::PATH_SEPARATOR).each do |path| + exts.each { |ext| + exe = File.join(path, "#{cmd}#{ext}") + return exe if File.executable?(exe) && !File.directory?(exe) + } + end + return nil end end end