       process.exit(1)
       return
 
-    html = new delexe().renderSync({filePath: outputPath, scopeName: cli.argv.scope})
-    if outputPath
-      fs.writeFileSync(outputPath, html)
-    else
-      console.log(html)
+    string = delexe.renderSync({filePath: outputPath, scopeName: cli.argv.scope})
+    output outputPath, string
   else
     filePath = cli.argv.f or outputPath
     process.stdin.resume()

fs = require 'fs-plus'
CSON = require 'season'
optimist = require 'optimist'
delexe = require './delexe'

module.exports = ->
  cli = optimist.describe('h', 'Show this message').alias('h', 'help')

  outputPath = cli.argv.output
  outputPath = path.resolve(outputPath) if outputPath

  delexe = new Delexe()

  output = (outputPath, string) ->
    if outputPath
      fs.writeFileSync(outputPath, string)
    else
      console.log(string)

  if filePath
    filePath = path.resolve(filePath)
    unless fs.isFileSync(filePath)
