#!/usr/bin/python
# PyCoffee, http://github.com/sikaondrej/pycoffee/
# author: Ondrej Sika, http://ondrejsika.com/

import sys
import io
import coffeescript

try:
    filename = sys.argv[1]
except IndexError:
    sys.stderr.write("No input file\n")
    exit()

try:
    coffee = coffeescript.compile_file(filename=filename, encoding=u"utf-8", bare=True)
except IOError, e:
    sys.stderr.write("%s\n"%e)
    exit()

try:
    with io.open("%s.js"%filename.rsplit(".coffee")[0], "w") as f:
        f.write(coffee)
except IOError, e:
    sys.stderr.write("%s\n"%e)
    exit()
