   ['-o', '--output [DIR]',  'set the directory for compiled JavaScript']
   ['-w', '--watch',         'watch scripts for changes, and recompile']
   ['-p', '--print',         'print the compiled JavaScript to stdout']
+  ['-m', '--monitor',       'show a message every time a script is compiled']
   ['-l', '--lint',          'pipe the compiled JavaScript through JSLint']
   ['-s', '--stdio',         'listen for and compile scripts over stdio']
   ['-e', '--eval',          'compile a string from the command line']

# Top-level objects shared by all the functions.
options: {}
sources: []
option_parser: null

# Run `coffee` by parsing passed options and determining what action to take.

  stdin.addListener 'end', ->
    compile_script 'stdio', code

# Watch a source CoffeeScript file using `fs.watchFile`, recompiling it every
# time the file is updated. May be used in combination with other options,
# such as `--lint` or `--print`.
watch: (source) ->
  is_watched[source] = true
  fs.watchFile source, {persistent: true, interval: 500}, (curr, prev) ->
    return if curr.mtime.getTime() is prev.mtime.getTime()
    puts 'Recompiling ' + source              if options.monitor
    fs.readFile source, (err, code) -> compile_script(source, code)

# Write out a JavaScript source file with the compiled code. By default, files
# are written out in `cwd` as `.js` files with the same name, but the output
# directory can be customized with `--output`.
write_js: (source, js) ->
  filename: path.basename(source, path.extname(source)) + '.js'
  src_dir:  path.dirname(source)
  dir: if options.output then \
    path.join options.output, src_dir.substring(base.length) else src_dir
  js_path:  path.join dir, filename
  exec "mkdir -p $dir", (error, stdout, stderr) -> fs.writeFile js_path, js

# Pipe compiled JS through JSLint (requires a working `jsl` command), printing
# any errors or warnings that arise.
