#!/usr/bin/env ruby require File.join(File.dirname(__FILE__), "../lib/boojs") require 'optparse' require 'phantomjs' require 'timeout' #Parse ########################################## parser = OptionParser.new do |opts| opts.banner = "Usage: boojs [-v file] [-e command] [file]" #Verify this file opts.on "-v FILE" do |f| @vfile = f end #One-shot command opts.on "-e COMMAND" do |c| @c = c end #Timeout opts.on "-t TIMEOUT" do |t| @t = t.to_i end #The first line of stdout will be the PID of the PhantomJS process #This is for a spec that tests to make sure the PhanomJS process is #correctly terminated when it is spawned opts.on "-p" do @output_phantomjs_pid = true end end parser.parse! file = ARGV.pop ########################################## #Pipe with with a optional file and optional execute command pipe_proc = Proc.new do if file BooJS.pipe File.read(file), @c, !@t.nil?, @output_phantomjs_pid else BooJS.pipe nil, @c, !@t.nil?, @output_phantomjs_pid end end #This takes a long time $phantomjs_path = Phantomjs.path #Run verify or run stdin/stdout mode? if @vfile exit BooJS.verify File.read(@vfile) else if file exit 1 unless BooJS.verify(File.read(file)) == 0 end if @t begin Timeout::timeout(@t) do pipe_proc.call end rescue Timeout::Error exit 0 end else pipe_proc.call end end