   outputPath = cli.argv.output
   outputPath = path.resolve(outputPath) if outputPath
 
+  textlex = new Textlex()
+
+  stringify = (tokens, tab) ->
+    JSON.stringify tokens, null, tab
+
+  output = (outputPath, tokens, tab) ->
+    if outputPath
+      fs.writeFileSync(outputPath, stringify tokens, tab)
+    else
+      console.log(stringify tokens, tab)
+
   if filePath
     filePath = path.resolve(filePath)
     unless fs.isFileSync(filePath)

    fileContents = ''
    process.stdin.on 'data', (chunk) -> fileContents += chunk.toString()
    process.stdin.on 'end', ->
      tokens = new Textlex().lexSync({filePath, fileContents, scopeName: cli.argv.scope})
      if outputPath
        fs.writeFileSync(outputPath, JSON.stringify tokens, null, cli.argv.t)
      else
        console.log(JSON.stringify tokens, null, cli.argv.t)

      process.exit(1)
      return

    tokens = textlex.lexSync({filePath, scopeName: cli.argv.scope})
    output outputPath, tokens, cli.argv.tab
  else
    filePath = cli.argv.f
    process.stdin.resume()
