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
52
53
54
55
56
57
58
59
60
61
62
63
64
|
# File 'lib/rsx/cli.rb', line 25
def run(argv)
options = { props: {}, cache_dir: nil }
parser = OptionParser.new do |opts|
opts.banner = BANNER
opts.on("-p", "--prop NAME=VALUE", "Pass a string prop when rendering") do |pair|
name, value = pair.split("=", 2)
options[:props][name.to_sym] = value
end
opts.on("-I", "--include PATH", "Add a directory to the RSX load path") do |path|
RSX.config.paths |= [File.expand_path(path)]
end
opts.on("-c", "--cache-dir DIR", "Directory for compiled output") do |dir|
options[:cache_dir] = dir
end
opts.on("-h", "--help", "Show this message") { puts opts; return 0 }
end
arguments = parser.parse(argv)
command = arguments.shift
RSX.config.cache_dir = options[:cache_dir]
case command
when "compile" then compile(arguments)
when "render" then render(arguments, options[:props])
when "precompile" then precompile(arguments, options[:cache_dir])
when "version", "-v", "--version" then puts RSX::VERSION
when nil then puts parser
else
warn "rsx: unknown command #{command.inspect}"
puts parser
return 1
end
0
rescue RSX::Error, Errno::ENOENT => e
warn "rsx: #{e.message}"
1
end
|