bin/boojs in boojs-0.0.16 vs bin/boojs in boojs-0.0.17

- old
+ new

@@ -1,9 +1,10 @@ #!/usr/bin/env ruby require 'boojs' require 'optparse' require 'phantomjs' +require 'timeout' #Parse ########################################## parser = OptionParser.new do |opts| opts.banner = "Usage: boojs [-v file] [-e command] [file]" @@ -15,21 +16,44 @@ #One-shot command opts.on "-e COMMAND" do |c| @c = c end + + #Timeout + opts.on "-t TIMEOUT" do |t| + @t = t.to_i + 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? + else + BooJS.pipe nil, @c, !@t.nil? + end +end + +#This takes a long time +$phantomjs_path = Phantomjs.path + #Run verify or run stdin/stdout mode? if @vfile BooJS.verify File.read(@file) else - if file - BooJS.pipe File.read(file), @c + if @t + begin + Timeout::timeout(@t) do + pipe_proc.call + end + rescue Timeout::Error + exit 0 + end else - BooJS.pipe nil, @c + pipe_proc.call end end