6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
|
# File 'lib/v8/cli.rb', line 6
def self.run(exename = 'v8', args = [])
options = OpenStruct.new
options.libs = []
options.libdirs = []
parser = OptionParser.new
parser.banner = "Usage: #{exename} [options]"
parser.on("-r", "--require FILE", "load and execute FILE as JavaScript source") {|r| options.libs << r}
parser.on("-i", "--interactive", "interactive mode") {options.interactive = true}
parser.on("-e", "--execute JAVASCRIPT", String, "evaluate JAVASCRIPT and exit") {|src| options.execute = src}
parser.on("--selftest", "check that therubyracer is functioning properly") {options.selftest = true}
parser.on_tail("-v", "--version", "Show version and exit") {options.version_info = true}
parser.on_tail("-h", "--help", "Show this message") do
puts parser
exit
end
begin
parser.parse!(args.dup)
rescue OptionParser::InvalidOption => e
puts "#{exename}: #{e.message}"
exit(1)
end
if options.version_info
require 'libv8'
puts "The Ruby Racer #{V8::VERSION}"
puts "V8 Version #{Libv8::V8_VERSION}"
exit
elsif options.selftest
self.test
end
Context.new(:with => Shell.new) do |cxt|
for libfile in options.libs do
load(cxt,libfile)
end
if options.interactive
repl(cxt, exename)
elsif options.execute
cxt.eval(options.execute, '<execute>')
else
begin
cxt.eval($stdin, '<stdin>')
rescue Interrupt => e
puts; exit
end
end
end
end
|