#!/usr/bin/ruby

# Creates a command to be run later in the execution framework.

if ARGV.size == 0
  puts "Usage: #{File.basename($0)} <command> <arg_1> ... <arg_n>"
  exit 1
end

def quote(x)
  x.gsub!(/'/, "\\'") # Escape single quotes
  "'#{x}'" # Apply single quotes
end

system "mkdir -p state/execs"

command = ["java figems.exec.ExecWrapper"]
command << '-makeThunk'
command += ['-command'] + ARGV.map { |x| quote(x) }
if system(command.join(' ')) != 0
  exit 1
end
